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.

153 lines
3.2KB

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