// pages/buyTicket/buyTicket.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { buyNumber:1,//购买数量 num : 1, ticketUser: [],//优惠券信息 orderUser:[],//下单信息 sign_num:"",//确认支付参数 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log(options) if (app.globalData.openId) { this.getTicketUser(options.index, 1) } else { app.globalData.openidSuccessFuc = this.getTicketUser; } }, getTicketUser:function(index,from){//获取优惠券信息 app.wxRequest(app.globalData.httpUrl + 'couponsell/detail', { coupon_sell_id: index, from: from}, 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(){//购买下单 app.wxRequest(app.globalData.httpUrl + 'order/set', { coupon_sell_id: this.data.ticketUser.coupon_sell_id, buy_num: this.data.buyNumber}, e => { 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, 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) { wx.reLaunch({ url: '/pages/personalCenter/personalCenter' }) } }, this,"POST") }, getInputVal:function(e){ // if (e.detail.value < 1) { // wx.showToast({ // title: "购买量最小为1", // duration: 1000 // }) // this.setData({ // buyNumber: 1, // ticketNum: 1 // }) // } else { // this.setData({ // buyNumber: e.detail.value, // num: e.detail.value // }) // } this.setData({ buyNumber: e.detail.value, num: e.detail.value }) console.log(this.data.buyNumber) }, })