Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

164 lines
3.4KB

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