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.

219 lines
4.7KB

  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. success: res => {
  75. console.log(res, "转发成功")
  76. },
  77. }
  78. },
  79. addFn:function(){
  80. // if (this.data.num<5){
  81. this.data.num++;
  82. this.setData({
  83. buyNumber: this.data.num
  84. })
  85. // }
  86. },
  87. subtractFn:function(){
  88. if (this.data.num > 1) {
  89. this.data.num--;
  90. this.setData({
  91. buyNumber: this.data.num
  92. })
  93. }
  94. },
  95. buySuccess:function(){//购买下单
  96. var state = wx.getStorageSync('state');
  97. if (state == 1) {//已注册
  98. } else if (state == 0) {//未注册
  99. wx.navigateTo({
  100. url: '/pages/register/register',
  101. })
  102. return;
  103. } else if (state == -1) {
  104. app.globalData.userInfoBackFn = res => {//等待结果
  105. console.log(res)
  106. if (res) {
  107. } else {
  108. wx.navigateTo({
  109. url: '/pages/register/register',
  110. })
  111. return;
  112. }
  113. }
  114. }
  115. if (!this.data.buyNumber) {
  116. wx.showToast({
  117. title: '请先输入购买优惠券的数量',
  118. icon: "none",
  119. duration: 2000
  120. })
  121. return;
  122. } else if (this.data.buyNumber == 0) {
  123. wx.showToast({
  124. title: '购买优惠券的数量最小为1',
  125. icon: "none",
  126. duration: 2000
  127. })
  128. return;
  129. }
  130. console.log(this.data.yesClick)
  131. if (this.data.yesClick){
  132. return;
  133. }
  134. this.data.yesClick = true;
  135. app.wxRequest(app.globalData.httpUrl + 'order/set', { coupon_sell_id: this.data.ticketUser.coupon_sell_id, buy_num: this.data.buyNumber}, e => {
  136. console.log(e)
  137. if (e.code == 200) {
  138. this.setData({
  139. orderUser: e.data.submit,
  140. sign_num: e.data.sign_num
  141. })
  142. wx.requestPayment({
  143. timeStamp: this.data.orderUser.timeStamp,
  144. nonceStr: this.data.orderUser.nonceStr,
  145. package: this.data.orderUser.package,
  146. signType: this.data.orderUser.signType,
  147. paySign: this.data.orderUser.paySign,
  148. success: res => {
  149. console.log(res)
  150. this.orderPay()
  151. },
  152. fail: res => {
  153. this.data.yesClick = false;
  154. },
  155. complete: res => {
  156. this.data.yesClick = false;
  157. }
  158. })
  159. } else if (e.code == -3003) {
  160. this.data.yesClick = false;
  161. wx.showToast({
  162. title: e.message,
  163. icon:"none",
  164. duration:2000
  165. })
  166. }
  167. }, this,"POST")
  168. },
  169. orderPay:function(){
  170. app.wxRequest(app.globalData.httpUrl + 'order/paid', { sign_num: this.data.sign_num}, e => {
  171. console.log(e)
  172. if (e.code == 200) {
  173. wx.switchTab({
  174. url: '/pages/personalCenter/personalCenter'
  175. })
  176. }
  177. }, this,"POST")
  178. },
  179. getInputVal:function(e){
  180. if (e.detail.value > 50) {
  181. wx.showToast({
  182. title: "最多购买50张",
  183. icon:"none",
  184. duration: 2000
  185. })
  186. this.setData({
  187. buyNumber: 1,
  188. ticketNum: 1
  189. })
  190. } else {
  191. this.setData({
  192. buyNumber: e.detail.value,
  193. num: e.detail.value
  194. })
  195. }
  196. console.log(this.data.buyNumber)
  197. },
  198. })