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.
98 lines
2.9 KiB
98 lines
2.9 KiB
// pages/stock/index.js
|
|
import Dialog from '../../components/dialog/dialog'
|
|
import { finalizeToken } from "../../api/user"
|
|
import { getBalanceInfo } from '../../api/payment'
|
|
const util = require('../../utils/util')
|
|
const event = require('../../utils/event')
|
|
const math = require('../../utils/math')
|
|
const storage = require('../../utils/storage')
|
|
const app = getApp()
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
height: app.globalData.safeFragmentHeight,
|
|
firstShow: false,
|
|
userInfo: null,
|
|
avatarUrl: '/assets/image/ygImg.png',
|
|
xsaccountMoney: 0, //显示余额
|
|
},
|
|
lifetimes: {
|
|
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
|
|
attached: function () {
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
detached: function () {
|
|
event.remove('EventMessage', this)
|
|
}
|
|
},
|
|
methods: {
|
|
// resume的处理;
|
|
onRestart: function () {
|
|
this.setUserInfo()
|
|
getBalanceInfo().then(result => {
|
|
if(result.data){
|
|
this.setData({ xsaccountMoney: math.minus(result.data.accountMoney, result.data.frozenMoney) })
|
|
}
|
|
}).catch(err => {
|
|
console.log(err)
|
|
})
|
|
this.data.firstShow = true
|
|
},
|
|
onEvent: function (message) {
|
|
if (message.what == 82) {
|
|
// 认证成功
|
|
}
|
|
},
|
|
setUserInfo: function(){
|
|
if(!app.userInfo){
|
|
return
|
|
}
|
|
var nickname = ''
|
|
if(app.userInfo.isAuth) {
|
|
nickname = app.userInfo.realName.substring(0, 14)
|
|
} else if(!util.isEmpty(app.userInfo.nickname)){
|
|
nickname = app.userInfo.nickname.substring(0, 14)
|
|
} else if(!util.isEmpty(app.userInfo.realName)){
|
|
nickname = app.userInfo.realName.substring(0, 14)
|
|
}
|
|
this.setData({
|
|
avatarUrl: util.isEmpty(app.userInfo.avatarUrl) ? '/assets/image/ygImg.png' : app.userInfo.avatarUrl,
|
|
userInfo: app.userInfo,
|
|
userName: nickname,
|
|
height: app.globalData.safeFragmentHeight- 100
|
|
})
|
|
},
|
|
toUserInfo: function(){
|
|
if(!app.userInfo){
|
|
return
|
|
}
|
|
if(!app.userInfo.isAuth){
|
|
wx.navigateTo({ url: '/pages/setting/authory/index' })
|
|
}
|
|
},
|
|
orderList: function(){
|
|
wx.navigateTo({ url: '/pages/client/order-list/index' })
|
|
},
|
|
tipApply: function(){
|
|
wx.navigateTo({ url: '/pages/htmls/auths/index' })
|
|
},
|
|
loginOut: function () {
|
|
Dialog.confirm({ title: '温馨提示', message: '确定退出纸通宝账号?' }).then(() => {
|
|
storage.remove('Authorization')
|
|
app.globalData.token = null
|
|
app.userInfo = null
|
|
this.setData({ userInfo: null, avatarUrl: '/assets/image/ygImg.png' })
|
|
finalizeToken()
|
|
wx.redirectTo({ url: '/pages/login/index' })
|
|
event.emit('EventMessage', { what: 888, desc: 'Logout' })
|
|
})
|
|
}
|
|
}
|
|
})
|