Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

221 lines
4.3KB

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