You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

buyTicket.js 3.5KB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 > 50) {
  134. wx.showToast({
  135. title: "最多购买50张",
  136. icon:"none",
  137. duration: 2000
  138. })
  139. this.setData({
  140. buyNumber: 1,
  141. ticketNum: 1
  142. })
  143. } else {
  144. this.setData({
  145. buyNumber: e.detail.value,
  146. num: e.detail.value
  147. })
  148. }
  149. console.log(this.data.buyNumber)
  150. },
  151. })