Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

189 Zeilen
4.0KB

  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. return {
  73. title: "老门框爆肚会员",
  74. path: "/pages/register/register",
  75. success: res => {
  76. console.log(res, "转发成功")
  77. },
  78. }
  79. },
  80. addFn:function(){
  81. // if (this.data.num<5){
  82. this.data.num++;
  83. this.setData({
  84. buyNumber: this.data.num
  85. })
  86. // }
  87. },
  88. subtractFn:function(){
  89. if (this.data.num > 1) {
  90. this.data.num--;
  91. this.setData({
  92. buyNumber: this.data.num
  93. })
  94. }
  95. },
  96. buySuccess:function(){//购买下单
  97. if (!this.data.buyNumber) {
  98. wx.showToast({
  99. title: '请先输入购买优惠券的数量',
  100. icon: "none",
  101. duration: 2000
  102. })
  103. return;
  104. } else if (this.data.buyNumber == 0) {
  105. wx.showToast({
  106. title: '购买优惠券的数量最小为1',
  107. icon: "none",
  108. duration: 2000
  109. })
  110. return;
  111. }
  112. if (this.data.yesClick){
  113. return;
  114. }
  115. this.data.yesClick = true;
  116. app.wxRequest(app.globalData.httpUrl + 'order/set', { coupon_sell_id: this.data.ticketUser.coupon_sell_id, buy_num: this.data.buyNumber}, e => {
  117. console.log(e)
  118. if (e.code == 200) {
  119. this.setData({
  120. orderUser: e.data.submit,
  121. sign_num: e.data.sign_num
  122. })
  123. wx.requestPayment({
  124. timeStamp: this.data.orderUser.timeStamp,
  125. nonceStr: this.data.orderUser.nonceStr,
  126. package: this.data.orderUser.package,
  127. signType: this.data.orderUser.signType,
  128. paySign: this.data.orderUser.paySign,
  129. success: res => {
  130. console.log(res)
  131. this.orderPay()
  132. },
  133. })
  134. } else if (e.code == -3003){
  135. wx.showToast({
  136. title: e.message,
  137. icon:"none",
  138. duration:500
  139. })
  140. }
  141. }, this,"POST")
  142. },
  143. orderPay:function(){
  144. app.wxRequest(app.globalData.httpUrl + 'order/paid', { sign_num: this.data.sign_num}, e => {
  145. console.log(e)
  146. if (e.code == 200) {
  147. this.data.yesClick = false;
  148. wx.reLaunch({
  149. url: '/pages/personalCenter/personalCenter'
  150. })
  151. }
  152. }, this,"POST")
  153. },
  154. getInputVal:function(e){
  155. if (e.detail.value > 50) {
  156. wx.showToast({
  157. title: "最多购买50张",
  158. icon:"none",
  159. duration: 2000
  160. })
  161. this.setData({
  162. buyNumber: 1,
  163. ticketNum: 1
  164. })
  165. } else {
  166. this.setData({
  167. buyNumber: e.detail.value,
  168. num: e.detail.value
  169. })
  170. }
  171. console.log(this.data.buyNumber)
  172. },
  173. })