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.
119 lines
3.5 KiB
119 lines
3.5 KiB
// pages/stock/index.js
|
|
import { getBaseInfo, getBalanceInfo } from "../../api/saas"
|
|
const util = require('../../../utils/util')
|
|
const math = require('../../../utils/math')
|
|
const event = require('../../../utils/event')
|
|
const app = getApp()
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
lifetimes: {
|
|
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
|
|
attached: function () {
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
detached: function () {
|
|
event.remove('EventMessage', this)
|
|
}
|
|
},
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
firstShow: false,
|
|
token: app.globalData.token,
|
|
userInfo: null,
|
|
userName: null,
|
|
avatarUrl: null,
|
|
accountMoney: 0
|
|
},
|
|
methods: {
|
|
onRestart: function () {
|
|
this.fetchUserInfo()
|
|
this.data.firstShow = true
|
|
},
|
|
fetchUserInfo: function () {
|
|
if(!app.globalData.userInfo){
|
|
return
|
|
}
|
|
getBaseInfo().then(result => {
|
|
app.globalData.userInfo = result.data
|
|
this.setData({
|
|
avatarUrl: util.isEmpty(app.globalData.userInfo.avatar) ? '/assets/image/ygImg.png' : app.globalData.userInfo.avatar,
|
|
userInfo: app.globalData.userInfo,
|
|
userName: util.isEmpty(app.globalData.userInfo.userName) ? '' : app.globalData.userInfo.userName.substring(0, 14)
|
|
})
|
|
}).catch((e) => {
|
|
})
|
|
getBalanceInfo().then(res => {
|
|
this.setData({ accountMoney: math.minus(res.data.accountMoney, res.data.frozenMoney) })
|
|
}).catch(err => {
|
|
})
|
|
},
|
|
onEvent: function (message) {
|
|
if (message.what == 888) {
|
|
this.setData({ userInfo: app.globalData.userInfo, accountMoney: 0, avatarUrl: '/assets/image/ygImg.png', userName: null })
|
|
}
|
|
},
|
|
checkout: function () {
|
|
if(!app.globalData.userInfo){
|
|
wx.navigateTo({ url: '/pages/login/index' })
|
|
return
|
|
}
|
|
wx.navigateTo({ url: '/pages/withdrawal/checkout/index' })
|
|
},
|
|
toUserInfo: function () {
|
|
if(!app.globalData.userInfo){
|
|
wx.navigateTo({ url: '/pages/login/index' })
|
|
return
|
|
}
|
|
if(app.globalData.userInfo.isAuth != 1 && app.globalData.userInfo.userType == 1){
|
|
wx.navigateTo({ url: '/pages/home/idcard/index' })
|
|
} else {
|
|
wx.navigateTo({ url: '/pages/home/pinfo/index' })
|
|
}
|
|
},
|
|
toAuthor: function () {
|
|
if(!app.globalData.userInfo){
|
|
wx.navigateTo({ url: '/pages/login/index' })
|
|
return
|
|
}
|
|
if(app.globalData.userInfo.isAuth != 1 && app.globalData.userInfo.userType == 1){
|
|
wx.navigateTo({ url: '/pages/home/idcard/index' })
|
|
} else {
|
|
wx.navigateTo({ url: '/pages/home/pinfo/index' })
|
|
}
|
|
},
|
|
toBankCard: function () {
|
|
if(!app.globalData.userInfo){
|
|
wx.navigateTo({ url: '/pages/login/index' })
|
|
return
|
|
}
|
|
wx.navigateTo({ url: '/pages/bank/index/index' })
|
|
},
|
|
toWithdrawal: function () {
|
|
if(!app.globalData.userInfo){
|
|
wx.navigateTo({ url: '/pages/login/index' })
|
|
return
|
|
}
|
|
wx.navigateTo({ url: '/pages/withdrawal/index/index' })
|
|
},
|
|
toBalance: function () {
|
|
if(!app.globalData.userInfo){
|
|
wx.navigateTo({ url: '/pages/login/index' })
|
|
return
|
|
}
|
|
wx.navigateTo({ url: '/pages/balance/index/index' })
|
|
},
|
|
toSetting: function () {
|
|
if(!app.globalData.userInfo){
|
|
wx.navigateTo({ url: '/pages/login/index' })
|
|
return
|
|
}
|
|
wx.navigateTo({ url: '/pages/home/setting/index' })
|
|
}
|
|
}
|
|
})
|