Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

171 linhas
3.6KB

  1. // pages/buyTicket/buyTicket.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. buyNumber:1,//购买数量
  9. num : 1,
  10. ticketUser: [],//优惠券信息
  11. orderUser:[],//下单信息
  12. sign_num:"",//确认支付参数
  13. id:"",
  14. yesClick:false,//防止购买按钮多次点击
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. console.log(options)
  21. this.data.id = options.index;
  22. if (app.globalData.openId) {
  23. this.getTicketUser()
  24. } else {
  25. app.globalData.openidSuccessFuc = this.getTicketUser;
  26. }
  27. },
  28. getTicketUser:function(){//获取优惠券信息
  29. app.wxRequest(app.globalData.httpUrl + 'couponsell/detail', { coupon_sell_id: this.data.id, from: 1}, e => {
  30. console.log(e)
  31. if (e.code == 200) {
  32. this.setData({
  33. ticketUser:e.data
  34. })
  35. }
  36. }, this)
  37. },
  38. /**
  39. * 生命周期函数--监听页面初次渲染完成
  40. */
  41. onReady: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面显示
  45. */
  46. onShow: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面隐藏
  50. */
  51. onHide: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面卸载
  55. */
  56. onUnload: function () {
  57. },
  58. /**
  59. * 页面相关事件处理函数--监听用户下拉动作
  60. */
  61. onPullDownRefresh: function () {
  62. },
  63. /**
  64. * 页面上拉触底事件的处理函数
  65. */
  66. onReachBottom: function () {
  67. },
  68. /**
  69. * 用户点击右上角分享
  70. */
  71. onShareAppMessage: function () {
  72. },
  73. addFn:function(){
  74. // if (this.data.num<5){
  75. this.data.num++;
  76. this.setData({
  77. buyNumber: this.data.num
  78. })
  79. // }
  80. },
  81. subtractFn:function(){
  82. if (this.data.num > 1) {
  83. this.data.num--;
  84. this.setData({
  85. buyNumber: this.data.num
  86. })
  87. }
  88. },
  89. buySuccess:function(){//购买下单
  90. if (this.data.yesClick){
  91. return;
  92. }
  93. app.wxRequest(app.globalData.httpUrl + 'order/set', { coupon_sell_id: this.data.ticketUser.coupon_sell_id, buy_num: this.data.buyNumber}, e => {
  94. this.data.yesClick = true;
  95. console.log(e)
  96. if (e.code == 200) {
  97. this.setData({
  98. orderUser: e.data.submit,
  99. sign_num: e.data.sign_num
  100. })
  101. wx.requestPayment({
  102. timeStamp: this.data.orderUser.timeStamp,
  103. nonceStr: this.data.orderUser.nonceStr,
  104. package: this.data.orderUser.package,
  105. signType: this.data.orderUser.signType,
  106. paySign: this.data.orderUser.paySign,
  107. success: res => {
  108. console.log(res)
  109. this.orderPay()
  110. },
  111. })
  112. } else if (e.code == -3003){
  113. wx.showToast({
  114. title: e.message,
  115. icon:"none",
  116. duration:500
  117. })
  118. }
  119. }, this,"POST")
  120. },
  121. orderPay:function(){
  122. app.wxRequest(app.globalData.httpUrl + 'order/paid', { sign_num: this.data.sign_num}, e => {
  123. console.log(e)
  124. if (e.code == 200) {
  125. this.data.yesClick = false;
  126. wx.reLaunch({
  127. url: '/pages/personalCenter/personalCenter'
  128. })
  129. }
  130. }, this,"POST")
  131. },
  132. getInputVal:function(e){
  133. // if (e.detail.value < 1) {
  134. // wx.showToast({
  135. // title: "购买量最小为1",
  136. // duration: 1000
  137. // })
  138. // this.setData({
  139. // buyNumber: 1,
  140. // ticketNum: 1
  141. // })
  142. // } else {
  143. // this.setData({
  144. // buyNumber: e.detail.value,
  145. // num: e.detail.value
  146. // })
  147. // }
  148. this.setData({
  149. buyNumber: e.detail.value,
  150. num: e.detail.value
  151. })
  152. console.log(this.data.buyNumber)
  153. },
  154. })