139 lines
3.1 KiB
JavaScript
139 lines
3.1 KiB
JavaScript
// user/upgradeCart/upgradeCart.js
|
|
const app = getApp();
|
|
const regeneratorRuntime = app.loadAsync()
|
|
const model = app.loadModel("index")
|
|
const http = app.loadHttp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
system: app.globalData.system, //设备相关信息
|
|
pageTitle: "办卡/升级卡", //头部标题
|
|
isBack: true,//显示返回
|
|
isLoading: true,//加载显示关闭
|
|
cardCur: 0,//轮播当前下表
|
|
swiperList: [],
|
|
cardType: 0,// 购买或需要升级的卡类型
|
|
openType: 0,//0升级 1购买
|
|
is_upgrade: 0,
|
|
card_upgrade: null,
|
|
card_id: 0
|
|
},
|
|
// cardSwiper
|
|
cardSwiper(e) {
|
|
this.setData({
|
|
cardCur: e.detail.current
|
|
})
|
|
},
|
|
// tab切换Swiper
|
|
tabSwiper(e) {
|
|
let index = e.currentTarget.dataset.index
|
|
this.setData({
|
|
cardCur: index
|
|
})
|
|
},
|
|
//获取用户可升级的会员卡和可购买的卡
|
|
async getUpgradeCard() {
|
|
let res = await http.http.request2({ url: `${http.api.getUpgradeCard}`, method: 'POST', data: { type: this.data.cardType, card_id: this.data.card_id } })
|
|
this.setData({
|
|
swiperList: res.data.data,
|
|
isLoading: false
|
|
})
|
|
},
|
|
// 用户会员卡购买/升级
|
|
async cardUpgrade() {
|
|
let userInfo = app.globalData.userInfo
|
|
if (typeof userInfo['telnum'] == 'string' && (userInfo['telnum'] == "未授权手机号" || userInfo['telnum'] == '')) {
|
|
wx.showModal({
|
|
title: '未授权手机号不能办卡哦!!!',
|
|
content: '点击确定前往授权手机号',
|
|
success(res) {
|
|
if (res.confirm) {
|
|
wx.navigateTo({
|
|
url: '/pages/login/login'
|
|
})
|
|
}
|
|
}
|
|
})
|
|
return
|
|
}
|
|
let swiperList = this.data.swiperList[this.data.cardCur]
|
|
let data = {
|
|
type: this.data.cardType,
|
|
card_id: swiperList.id,
|
|
total_money: swiperList.recharge_money,
|
|
card_upgrade: this.data.card_upgrade,
|
|
is_upgrade: this.data.is_upgrade
|
|
}
|
|
let res = await model.payment.pay(http.api.cardUpgrade, data)
|
|
if (res == 1) {
|
|
wx.navigateTo({
|
|
url: "/user/upgradeCart/paid/paid?name=支付成功"
|
|
})
|
|
}
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({
|
|
cardType: options.type,
|
|
openType: options.openType,
|
|
is_upgrade: options.is_upgrade,
|
|
card_upgrade: options.card_upgrade,
|
|
card_id: options.card_id,
|
|
pageTitle: options.openType == 1 ? '办卡' : '升级'
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
this.getUpgradeCard()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |