56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { onGoH5Page } from '../../../utils/getUserInfo'
|
|
import { apiActIsMulPhones, apiActChangeAccount } from '../../../api/index/index'
|
|
const H5Link = require('../../../api/base').allBaseUrl.GDEnvs.web
|
|
|
|
Component({
|
|
data: {
|
|
chooseUserId: null,
|
|
mulPhonesData: {} as any
|
|
},
|
|
created() {
|
|
this.handleGetMulPhones()
|
|
},
|
|
methods: {
|
|
// 获取多账号列表
|
|
handleGetMulPhones() {
|
|
apiActIsMulPhones({}).then((res: any) => {
|
|
if (res.code === '1000') {
|
|
const chooseUserId = res.data.userNames.find((it: any) => it.current === 1).userId
|
|
this.setData({
|
|
chooseUserId,
|
|
mulPhonesData: res.data
|
|
})
|
|
} else {
|
|
wx.showToast({ title: res.msg, icon: 'none' })
|
|
}
|
|
})
|
|
},
|
|
// 选中手机号
|
|
onSelect (event: any) {
|
|
const index = event.currentTarget.dataset.index
|
|
const item = event.currentTarget.dataset.item
|
|
console.log(`index=${index}`, `item=${item}`)
|
|
this.setData({ chooseUserId: item.userId })
|
|
},
|
|
// 确定绑定
|
|
onBind () {
|
|
if (this.data.mulPhonesData.changeToast) {
|
|
wx.showToast({ title: this.data.mulPhonesData.changeToast, icon: 'none' })
|
|
} else {
|
|
const chooseUserItem = this.data.mulPhonesData.userNames.find((it: any) => it.userId === this.data.chooseUserId)
|
|
if (chooseUserItem.current === 1 && chooseUserItem.isMain) {
|
|
apiActChangeAccount({ userId: chooseUserItem.userId }).then(res => {
|
|
if (res.code === '1000') {
|
|
this.triggerEvent('handleGetHomePage')
|
|
this.triggerEvent('onCloseDialogMultiple')
|
|
} else {
|
|
wx.showToast({ title: res.msg, icon: 'none' })
|
|
}
|
|
})
|
|
} else {
|
|
onGoH5Page({ is_need_login: true, url: `${H5Link}/auth/validateuser?chooseUserId=${this.data.chooseUserId}` })
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}) |