import { get, post } from '../../utils/http' import { formatActivity } from '../../utils/time' import { toQrcode } from '../../utils/util' Page({ /** * 页面的初始数据 */ data: { userInfo: {}, agree: false, visible: false, sum: 0, activity: {}, needReqActivity: true, inserllAmount: 0, inserllAmountLittle: '00', CardDiscount: '', //是否购买次卡拥有美妆折扣 goods_discount: '', //是否存在商品权益,1是,0否 level: '', //用户折扣等级 (0是未拥有等级) levelList: { 8: '0.8', 9: '0.9', 9.5: '0.95', 9.8: '0.98', }, //折扣列表 levelImage: ['https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20221201/20221202-174911.png', 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220920/%E7%BC%96%E7%BB%84%208%E5%A4%87%E4%BB%BD%207%402x.png', 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220920/%E7%BC%96%E7%BB%84%208%E5%A4%87%E4%BB%BD%202%402x.png', 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220920/%E7%BC%96%E7%BB%84%208%E5%A4%87%E4%BB%BD%205%402x.png'], showQR: false, //我的二维码弹窗开关 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { // 获取用户折扣等级 this.getLevel() this.getUser() this.getAmount() this.getCoin() if (wx.getStorageSync('token') && this.data.needReqActivity) { this.getUserActivity() } this.setData({ agree: wx.getStorageSync('agree') || false }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () {}, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { if (this.timer_) { clearInterval(this.timer_) } }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () {}, /** * 用户点击右上角分享 */ onShareAppMessage: function () {}, // 点击头像切换环境 onAvatar() { this.data.sum++ if (this.data.sum >= 10) { this.setData({ visible: true, sum: 0 }) } }, // 获取用户折扣等级 getLevel() { get('/v2/api/user/discount_level', {}, (res) => { if (res.code == 200) { res.data = Number(res.data) let arr = [8, 9, 9.5, 9.8] let index = arr.findIndex(item => { return item == res.data }) this.setData({ imageIndex: index }) if (res.data == 0) { this.setData({ level: 0 }) return } this.setData({ level: Number(res.data * 0.1) }) } }) }, /** * 获取用户信息 * api/user */ getUser() { get('api/user', {}, (res) => { if (res.data) { this.setData({ userInfo: res.data, goods_discount: res.data.goods_discount }, ) wx.setStorageSync('userInfo', res.data) } }) }, /** * 获取我的储值 * api/user */ getAmount() { get('api/user/amount', {}, (res) => { if (res.data) { this.setData({ inserllAmount: res.data.amount.split('.')[0], inserllAmountLittle: res.data.amount.split('.')[1], }) } }) }, /** * 获取我的积分 * api/user */ getCoin() { get('api/user/coin', {}, (res) => { if (res.data) { this.setData({ coin: res.data.coin_num }) } }) }, /** * 跳转vip页面 */ goToVip() { console.log(this.data.userInfo) let nextDatas = JSON.stringify(this.data.userInfo) wx.navigateTo({ url: `/pages/vip/vip?userInfo=${encodeURIComponent(nextDatas)}` // url: `/pages/vip/vip?userInfo=${JSON.stringify(this.data.userInfo)}` // url: '/pages/vip/vip?userInfo='+ JSON.stringify(this.data.userInfo), }) }, /** * 获取首次开卡优惠 * api/user/activity */ getUserActivity() { if (this.timer) { clearInterval(this.timer_) } get('api/user/activity', {}, (res) => { this.data.needReqActivity = false if (res.data) { res.data.currentTime = formatActivity(res.data.expire_time_seconds) this.setData({ activity: res.data }) this.timer_ = setInterval(() => { if (res.data.expire_time_seconds <= 0) { clearInterval(this.timer_) } res.data.expire_time_seconds-- res.data.currentTime = formatActivity(res.data.expire_time_seconds) this.setData({ activity: res.data }) }, 1000) } }) }, // 获取是否拥有购买次卡后拥有的美妆折扣 getCardDiscount() { get('', {}, (res) => { this.setData({ CardDiscount: '' }) }) }, // 跳转到个人档案 goDossier() { wx.navigateTo({ url: '/pages/dossier/dossier', }) }, // 打开我的二维码 getQR() { this.setData({ showQR: true }) let userId = 'userid' + wx.getStorageSync('userInfo').uid toQrcode('qrcode', userId, 400, 400) }, // 关闭我的二维码 onCloseLandscape() { this.setData({ showQR: false }) } })