纸通宝小程序
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.
 

92 lines
2.5 KiB

// pages/stock/index.js
const request = require('../../../utils/request'); //导入模块
const util = require('../../../utils/util');
const event = require('../../../utils/event.js')
const math = require('../../../utils/math.js');
const app = getApp()
Component({
options: {
addGlobalClass: true,
multipleSlots: true
},
/**
* 页面的初始数据
*/
data: {
firstShow: false,
token: app.globalData.token,
userInfo: null,
avatarUrl: null,
accountMoney: 0
},
lifetimes: {
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
attached: function () {
this.setData({
userInfo: app.globalData.userInfo
})
event.on('EventMessage', this, this.onEvent)
},
detached: function () {
event.remove('EventMessage', this)
}
},
methods: {
// resume的处理;
onRestart: function () {
this.fetchUserInfo()
// this.fetchMoney()
this.data.firstShow = true
},
onEvent: function (message) {
console.log('home>>index>>onEvent', message)
},
fetchUserInfo: function () {
// /user/userInfo 获取用户信息
request.get('/user-centre/front/customer/myInfo').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) => {
})
request.get('/saas-user/account/balance').then(res => {
this.setData({
accountMoney: math.minus(res.data.accountMoney, res.data.frozenMoney)
})
}).catch((e) => {
})
},
checkout: function () {
wx.navigateTo({
url: '/pages/withdrawal/checkout/index'
})
},
toUserInfo: function () {
if(app.globalData.userInfo.isAuth != 1 && app.globalData.userInfo.userType == 1){
wx.navigateTo({
url: '/pages/home/pauthory/index'
})
} else {
wx.navigateTo({
url: '/pages/home/pinfo/index'
})
}
},
toAuthor: function () {
if(app.globalData.userInfo.isAuth != 1 && app.globalData.userInfo.userType == 1){
wx.navigateTo({
url: '/pages/home/pauthory/index'
})
} else {
wx.navigateTo({
url: '/pages/home/pinfo/index'
})
}
}
}
})