会员模块
This commit is contained in:
204
pages/member/index.js
Normal file
204
pages/member/index.js
Normal file
@@ -0,0 +1,204 @@
|
||||
// pages/member/index.js
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
userLogin : '', //登录状态
|
||||
avatar : '', //头像
|
||||
nickName : '', //昵称
|
||||
identityId : '', //用户id
|
||||
identityShow : '', //身份有效期
|
||||
tabType : 2, // 会员选项
|
||||
identitiesData : [],
|
||||
interestData : '', // 会员权益
|
||||
vipsData : '', //会员公告
|
||||
barHeight : getApp().globalData.statusBarHeight, // 状态栏高度
|
||||
jiaonangheight : getApp().globalData.jiaonangheight, //胶囊高度
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
// 获取登录状态
|
||||
if(wx.getStorageSync("token")){
|
||||
this.setData({
|
||||
userLogin: true
|
||||
})
|
||||
|
||||
// 获取用户信息
|
||||
this.userInfo();
|
||||
}
|
||||
// 获取身份前置
|
||||
this.identityInfo();
|
||||
|
||||
// 获取身份权益
|
||||
this.openTab();
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
userInfo() {
|
||||
wx.$api.user.home().then(res => {
|
||||
this.setData({
|
||||
userData : res.data,
|
||||
avatar : res.data.avatar,
|
||||
nickName : res.data.nickname,
|
||||
identityId : res.data.identity.id,
|
||||
identityShow : res.data.identityShow
|
||||
})
|
||||
|
||||
}).catch(err => {})
|
||||
},
|
||||
|
||||
/**
|
||||
* 身份前置
|
||||
*/
|
||||
identityInfo(){
|
||||
wx.$api.member.openModel().then(res => {
|
||||
this.setData({
|
||||
identitiesData : res.data.identities,
|
||||
vipsData : res.data.vips
|
||||
})
|
||||
|
||||
}).catch(err => {})
|
||||
},
|
||||
|
||||
/**
|
||||
* 切换身份
|
||||
*/
|
||||
typeClick(e) {
|
||||
this.setData({
|
||||
tabType: e.currentTarget.dataset.type
|
||||
})
|
||||
// 获取身份权益
|
||||
this.openTab();
|
||||
},
|
||||
|
||||
/**
|
||||
* 身份权益
|
||||
*/
|
||||
openTab() {
|
||||
// 3为金卡,4为钻卡
|
||||
wx.$api.member.openSee(this.data.tabType).then(res => {
|
||||
this.setData({
|
||||
interestData: res.data
|
||||
})
|
||||
}).catch(err => {})
|
||||
},
|
||||
|
||||
/**
|
||||
* 截获竖向滑动
|
||||
*/
|
||||
catchTouchMove(){
|
||||
return false
|
||||
},
|
||||
|
||||
/**
|
||||
* 处理未登录时的转跳
|
||||
*/
|
||||
userNav(e){
|
||||
let pageUrl = e.currentTarget.dataset.url
|
||||
if(wx.getStorageSync("token")){
|
||||
// 微信支付-线上支付
|
||||
if(this.data.interestData.channel.value == 1) {
|
||||
this.wxPay();
|
||||
return
|
||||
}
|
||||
// 上传打款凭证
|
||||
wx.navigateTo({
|
||||
url: pageUrl
|
||||
})
|
||||
}else{
|
||||
// 去登录
|
||||
wx.navigateTo({
|
||||
url: "/pages/login/index"
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 立即续费
|
||||
*/
|
||||
renewTap() {
|
||||
// 微信支付-线上支付
|
||||
if(this.data.interestData.channel.value == 1) {
|
||||
this.wxPay();
|
||||
return
|
||||
}
|
||||
// 上传打款凭证-线下支付
|
||||
wx.navigateTo({
|
||||
url: "/pages/member/open/open?identity_id=" + this.data.interestData.identity_id
|
||||
})
|
||||
},
|
||||
|
||||
// 微信支付
|
||||
wxPay() {
|
||||
wx.showLoading({
|
||||
title: '支付中...',
|
||||
mask : true
|
||||
})
|
||||
let that = this
|
||||
wx.login({
|
||||
success: res => {
|
||||
wx.$api.member.openid(res).then(openidRes => {
|
||||
wx.$api.member.openIndex(that.data.interestData.identity_id,{}).then(memberRes => {
|
||||
wx.hideLoading()
|
||||
wx.$api.member.identityPay(memberRes.data.order_id, {
|
||||
channel: 'miniapp',
|
||||
openid : openidRes.data
|
||||
}).then(PayRes => {
|
||||
let payInfo = JSON.parse(PayRes.data.wechat)
|
||||
wx.requestPayment({
|
||||
timeStamp: payInfo.timeStamp,
|
||||
nonceStr : payInfo.nonceStr,
|
||||
package : payInfo.package,
|
||||
paySign : payInfo.paySign,
|
||||
signType : payInfo.signType,
|
||||
success : payInfoRes=>{
|
||||
if(payInfoRes.errMsg == "requestPayment:ok"){
|
||||
wx.showToast({
|
||||
title: '支付成功',
|
||||
icon : 'success'
|
||||
})
|
||||
setTimeout(()=>{
|
||||
wx.switchTab({
|
||||
url: '/pages/user/index'
|
||||
})
|
||||
},3000)
|
||||
}
|
||||
},
|
||||
fail : res=>{
|
||||
wx.showToast({
|
||||
title: '取消支付',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
}).catch(err => {})
|
||||
}).catch(err => {})
|
||||
}).catch(err => {})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 查看驳回原因
|
||||
*/
|
||||
tapCause(e) {
|
||||
wx.showModal({
|
||||
title : '驳回原因',
|
||||
content : e.currentTarget.dataset.text,
|
||||
showCancel: false,
|
||||
success : res=> {}
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user