/*************************************************
 *@description: 登录模块
 *@return {*}
 *@param {}-
*/

import { setLoading } from '@/utils/tools'
import request from '../request'


const login = {
    /*************************************************
     * 获取微信登录code 已完成
     */
    get_jx_code: (isLoading?:boolean): Promise<AnyObject> => new Promise((resolve, reject) => {
        console.log('登录中----------',isLoading)
        if(!isLoading) {
            console.log('你走的if')
            setLoading('登录中...')
        }else{
            console.log('走的时else')
        }
        uni.login({
            provider: 'weixin',
            success: (res) => {
                resolve(res)
            },
            fail: (error) => {
                reject(error)
            }
        })
    }),


    /*************************************************
     * 登录 获取用户信息 已完成
     * AuthType        string `p:"auth_type"        v:"required#登录类型不能为空"`    // 登录类型，当前支持[pwd：本地账号密码，sms：手机短信，wx：微信APP，ali：支付宝小程序]
     * AuthSecret      string `p:"auth_secret"`                                     // pwd:md5Pwd,wx:code,yzn:code
     * AuthIDType      string `p:"auth_id_type"`                                    // pwd:userID / mobile
     * AuthID          string `p:"auth_id"`                                         // pwd:AuthIDType值
     * CId             string `p:"c_id"`
     * PromotionSource string `p:"promotion_source"` // 推广来源
     */
    applets_login: (params: AnyObject,isLoading?:boolean): Promise<AnyObject> => {
        if(!isLoading)  setLoading('登录中...')
        // return request.api('/v2/auth2/Login', 'POST', params)
        return request.api('/jx_horizon/wechat/login', 'POST', params)
    },


    /*************************************************
     * 获取手机登录验证码 已完成
     * @Param   authType    query    string     true        "验证类型[yzm]"
     * @Param   phone       query    string     true        "电话号码"
     */
    send_verify_code: async (params: AnyObject): Promise<AnyObject> => {
        return await request.api('/jx_horizon/wechat/sendVerifyCode', 'GET', params)
    },



    /**
     * 解密用户信息 已完成
     * @Param   sessionKey        query    string     true        "key"
     * @Param   encryptedData     query    string     true        "加密信息"
     * @Param   iv        		  query    string     true        "iv"
     * 
     * @Param   type        	  query    string     true        "phone/name"
     * 
     */
    decryUser: async (params: AnyObject): Promise<AnyObject> => {
        return await request.api('/jx_horizon/wechat/decryUser', 'GET', params)
    },


    /*************************************************
     * 获取推广用户的推广二维码 已完成
     * @param vendorOrderID  订单id
     * @Param   scene       query    string     true        "推广人员信息"
     * @Param   page        query    string     false        "跳转页面"
     */
    getTiktokOrWxCode: async (json: string | Record<string,string>): Promise<AnyObject> => {
        return await request.api('/jx_horizon/wechat/qrCode', 'GET', json)
    },

    /*************************************************
     * 查询用户账户余额 已完成
     */
    queryAccountBalance: async (): Promise<AnyObject> => {
        return await request.api('/jx_horizon/wechat/balance', 'GET')
    },


    /**
     * 注册和修改密码 
     * Password    string `p:"password"`     // 密码
     * OldPassword string `p:"old_password"` // 旧密码
     */
    changePassword: async (params:AnyObject): Promise<AnyObject> => {
        return await request.api('/jx_horizon/wechat/changePassword', 'POST',params)
    },


        /**
     * 注册和修改密码 
     * Password    string `p:"password"`     // 密码
     * OldPassword string `p:"old_password"` // 旧密码
     */
    ressss: async (): Promise<AnyObject> => {
        return await request.api('/api/register', 'POST')
    },
}


export default login