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

98 lines
3.1 KiB

// pages/ztbvip/index.js
const request = require('../../utils/request') //导入模块
const util = require('../../utils/util')
const event = require('../../utils/event.js')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
userInfo: null,
avatarUrl: '../../assets/image/ygImg.png',
iconList: [],
safeBottom: app.globalData.safeBottom,
divIndex:null,
vipInfo: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({ safeBottom: app.globalData.safeBottom, userInfo: app.globalData.userInfo })
request.get('/recycle-service/member/get/member-expense-list').then(res => {
this.setData({ iconList: res.data, divIndex:res.data[0].id })
})
this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog')
},
onShow: function () {
if(!app.globalData.userInfo){
return
}
wx.showLoading({ title: '处理中', mask: true })
// /user/userInfo 获取用户信息
request.get('/recycle-service/user/get/base-info').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.realName) ? '' : app.globalData.userInfo.realName.substring(0, 14)
})
})
request.get('/recycle-service/user/get/member-info').then(res => {
this.setData({ vipInfo: res.data, ['vipInfo.memberExpiredAt']: res.data.memberExpiredAt.substring(0, 10) })
wx.hideLoading()
}).catch(error => {
wx.hideLoading()
})
},
toAuthor: function(){
if(this.data.userInfo && !this.data.userInfo.isAuth){
util.navigateTo('/pages/home/idcard/index')
}
},
/**
* 点击选择会员资费类型事件
*/
onGridTap:function(e){
var divIndexId=e.currentTarget.dataset.index
this.setData({ divIndex:this.data.iconList[divIndexId].id })
},
openVip:function(){
if(!app.globalData.userInfo){
wx.navigateTo({ url: '/pages/login/index' })
return
}
if(!app.globalData.userInfo.isAuth){
this.wuxDialog.open({
resetOnClose: true,
title: '温馨提示',
content: '您还没有进行个人信息认证,无法购买会员,现在去进行个人信息认证?',
buttons: [{
text: '确定',
type: 'primary',
onTap(e) {
util.navigateTo('/pages/home/idcard/index')
}
}]
})
return
}
wx.showLoading({ title: '处理中', mask: true })
request.post('/recycle-service/member/buy/member',{ memberExpenseId: this.data.divIndex }).then(res => {
wx.hideLoading()
if(res.data.isNeedPay && res.data.orderId){
wx.navigateTo({ url: '/pages/payment/index?type=2&orderId=' + res.data.orderId })
} else {
app.globalData.userInfo.isVIP = 1
event.emit('EventMessage', { what: 200, desc: 'Vip' })
util.showBackToast('会员购买成功')
}
}).catch((e) => {
wx.hideLoading()
})
}
})