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

import request from '../request'
import { getStorage } from "@/utils/storage";
import { setLoading } from '@/utils/tools';


const login = {
    /*************************************************
     * 获取微信登录code
     */
    get_jx_code: (): Promise<AnyObject> => new Promise((resolve, reject) => {
        setLoading('登录中...')
        uni.login({
            provider: 'weixin',
            success: (res) => {
                resolve(res)
            },
            fail: (error) => {
                reject(error)
            }
        })
    }),


    /*************************************************
     * 获取用户信息
     */
    applets_login: async (params: AnyObject): Promise<AnyObject> => {
        setLoading('登录中...')
        params.cId = getStorage('cid')
        return await request.api('/v2/auth2/Login', 'POST', params)
    },


    /*************************************************
     * 用户绑定手机号
     */
    add_auth_bind: async (params: AnyObject): Promise<AnyObject> => {
        return await request.api('/v2/auth2/AddAuthBindWithMobile', 'POST', params)
    },


    /*************************************************
     * 获取用户手机号
     */
    getUser_by_mini_info: async (params: AnyObject): Promise<AnyObject> => {
        return await request.api('/v2/auth2/GetUserByMiniInfo', 'POST', params)
    },


    /*************************************************
     * 刷新token
     */
    get_token_info: async (params?: AnyObject): Promise<AnyObject> => {
        return await request.api('/v2/auth2/GetTokenInfo', 'GET', params)
    },


    /*************************************************
     * 获取手机登录验证码
     */
    send_verify_code: async (params: AnyObject): Promise<AnyObject> => {
        return await request.api('/v2/auth2/SendVerifyCode', 'POST', params)
    },


    /*************************************************
     * 注册用户
     */
    register_user: async (params: AnyObject): Promise<AnyObject> => {
        return await request.api('/v2/user2/RegisterUser', 'POST', params)
    },


    /*************************************************
     * 选择门店 
     */
    get_my_store_list: async (params?: AnyObject): Promise<AnyObject> => {

        return await request.api('/v2/user2/GetMyStoreList', 'GET', params)
    },


    /*************************************************
     * 获取系统数据
     */
    get_service_info: async (params?: AnyObject): Promise<AnyObject> => {
        return await request.api('/v2/cms/GetServiceInfo', 'GET', params)
    },


    /*************************************************
     * 查询用户其他信息，比如角色等
     */
    get_self_info: async (params?: AnyObject): Promise<AnyObject> => {
        return await request.api('/v2/user2/GetSelfInfo', 'GET', params)
    },


    /*************************************************
     * 修改密码
    */
    change_password: async (params?: AnyObject): Promise<AnyObject> => {
        return await request.api('/v2/auth2/ChangePassword', 'PUT', params)
    }
}


export default login