You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xxdj1/store/modules/user.js

148 lines
2.9 KiB

2 years ago
import $util from "@/utils/index.js"
import $api from "@/api/index.js"
import $store from "@/store/index.js"
import {
req
} from '@/utils/req.js';
export default {
state: {
autograph: '',
userInfo: '',
appLogin: '',
commonOptions: {
coupon_atv_id: 0,
channel_id: 0
},
location: {},
wxlocation: {},
isShowAuth: true,
mineInfo: {},
userPageType: 1 // 1用户,2技师
},
mutations: {
//更新内容
async updateUserItem(state, item) {
let {
key,
val
} = item
if (key == 'userInfo') {
let {
phone = '',
create_time,
} = val
if (phone) {
val.split_phone = phone.substring(0, 3) + '****' + phone.substring(7, 11)
}
val.create_date = $util.formatTime(create_time * 1000, 'YY-M-D')
}
state[key] = val
if (['autograph', 'userInfo', 'location', 'appLogin'].includes(key)) {
uni.setStorageSync(key, val)
}
}
},
actions: {
//获取个人信息
async getUserInfo({
commit,
state
}, param) {
console.log("============user.js getUserInfo")
let data = await $api.user.userInfo()
commit('updateUserItem', {
key: 'userInfo',
val: data
})
},
//获取用户个人中心数据
async getMineInfo({
commit,
state
}, param) {
let data = await $api.mine.index()
let {
fx_status
} = data
2 years ago
// data.coach_status = 2
// data.service_time_long=25
2 years ago
commit('updateUserItem', {
key: 'mineInfo',
val: data
})
},
// 获取用户信息
async getAuthUserProfile({
commit,
state
}, param) {
let {
nickName,
avatarUrl
} = param
await $api.user.userUpdate(param)
let data = Object.assign(state.userInfo, {
nickName,
avatarUrl
})
commit('updateUserItem', {
key: 'userInfo',
val: data
})
},
// 获取手机号
async getAuthPhone({
commit,
state
}, {
e = {
detail: {}
},
must = false
} = {}) {
let {
encryptedData = '', iv = ''
} = e.detail;
let phone = ''
if (encryptedData && iv) {
let phone = await $api.user.reportPhone({
encryptedData,
iv
})
console.log(phone, "=====phone")
let data = Object.assign(state.userInfo, {
phone
})
commit('updateUserItem', {
key: 'userInfo',
val: data
})
console.log(data, state.userInfo, "===========")
return phone;
}
},
// 更新公共参数
async updateCommonOptions({
commit,
state
}, param) {
let target = {}
if (param.scene) {
let res = await $api.base.getWxCodeData({
code_id: param.scene
})
target = Object.assign({}, state.commonOptions, res.data)
} else {
target = Object.assign({}, state.commonOptions, param)
}
let data = $util.pick(target, ['id', 'coupon_atv_id', 'admin_id', 'channel_id'])
commit('updateUserItem', {
key: 'commonOptions',
val: data
})
console.log(target, "======target");
return target
}
}
}