// import Login from '@/api/https/login'

import login from "@/api/https/login";
import { setStorage } from "@/utils/storage";
import { log } from "node:console";

/**
 * storeInfoStore 模块的 actions
 */
export default {
    // get_services: async (store: any) => {
    //     let res = await Login.get_service_info()
    //     if (res.code == '0') store.commit('setServiceInfo', res.data.metaData)
    // }
    /**
     * isJudg 是否对新用户进行拦截 authType = 'wx',isJudg = false}
     */
    wxLogin:async (store:any,{authType = 'wx',isJudg = false,obj = {}}) => {
        store.commit('changeLoginStatus',false) // 重置登录状态
        let data = {} 
        if(authType == 'wx'){
            // 微信登录
            let getCode = await login.get_jx_code(isJudg);
            data = {
                authType,
                authSecret: getCode.code,
            }
        }else if(authType == 'pwd' || authType == 'yzm'){
            // 账号密码登录 或 验证码登录
            data = obj
        }
       
        console.log('登录的参数信息',data)
        let res = await login.applets_login(data,isJudg);
        if(res.code == 0){
            let user = res.data.user
            setStorage("token", res.data.token);
            setStorage('userInfo',user)
            setStorage('mobile',user.phoneNumber)
            if(user && user.phoneNumber.length === 0) store.commit('setIsBindMobile',{need:true}) // 是否需要需要绑定手机号
            // console.log('判断是否为新用户999999999999999',res,'isJudg',isJudg,'store',store)
         
            if(!isJudg){
                store.commit('changeLoginStatus',true) // 老用户
                // 查询用户信息
                await store.dispatch('queryAccount') // 查询账余额
                uni.navigateTo({ url: '/pages/index/index' }) // 调转到首页
            }
        }
    },

    /**
     * 查询账户余额
     */
    queryAccount:async(store:any) => {
        console.log('初始化,获取账户余额')
        let res = await login.queryAccountBalance()
        if(res.code == 0){
            store.commit('changeAccountBalance',res.data.balance / 100)
            console.log('打印账户余额',res)
        }
    },
}