// pages/buyTicket/buyTicket.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { buyNumber:1,//购买数量 num : 1, ticketUser: [],//优惠券信息 orderUser:[],//下单信息 sign_num:"",//确认支付参数 id:"", yesClick:false,//防止购买按钮多次点击 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log(options) this.data.id = options.index; if (app.globalData.openId) { this.getTicketUser() } else { app.globalData.openidSuccessFuc = this.getTicketUser; } }, getTicketUser:function(){//获取优惠券信息 app.wxRequest(app.globalData.httpUrl + 'couponsell/detail', { coupon_sell_id: this.data.id, from: 1}, e => { console.log(e) if (e.code == 200) { this.setData({ ticketUser:e.data }) } }, this) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, addFn:function(){ // if (this.data.num<5){ this.data.num++; this.setData({ buyNumber: this.data.num }) // } }, subtractFn:function(){ if (this.data.num > 1) { this.data.num--; this.setData({ buyNumber: this.data.num }) } }, buySuccess:function(){//购买下单 if (this.data.yesClick){ return; } app.wxRequest(app.globalData.httpUrl + 'order/set', { coupon_sell_id: this.data.ticketUser.coupon_sell_id, buy_num: this.data.buyNumber}, e => { this.data.yesClick = true; console.log(e) if (e.code == 200) { this.setData({ orderUser: e.data.submit, sign_num: e.data.sign_num }) wx.requestPayment({ timeStamp: this.data.orderUser.timeStamp, nonceStr: this.data.orderUser.nonceStr, package: this.data.orderUser.package, signType: this.data.orderUser.signType, paySign: this.data.orderUser.paySign, success: res => { console.log(res) this.orderPay() }, }) } else if (e.code == -3003){ wx.showToast({ title: e.message, icon:"none", duration:500 }) } }, this,"POST") }, orderPay:function(){ app.wxRequest(app.globalData.httpUrl + 'order/paid', { sign_num: this.data.sign_num}, e => { console.log(e) if (e.code == 200) { this.data.yesClick = false; wx.reLaunch({ url: '/pages/personalCenter/personalCenter' }) } }, this,"POST") }, getInputVal:function(e){ if (e.detail.value > 50) { wx.showToast({ title: "最多购买50张", icon:"none", duration: 2000 }) this.setData({ buyNumber: 1, ticketNum: 1 }) } else { this.setData({ buyNumber: e.detail.value, num: e.detail.value }) } console.log(this.data.buyNumber) }, })