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ů.

207 lines
4.0KB

  1. // pages/coupon/coupon.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. type: 2, //1券码核销 2手机号核销
  9. user_phone: '', //手机号
  10. state: 0, //0核销未完成 1核销中 2核销已完成
  11. totalNums: 1, //总数量
  12. nums: 1, //核销数量
  13. coupon_name: '', //优惠券名称
  14. couponTime: '', //优惠券购买时间
  15. code_num: '', //核销短信验证码
  16. couponCode:'',//券号
  17. couponType:'',//券类型
  18. duration:'',//券期间
  19. },
  20. /**
  21. * 验证码修改
  22. */
  23. changeCode(event) {
  24. this.setData({
  25. code_num: event.detail.value
  26. })
  27. },
  28. /**
  29. * 核销
  30. */
  31. writeOff: function() {
  32. if (this.data.state == 1) {
  33. return
  34. }
  35. var data;
  36. if (this.data.type==1){//券核销
  37. data = {
  38. check_type: 1,
  39. coupon_code: this.data.couponCode,
  40. check_num: 1
  41. }
  42. }else{//手机号核销
  43. if (this.data.code_num.length != 6) {
  44. wx.showToast({
  45. title: '验证码错误',
  46. icon: 'none',
  47. duration: 2000
  48. })
  49. return
  50. }
  51. data = {
  52. check_type: 2,
  53. user_phone: this.data.user_phone,
  54. code_num: this.data.code_num,
  55. coupon_code: '',
  56. check_num: this.data.nums
  57. }
  58. }
  59. data.coupon_sell_id = app.globalData.couponData.coupon_sell_id;
  60. console.log(data);
  61. this.setData({
  62. state: 1
  63. })
  64. var that=this;
  65. app.requestPost('couponbuy/check', data, res => {
  66. var state;
  67. if (res.code == 200) {
  68. state = 2;
  69. if (that.data.type == 2) {//手机号核销
  70. wx.switchTab({
  71. url: '../record/record'
  72. })
  73. }
  74. } else {
  75. state = 0;
  76. wx.showToast({
  77. title: res.message,
  78. icon: 'none',
  79. duration: 2000
  80. })
  81. }
  82. that.setData({
  83. state: state
  84. })
  85. })
  86. },
  87. /**
  88. * 添加优惠券
  89. */
  90. addCoupon() {
  91. if (this.data.nums + 1 <= this.data.totalNums) {
  92. this.setData({
  93. nums: this.data.nums + 1
  94. })
  95. }
  96. },
  97. /**
  98. * 减少优惠券
  99. */
  100. reduceCoupon() {
  101. if (this.data.nums - 1 > 0) {
  102. this.setData({
  103. nums: this.data.nums - 1
  104. })
  105. }
  106. },
  107. /**
  108. * 返回核销大厅
  109. */
  110. goHome(){
  111. wx.switchTab({
  112. url: '../home/home'
  113. })
  114. },
  115. /**
  116. * 生命周期函数--监听页面加载
  117. */
  118. onLoad: function(options) {
  119. wx.hideShareMenu();
  120. var code = options.code;
  121. var pohone = options.phone;
  122. var couponData = app.globalData.couponData;
  123. if (code) { //券码查询
  124. this.setData({
  125. type: 1,
  126. couponCode:code,
  127. coupon_name: couponData.coupon_name,
  128. couponTime: couponData.buy_date,
  129. couponType: couponData.coupon_type,
  130. duration: couponData.duration
  131. })
  132. }
  133. if (pohone) { //手机号查询
  134. this.setData({
  135. type: 2,
  136. user_phone: pohone,
  137. totalNums: couponData.num,
  138. coupon_name: couponData.coupon_name,
  139. couponTime: couponData.buy_date
  140. })
  141. /**
  142. * 发送验证码
  143. */
  144. app.requestGet('couponbuy/check/smscode', { user_phone: pohone},res=>{
  145. if(res.code==200){
  146. }else{
  147. wx.showToast({
  148. title: res.message,
  149. icon: 'none',
  150. duration: 2000
  151. })
  152. }
  153. })
  154. }
  155. },
  156. /**
  157. * 生命周期函数--监听页面初次渲染完成
  158. */
  159. onReady: function() {
  160. },
  161. /**
  162. * 生命周期函数--监听页面显示
  163. */
  164. onShow: function() {},
  165. /**
  166. * 生命周期函数--监听页面隐藏
  167. */
  168. onHide: function() {
  169. },
  170. /**
  171. * 生命周期函数--监听页面卸载
  172. */
  173. onUnload: function() {
  174. },
  175. /**
  176. * 页面相关事件处理函数--监听用户下拉动作
  177. */
  178. onPullDownRefresh: function() {
  179. },
  180. /**
  181. * 页面上拉触底事件的处理函数
  182. */
  183. onReachBottom: function() {
  184. },
  185. /**
  186. * 用户点击右上角分享
  187. */
  188. onShareAppMessage: function() {
  189. }
  190. })