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.
107 lines
2.7 KiB
107 lines
2.7 KiB
// pages/home/setting/index.js
|
|
import { finalizeToken } from "../../api/user"
|
|
import { $wuxDialog } from '../../../components/index'
|
|
import {
|
|
postRelation,
|
|
getBaseInfo
|
|
} from '../../api/ztb'
|
|
const event = require('../../../utils/event')
|
|
const storage = require('../../../utils/storage')
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
kg: app.globalData.kg,
|
|
version: 2,
|
|
userInfo: {
|
|
bizUserId:null,
|
|
bizUserName:null
|
|
},
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
getBaseInfo().then(res => {
|
|
this.setData({
|
|
userInfo: res.data,
|
|
bizUserId:res.data.bizUserId,
|
|
bizUserName:res.data.bizUserName,
|
|
})
|
|
})
|
|
this.setData({
|
|
kg: app.globalData.kg,
|
|
version: this.data.version
|
|
})
|
|
},
|
|
checKg: function(e){
|
|
var kg = e.currentTarget.id == 'kg' ? 1 : 0
|
|
app.globalData.kg = kg
|
|
storage.put('ztb-kg', kg)
|
|
event.emit('EventMessage', { what: 1001, desc: 'KGchange' })
|
|
this.setData({ kg })
|
|
},
|
|
|
|
loginOut: function () {
|
|
$wuxDialog().open({
|
|
resetOnClose: true,
|
|
title: '温馨提示',
|
|
content: '确定退出当前账号?',
|
|
buttons: [{
|
|
text: '取消'
|
|
}, {
|
|
text: '确定',
|
|
type: 'primary',
|
|
onTap(e) {
|
|
storage.remove('userToken')
|
|
storage.remove('Authorization')
|
|
storage.remove('isTokenHaveStatus')
|
|
app.globalData.token = null
|
|
app.globalData.userInfo = null
|
|
finalizeToken()
|
|
event.emit('EventMessage', { what: 888, desc: 'Logout' })
|
|
wx.navigateBack()
|
|
}
|
|
}]
|
|
})
|
|
},
|
|
showDialog: function (e1) {
|
|
this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog')
|
|
var that = this
|
|
var placeholderName = ''
|
|
if (e1.currentTarget.dataset.tag == '业务人员邀请码') {
|
|
placeholderName = that.data.userInfo.bizUserId
|
|
}
|
|
this.wuxDialog.prompt({
|
|
resetOnClose: true,
|
|
title: e1.currentTarget.dataset.tag,
|
|
placeholder: placeholderName || '请输入' + e1.currentTarget.dataset.tag,
|
|
maxlength: 18,
|
|
onConfirm(e, response) {
|
|
if (util.isEmpty(response)) {
|
|
util.showToast('请输入' + e1.currentTarget.dataset.tag)
|
|
return
|
|
}
|
|
if (e1.currentTarget.dataset.tag == '业务人员邀请码') {
|
|
postRelation(response).then(result => {
|
|
//成功回调
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
|
|
},
|
|
})
|
|
|
|
|
|
},
|
|
})
|