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

93 lines
3.0 KiB

import { getBaseInfo, getMemberExpenseList, getMemberInfo, buyMemberInfo } from "../../api/ztb"
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 })
getMemberExpenseList().then(res => {
this.setData({ iconList: res.data, divIndex:res.data[0].id })
}).catch(err => { })
this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog')
},
onShow: function () {
if(!app.globalData.userInfo){
return
}
wx.showLoading({ title: '处理中', mask: true })
getBaseInfo().then(result => {
this.setData({
avatarUrl: util.isEmpty(app.globalData.userInfo.avatarUrl) ? '/assets/image/ygImg.png' : app.globalData.userInfo.avatarUrl,
userInfo: app.globalData.userInfo,
userName: util.isEmpty(app.globalData.userInfo.userName) ? '' : app.globalData.userInfo.userName.substring(0, 14)
})
}).catch(err => { })
getMemberInfo().then(res => {
this.setData({ vipInfo: res.data, ['vipInfo.memberExpiredAt']: res.data.memberExpiredAt.substring(0, 10) })
wx.hideLoading()
}).catch(err => {
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 })
buyMemberInfo({ memberExpenseId: this.data.divIndex }).then(res => {
wx.hideLoading()
if(res.data.isNeedPay && res.data.orderId){
wx.navigateTo({ url: '/pages/withdrawal/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()
})
}
})