87 lines
1.7 KiB
JavaScript
87 lines
1.7 KiB
JavaScript
const app = getApp()
|
|
const QRCode = require('../../utils/qrcode.js')
|
|
|
|
Page({
|
|
data: {
|
|
userInfo: null,
|
|
ladderUser: null,
|
|
currentStore: null,
|
|
showQrcode: false
|
|
},
|
|
|
|
onLoad() {
|
|
this.initData()
|
|
},
|
|
|
|
onShow() {
|
|
this.refreshData()
|
|
},
|
|
|
|
async initData() {
|
|
if (!app.globalData.token) {
|
|
return
|
|
}
|
|
|
|
await this.refreshData()
|
|
},
|
|
|
|
async refreshData() {
|
|
if (!app.globalData.token) return
|
|
|
|
try {
|
|
await app.getUserInfo()
|
|
this.setData({
|
|
userInfo: app.globalData.userInfo,
|
|
ladderUser: app.globalData.ladderUser,
|
|
currentStore: app.globalData.currentStore
|
|
})
|
|
} catch (e) {
|
|
console.error('获取用户信息失败:', e)
|
|
}
|
|
},
|
|
|
|
async handleLogin() {
|
|
try {
|
|
await app.login()
|
|
await app.getCurrentStore()
|
|
this.setData({
|
|
userInfo: app.globalData.userInfo,
|
|
currentStore: app.globalData.currentStore
|
|
})
|
|
wx.showToast({ title: '登录成功', icon: 'success' })
|
|
} catch (e) {
|
|
wx.showToast({ title: '登录失败', icon: 'none' })
|
|
}
|
|
},
|
|
|
|
showMemberCode() {
|
|
if (!this.data.userInfo?.memberCode) return
|
|
|
|
this.setData({ showQrcode: true })
|
|
|
|
// 生成二维码
|
|
setTimeout(() => {
|
|
new QRCode('qrcode', {
|
|
text: this.data.userInfo.memberCode,
|
|
width: 200,
|
|
height: 200,
|
|
colorDark: '#000000',
|
|
colorLight: '#ffffff'
|
|
})
|
|
}, 100)
|
|
},
|
|
|
|
hideQrcode() {
|
|
this.setData({ showQrcode: false })
|
|
},
|
|
|
|
goTo(e) {
|
|
const url = e.currentTarget.dataset.url
|
|
if (!app.globalData.token) {
|
|
wx.showToast({ title: '请先登录', icon: 'none' })
|
|
return
|
|
}
|
|
wx.navigateTo({ url })
|
|
}
|
|
})
|