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

236 lines
7.6 KiB

// pages/stock/index.js
import {
getBaseInfo,
getMessageNumber
} from "../../api/ztb"
import {
getBalanceInfo
} from "../../api/payment"
const util = require('../../../utils/util')
const event = require('../../../utils/event')
const math = require('../../../utils/math')
const app = getApp()
Component({
options: {
addGlobalClass: true,
multipleSlots: true
},
/**
* 页面的初始数据
*/
data: {
height: app.globalData.safeFragmentHeight,
firstShow: false,
userInfo: null,
avatarUrl: '/assets/myinfo/user-icon.png',
accountMoney: 0,
messageNumber: 0
},
lifetimes: {
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
attached: function () {
event.on('EventMessage', this, this.onEvent)
},
detached: function () {
event.remove('EventMessage', this)
}
},
methods: {
// resume的处理;
onRestart: function () {
if (!this.data.firstShow) {
this.setData({
height: (app.globalData.safeFragmentHeight + app.globalData.statusBarHeight - 100),
CustomBar: app.globalData.CustomBar,
userInfo: app.globalData.userInfo
})
if (app.globalData.userInfo && app.globalData.userInfo.memberExpiredAt) {
this.setData({
'userInfo.memberExpiredAt': app.globalData.userInfo.memberExpiredAt,
userName: app.globalData.userInfo.realName || app.globalData.userInfo.nickname || ''
})
}
}
this.fetchUserInfo()
this.data.firstShow = true
},
onEvent: function (message) {
if (message.what == 888) {
this.setData({
userInfo: app.globalData.userInfo,
accountMoney: 0,
messageNumber: 0,
avatarUrl: '/assets/myinfo/user-icon.png'
})
}
},
fetchUserInfo: function () {
if (!app.globalData.token) {
return
}
getBaseInfo().then(result => {
var nickname = ''
if (app.globalData.userInfo.isAuth) {
nickname = result.data.realName.substring(0, 14)
} else if (!util.isEmpty(result.data.nickname)) {
nickname = result.data.nickname.substring(0, 14)
} else if (!util.isEmpty(result.data.realName)) {
nickname = result.data.realName.substring(0, 14)
}
app.globalData.userInfo.userName = nickname
if (!util.isEmpty(result.data.avatarUrl)) {
app.globalData.userInfo.avatarUrl = result.data.avatarUrl
}
app.globalData.userInfo.isVIP = result.data.isVIP
app.globalData.userInfo.hasStore = result.data.hasStore
this.setData({
avatarUrl: app.globalData.userInfo.avatarUrl,
userInfo: app.globalData.userInfo,
userName: nickname
})
if (this.data.userInfo.isVIP == 1) {
this.setData({
'userInfo.memberExpiredAt': util.formatDate(new Date(app.globalData.userInfo.memberExpiredAt.replace(/\-/g, "/")), 'Y-M-D')
})
}
})
getBalanceInfo().then(result => {
this.setData({
accountMoney: math.minus(result.data.accountMoney, result.data.frozenMoney),
frozenMoney: result.data.frozenMoney
})
})
getMessageNumber().then(result => {
this.setData({
messageNumber: result.data.messageNumber + result.data.notificationNumber
})
})
},
toPage: function (e) {
if (e.currentTarget.id == 'bidding') {
util.navigateTo('/pages/bidding/index/index')
} else if (e.currentTarget.id == 'shop') {
util.navigateTo('/pages/shop/index/index')
} else if (e.currentTarget.id == 'ordering') {
util.navigateTo('/pages/morder/index/index')
} else if (e.currentTarget.id == 'agent') {
util.navigateTo('/pages/agent/order/index')
} else if (e.currentTarget.id == 'message') {
util.navigateTo('/pages/message/index/index')
} else if (e.currentTarget.id == 'balance') {
util.navigateTo('/pages/withdrawal/balance/index')
} else if (e.currentTarget.id == 'integral') {
util.navigateTo('/pages/html/integral/index')
} else if (e.currentTarget.id == 'article') {
util.navigateTo('/pages/article/list/index')
} else if (e.currentTarget.id == 'adress') {
util.navigateTo('/pages/adress/list/index')
} else if (e.currentTarget.id == 'setting') {
util.navigateTo('/pages/home/setting/index')
} else if (e.currentTarget.id == 'tovip') {
util.navigateTo('/pages/ztbvip/index')
} else if (e.currentTarget.id == 'myCus') {
util.navigateTo('/pages/home/service/index')
} else if (e.currentTarget.id == 'qnLogistic') {
util.navigateTo('/pages/html/logistics/index')
} else if (e.currentTarget.id == 'toMyMoney') {
util.navigateTo('/pages/bank/bill/index')
} else if (e.currentTarget.id == 'agent50') {
util.navigateTo('/pages/agent/order/index?status=50&tabIndex=1')
} else if (e.currentTarget.id == 'agent51') {
wx.navigateTo({
url: '/pages/agent/order/index?status=51&tabIndex=2'
})
} else if (e.currentTarget.id == 'agent53') {
wx.navigateTo({
url: '/pages/agent/order/index?status=53&tabIndex=3'
})
} else if (e.currentTarget.id == 'agent54') {
wx.navigateTo({
url: '/pages/agent/order/index?status=54&tabIndex=4'
})
} else if (e.currentTarget.id == 'agent55') {
wx.navigateTo({
url: '/pages/agent/order/index?status=55&tabIndex=5'
})
} else if (e.currentTarget.id == 'agentall') {
wx.navigateTo({
url: '/pages/agent/order/index?status=&tabIndex=0'
})
}
},
toUserInfo: function () {
if (!app.globalData.userInfo) {
wx.navigateTo({
url: '/pages/login/index'
})
return
}
if (app.globalData.userInfo.isAuth != 1) {
wx.navigateTo({
url: '/pages/home/idcard/index'
})
} else {
wx.navigateTo({
url: '/pages/home/info/index'
})
}
},
toAuthor: function () {
if (app.globalData.userInfo.isAuth != 1) {
wx.navigateTo({
url: '/pages/home/idcard/index'
})
} else {
wx.navigateTo({
url: '/pages/home/info/index'
})
}
},
clickGrid: function (e) {
if (parseInt(e.currentTarget.id) == 1) {
wx.navigateTo({
url: '/pages/bidding/index/index'
})
} else if (parseInt(e.currentTarget.id) == 2) {
wx.navigateTo({
url: '/pages/morder/index/index'
})
} else if (parseInt(e.currentTarget.id) == 3) {
wx.navigateTo({
url: '/pages/message/index/index'
})
} else if (parseInt(e.currentTarget.id) == 4) {
wx.navigateTo({
url: '/pages/agent/order/index'
})
} else if (parseInt(e.currentTarget.id) == 5) {
wx.navigateTo({
url: '/pages/html/integral/index'
})
} else if (parseInt(e.currentTarget.id) == 6) {
wx.navigateTo({
url: '/pages/article/list/index'
})
} else if (parseInt(e.currentTarget.id) == 7) {
wx.navigateTo({
url: '/pages/adress/list/index'
})
}
},
onShareAppMessage: function () {
return {
title: '纸通宝--废纸交易、最新情报、最优资讯',
path: '/pages/home/index'
}
},
// 分享至朋友圈
onShareTimeline() {
return {
title: '纸通宝--废纸交易、最新情报、最优资讯',
path: '/pages/home/index'
}
},
}
})