var util = require('../../../utils/util.js'); var api = require('../../../config/api'); var user = require('../../../utils/user.js'); var app = getApp(); Page({ /** * 页面的初始数据 */ data: { buyType: '2', //1月卡 2年卡 oldPrice: '199', actualPrice: '199', typeList: [{ url:'https://jzmall.lifejingzhi.com/file/jzmall/weixin/memberCard-1229/member-type-1.png', type: '2', name: '年卡', price: '199', typeName: '年', oldPrice: '199' }, { url:'https://jzmall.lifejingzhi.com/file/jzmall/weixin/memberCard-1229/member-type-2.png', type: '1', name: '月卡', price: '19', typeName: '月', oldPrice: '19' }, { url:'https://jzmall.lifejingzhi.com/file/jzmall/weixin/memberCard-1229/member-type-3.png', type: '3', name: '年卡', }, ], memberUserInfo:{ nickName: '用户', avatarUrl: '/static/images/new/icon-user.png', level:'0' } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, switchType(e) { let type = e.currentTarget.dataset.type; let actualPrice = e.currentTarget.dataset.price; this.setData({ buyType: type, actualPrice: actualPrice, oldPrice: type == '2' ? '199' : '19' }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.setData({ memberUserInfo:app.globalData.memberUserInfo }); }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, payNow() { let that=this wx.showModal({ title: "会员开卡确认", content: "会员权益卡,购买后无法退换,确定购买?", showCancel: true, cancelText: "取消", cancelColor: "#000", confirmText: "购买", confirmColor: "#0f0", success: function (res) { if (res.confirm) { that.memberSubmit(); } } }) }, memberSubmit() { let orderInfo = { userId: app.globalData.userInfo.id, memberType: this.data.buyType, }; util.request(api.memberSubmit, orderInfo, 'POST').then(res => { if (res.errno === 0) { let orderId = res.data.memberOrderNo; this.prepayMember(orderId); } else { util.showErrorToast(res.errmsg); } }); }, prepayMember(orderId) { util.request(api.prepayMember, { memberOrderNo: orderId }, 'POST').then(res => { if (res.errno === 0) { let payParam = res.data; console.log("支付过程开始"); wx.requestPayment({ 'timeStamp': payParam.timeStamp, 'nonceStr': payParam.nonceStr, 'package': payParam.packageValue, 'signType': payParam.signType, 'paySign': payParam.paySign, 'success': res => { console.log("支付过程成功"); wx.redirectTo({ url: '/pages/member/becomeMember/becomeMember', }) }, 'fail': res => { console.log("支付过程失败"); util.showErrorToast('支付失败'); }, 'complete': function (res) { console.log("支付过程结束") } }); } else { util.showErrorToast(res.errmsg); } }); }, goConvert() { wx.navigateTo({ url: '/pages/member/memberConvert/memberConvert', }) }, })