import request from '../js/request'


/**
 * 发送验证码
 * @param {*} params.type 0:登录 1:注册 3:忘记密码 4:更换手机号第二步获取验证码 5:更换手机号第一步获取验证码
 * @returns 
 */
export function apiGetYms (params) {
    return request({
        url: '/shiningCloud/user/authCode',
        data: {
            phone: params.phone,
            devCode: uni.getStorageSync('cidAES'),
            type: params.type
        },
        method: 'POST'
    })
}

/**
 * 登录
 * @param {*} params.type 0:ysm 1:pwd
 * @returns 
 */
export function apiLogin (params) {
    console.log(uni.getStorageSync('cidAES'));
    return request({
        url: '/shiningCloud/user/login',
        data: {
            phone: params.phone,
            devCode: uni.getStorageSync('cidAES'),
            key: params.key.trim(),
            type: params.type
        },
        method: 'POST'
    })
}

/**
 * 注册
 * @param {*} params 
 * @returns 
 */
export function apiRegister (params) {
    return request({
        url: '/shiningCloud/user/register',
        data: {
            phone: params.phone,
            devCode: uni.getStorageSync('cidAES'),
            code: params.code.trim(),
        },
        method: 'POST'
    })
}
// 第一次登录设置密码
export function apiSetPsd (params) {
    return request({
        url: '/shiningCloud/user/setPsd',
        data: {
            userId: uni.getStorageSync('userInfo').userId,
            devCode: uni.getStorageSync('cidAES'),
            password: params.password.trim()
        },
        method: 'POST'
    })
}
// 重置密码
export function apiReSetPsd(params) {
    return request({
        url: '/shiningCloud/user/resetPsd',
        data: {
            phone: params.phone,
            code: params.code.trim(),
            devCode: uni.getStorageSync('cidAES'),
            password: params.password.trim()
        },
        method: 'POST'
    })
}

// 更换手机号第一步
export function apiComfirmCode (params) {
    return request({
        url: '/shiningCloud/user/comfirmCode',
        data: {
            devCode: uni.getStorageSync('cidAES'),
            phone: params.phone,
            code: params.code.trim()
        },
        method: 'POST'
    })
}
// 重新绑定手机号
export function apiRebindPhone (params) {
    return request({
        url: '/shiningCloud/user/rebindPhone',
        data: {
            devCode: uni.getStorageSync('cidAES'),
            userId: uni.getStorageSync('userInfo').userId,
            phoneNew: params.phone,
            code: params.code.trim()
        },
        method: 'POST'
    })
}