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.

228 lines
4.9KB

  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.id;
  22. if (app.globalData.openId) {
  23. this.getTicketUser()
  24. } else {
  25. app.globalData.openidSuccessFuc = this.getTicketUser;
  26. }
  27. if(options.type==1){
  28. wx.setNavigationBarTitle({
  29. title: "购买代金券",
  30. })
  31. }else{
  32. wx.setNavigationBarTitle({
  33. title: "购买菜品券",
  34. })
  35. }
  36. },
  37. getTicketUser:function(){//获取优惠券信息
  38. app.wxRequest(app.globalData.httpUrl + 'couponsell/detail', { coupon_sell_id: this.data.id, from: 1}, e => {
  39. console.log(e)
  40. if (e.code == 200) {
  41. this.setData({
  42. ticketUser:e.data
  43. })
  44. }
  45. }, this)
  46. },
  47. /**
  48. * 生命周期函数--监听页面初次渲染完成
  49. */
  50. onReady: function () {
  51. },
  52. /**
  53. * 生命周期函数--监听页面显示
  54. */
  55. onShow: function () {
  56. },
  57. /**
  58. * 生命周期函数--监听页面隐藏
  59. */
  60. onHide: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面卸载
  64. */
  65. onUnload: function () {
  66. },
  67. /**
  68. * 页面相关事件处理函数--监听用户下拉动作
  69. */
  70. onPullDownRefresh: function () {
  71. },
  72. /**
  73. * 页面上拉触底事件的处理函数
  74. */
  75. onReachBottom: function () {
  76. },
  77. /**
  78. * 用户点击右上角分享
  79. */
  80. onShareAppMessage: function () {
  81. return {
  82. title: "老门框爆肚会员",
  83. path: "/pages/buyTicket/buyTicket?index="+this.data.id,
  84. success: res => {
  85. console.log(res, "转发成功")
  86. },
  87. }
  88. },
  89. addFn:function(){
  90. // if (this.data.num<5){
  91. this.data.num++;
  92. this.setData({
  93. buyNumber: this.data.num
  94. })
  95. // }
  96. },
  97. subtractFn:function(){
  98. if (this.data.num > 1) {
  99. this.data.num--;
  100. this.setData({
  101. buyNumber: this.data.num
  102. })
  103. }
  104. },
  105. buySuccess:function(){//购买下单
  106. var state = wx.getStorageSync('state');
  107. if (state == 1) {//已注册
  108. } else if (state == 0) {//未注册
  109. wx.navigateTo({
  110. url: '/pages/register/register',
  111. })
  112. return;
  113. } else if (state == -1) {
  114. app.globalData.userInfoBackFn = res => {//等待结果
  115. console.log(res)
  116. if (res) {
  117. } else {
  118. wx.navigateTo({
  119. url: '/pages/register/register',
  120. })
  121. return;
  122. }
  123. }
  124. }
  125. if (!this.data.buyNumber) {
  126. wx.showToast({
  127. title: '请先输入购买优惠券的数量',
  128. icon: "none",
  129. duration: 2000
  130. })
  131. return;
  132. } else if (this.data.buyNumber == 0) {
  133. wx.showToast({
  134. title: '购买优惠券的数量最小为1',
  135. icon: "none",
  136. duration: 2000
  137. })
  138. return;
  139. }
  140. console.log(this.data.yesClick)
  141. if (this.data.yesClick){
  142. return;
  143. }
  144. this.data.yesClick = true;
  145. app.wxRequest(app.globalData.httpUrl + 'front/order/setting', { coupon_sell_id: this.data.ticketUser.coupon_sell_id, buy_num: this.data.buyNumber}, e => {
  146. console.log(e)
  147. if (e.code == 200) {
  148. this.setData({
  149. orderUser: e.data.submit,
  150. sign_num: e.data.sign_num
  151. })
  152. wx.requestPayment({
  153. timeStamp: this.data.orderUser.timeStamp,
  154. nonceStr: this.data.orderUser.nonceStr,
  155. package: this.data.orderUser.package,
  156. signType: this.data.orderUser.signType,
  157. paySign: this.data.orderUser.paySign,
  158. success: res => {
  159. console.log(res)
  160. this.orderPay()
  161. },
  162. fail: res => {
  163. this.data.yesClick = false;
  164. },
  165. complete: res => {
  166. this.data.yesClick = false;
  167. }
  168. })
  169. } else if (e.code == -3003) {
  170. this.data.yesClick = false;
  171. wx.showToast({
  172. title: e.message,
  173. icon:"none",
  174. duration:2000
  175. })
  176. }
  177. }, this,"POST")
  178. },
  179. orderPay:function(){
  180. app.wxRequest(app.globalData.httpUrl + 'front/order/paidconfirm', { sign_num: this.data.sign_num}, e => {
  181. console.log(e)
  182. if (e.code == 200) {
  183. wx.switchTab({
  184. url: '/pages/personalCenter/personalCenter'
  185. })
  186. }
  187. }, this,"POST")
  188. },
  189. getInputVal:function(e){
  190. if (e.detail.value > 50) {
  191. wx.showToast({
  192. title: "最多购买50张",
  193. icon:"none",
  194. duration: 2000
  195. })
  196. this.setData({
  197. buyNumber: 1,
  198. ticketNum: 1
  199. })
  200. } else {
  201. this.setData({
  202. buyNumber: e.detail.value,
  203. num: e.detail.value
  204. })
  205. }
  206. console.log(this.data.buyNumber)
  207. },
  208. })