Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

174 lines
3.3KB

  1. // pages/coupon/coupon.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. couponType:1,//1代金券 2菜品券
  9. coupon_img_large:'',//优惠券图片
  10. coupon_name_detail:'',//券名称
  11. coupon_memo:'',//券描述
  12. totalNums: 0, //总数量
  13. nums: 0, //核销数量
  14. writeOffing:false,
  15. original_price:100,//抵消金额
  16. },
  17. user_id:null,
  18. coupon_sell_id:null,
  19. /**
  20. * 核销数修改
  21. */
  22. changeNums(e) {
  23. var value=e.detail.value;
  24. var str=parseInt(value);
  25. if(str>this.data.totalNums){
  26. str=this.data.totalNums
  27. }
  28. this.setData({
  29. nums: str?str:0
  30. })
  31. },
  32. /**
  33. * 核销
  34. */
  35. writeOff: function() {
  36. if(!this.data.writeOffing){
  37. this.setData({
  38. writeOffing:true
  39. })
  40. var data={
  41. user_id:this.user_id,
  42. coupon_sell_id:this.coupon_sell_id,
  43. check_num:this.data.nums
  44. }
  45. app.requestPost('admin/buy/check',data,res=>{
  46. if(res.code==200){
  47. wx.showToast({
  48. title: '核销成功',
  49. icon: 'success',
  50. duration: 2000
  51. })
  52. this.getCouponDetails();
  53. // this.setData({
  54. // writeOffing:false,
  55. // totalNums:this.data.totalNums-this.data.nums,
  56. // nums:0
  57. // })
  58. }else{
  59. wx.showToast({
  60. title: res.message,
  61. icon: 'none',
  62. duration: 2000
  63. })
  64. this.setData({
  65. writeOffing:false
  66. })
  67. }
  68. })
  69. }
  70. },
  71. /**
  72. * 添加优惠券
  73. */
  74. addCoupon() {
  75. if (this.data.nums + 1 <= this.data.totalNums) {
  76. this.setData({
  77. nums: this.data.nums + 1
  78. })
  79. }
  80. },
  81. /**
  82. * 减少优惠券
  83. */
  84. reduceCoupon() {
  85. if (this.data.nums - 1 > 0) {
  86. this.setData({
  87. nums: this.data.nums - 1
  88. })
  89. }
  90. },
  91. /**
  92. * 返回核销大厅
  93. */
  94. goHome() {
  95. wx.switchTab({
  96. url: '../home/home'
  97. })
  98. },
  99. /**
  100. * 生命周期函数--监听页面加载
  101. */
  102. onLoad: function(options) {
  103. wx.hideShareMenu();
  104. this.user_id=options.user_id;
  105. this.coupon_sell_id=options.coupon_sell_id;
  106. this.getCouponDetails();
  107. },
  108. getCouponDetails(){
  109. app.requestGet('admin/buy/detail',{user_id:this.user_id,coupon_sell_id:this.coupon_sell_id},res=>{
  110. if(res.code==200){
  111. var {coupon_img_large,coupon_name_detail,coupon_memo,num,item_type:couponType,original_price}=res.data;
  112. this.setData({
  113. couponType,
  114. coupon_img_large,
  115. coupon_name_detail,
  116. coupon_memo,
  117. totalNums:num,
  118. writeOffing:false,
  119. original_price:parseInt(original_price)
  120. })
  121. app.globalData.couponToken = res.token;
  122. }
  123. })
  124. },
  125. /**
  126. * 生命周期函数--监听页面初次渲染完成
  127. */
  128. onReady: function() {
  129. },
  130. /**
  131. * 生命周期函数--监听页面显示
  132. */
  133. onShow: function() {},
  134. /**
  135. * 生命周期函数--监听页面隐藏
  136. */
  137. onHide: function() {
  138. },
  139. /**
  140. * 生命周期函数--监听页面卸载
  141. */
  142. onUnload: function() {
  143. },
  144. /**
  145. * 页面相关事件处理函数--监听用户下拉动作
  146. */
  147. onPullDownRefresh: function() {
  148. },
  149. /**
  150. * 页面上拉触底事件的处理函数
  151. */
  152. onReachBottom: function() {
  153. },
  154. /**
  155. * 用户点击右上角分享
  156. */
  157. onShareAppMessage: function() {
  158. }
  159. })