1
0

coupon.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. couponList: [],
  7. couponNumber: '',
  8. tabList: ['未使用', '已使用', '已过期'],
  9. discStatus: '',
  10. tabIndex: 0,
  11. ticketDiscountList:[]
  12. },
  13. toggleTab(e) {
  14. this.setData({
  15. tabIndex: e.currentTarget.dataset.index,
  16. couponList: [],
  17. page: 1,
  18. });
  19. this.switchDiscStatus(e.currentTarget.dataset.index);
  20. },
  21. /**
  22. * 根据使用类型查询用户已领取的优惠券列表
  23. */
  24. switchDiscStatus(tabIndex) {
  25. let that = this;
  26. if (tabIndex == 0) {
  27. that.setData({
  28. discStatus: 0
  29. });
  30. } else if (tabIndex == 1) {
  31. that.setData({
  32. discStatus: 1
  33. });
  34. } else if (tabIndex == 2) {
  35. that.setData({
  36. discStatus: 2
  37. });
  38. }
  39. that.getCouponList();
  40. this.getTicketDiscountList();
  41. },
  42. /**
  43. * 暂时无用,兑换码触发
  44. */
  45. bindCouponNumberInput: function (e) {
  46. this.setData({
  47. couponNumber: e.detail.value
  48. });
  49. },
  50. onLoad: function (options) {
  51. // 页面初始化 options为页面跳转所带来的参数
  52. this.setData({
  53. discStatus: 0
  54. });
  55. this.getCouponList();
  56. this.getTicketDiscountList();
  57. },
  58. onReady: function () {
  59. },
  60. onShow: function () {
  61. },
  62. onHide: function () {
  63. // 页面隐藏
  64. },
  65. onUnload: function () {
  66. // 页面关闭
  67. },
  68. /**
  69. * 查看用户已领取的优惠券
  70. */
  71. getCouponList() {
  72. wx.showLoading({
  73. title: '加载中...',
  74. });
  75. let that = this;
  76. util.request(api.CouponList, { coupon_number: that.data.couponNumber, discStatus: that.data.discStatus}).then(function (res) {
  77. if (res.errno === 0) {
  78. that.setData({
  79. couponList: res.data
  80. });
  81. wx.hideLoading();
  82. }
  83. });
  84. },
  85. /**
  86. * 查看优惠券列表
  87. */
  88. getTicketDiscountList() {
  89. let that = this;
  90. util.request(api.TicketDiscountList, { storeId: wx.getStorageSync('storeId')}).then(function (res) {
  91. if (res.errno === 0) {
  92. // console.log(res.data);
  93. that.setData({
  94. ticketDiscountList: res.data
  95. });
  96. }
  97. });
  98. },
  99. /**
  100. * 兑换优惠券,暂时无用
  101. */
  102. exchangeCoupon() {
  103. var that = this;
  104. if (that.data.couponNumber.length == 0
  105. && that.data.couponNumber == '0') {
  106. wx.showModal({
  107. title: '错误信息',
  108. content: '优惠码不能为空',
  109. showCancel: false
  110. });
  111. return false;
  112. }
  113. util.request(api.CouponExchange, {
  114. coupon_number: that.data.couponNumber
  115. }, 'POST').then(function (res) {
  116. if (res.errno === 0) {
  117. wx.showToast({
  118. title: '兑换成功'
  119. });
  120. that.getCouponList();
  121. } else if (res.errno === 1) {
  122. util.showErrorToast(res.errmsg);
  123. }
  124. });
  125. },
  126. /**
  127. * 优惠券可使用商品
  128. */
  129. linkCoupon(event){
  130. // let url = event.currentTarget.dataset.couponUrl;
  131. let tickDiscId = event.currentTarget.dataset.tickId;
  132. let storeTopicId = event.currentTarget.dataset.storeTopicId;
  133. let storeId = wx.getStorageSync('storeId');
  134. wx.navigateTo({
  135. url: '../ticketDiscountGoods/ticketDiscountGoods?tickDiscId=' + tickDiscId + '&&storeId=' + storeId + '&&storeTopicId=' + storeTopicId
  136. })
  137. },
  138. /**
  139. * 领取优惠券
  140. */
  141. getUserCoupon(event) {
  142. var that = this;
  143. let tickDiscId = event.currentTarget.dataset.couponId;
  144. let storeTopicId = event.currentTarget.dataset.storeTopicId;
  145. let storeId = wx.getStorageSync('storeId');
  146. util.request(api.getUserCoupon, {
  147. tickDiscId: tickDiscId,
  148. storeTopicId: storeTopicId,
  149. storeId: storeId
  150. }, 'POST').then(function (res) {
  151. if (res.errno === 0) {
  152. wx.showToast({
  153. title: '领取成功'
  154. });
  155. that.setData({
  156. discStatus: 0,
  157. tabIndex: 0
  158. });
  159. that.getCouponList();
  160. that.getTicketDiscountList();
  161. } else {
  162. wx.showToast({
  163. title: res.errmsg,
  164. icon: 'none'
  165. })
  166. }
  167. });
  168. },
  169. clearData: function () {
  170. let that = this;
  171. that.setData({
  172. couponNumber: ''
  173. });
  174. },
  175. /**
  176. * 去逛逛
  177. */
  178. toIndexPage: function () {
  179. wx.switchTab({
  180. url: "/pages/index/index"
  181. });
  182. },
  183. getCouponDetail(event) {
  184. // let url = event.currentTarget.dataset.couponUrl;
  185. let couponId = event.currentTarget.dataset.couponId;
  186. let storeTopicId = event.currentTarget.dataset.storeTopicId;
  187. let storeId = wx.getStorageSync('storeId');
  188. if (this.data.discStatus == 0) {
  189. wx.navigateTo({
  190. url: '../couponDetail/couponDetail?couponId=' + couponId + '&&storeId=' + storeId + '&&storeTopicId=' + storeTopicId + "&&isShare=2"
  191. })
  192. }else{
  193. if(this.data.discStatus == 1){
  194. wx.showToast({
  195. title: '该优惠券已使用',
  196. icon: 'none'
  197. })
  198. }else{
  199. wx.showToast({
  200. title: '该优惠券已过期',
  201. icon: 'none'
  202. })
  203. }
  204. }
  205. },
  206. getCouponDetail2(event) {
  207. // let url = event.currentTarget.dataset.couponUrl;
  208. let discId = event.currentTarget.dataset.discId;
  209. let storeTopicId = event.currentTarget.dataset.storeTopicId;
  210. let storeId = wx.getStorageSync('storeId');
  211. wx.navigateTo({
  212. url: '../couponDetail/couponDetail?discId=' + discId + '&&storeId=' + storeId + '&&storeTopicId=' + storeTopicId + "&&isShare=0"
  213. })
  214. },
  215. })