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.

242 line
4.8KB

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