1
0

coupon.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. },
  56. onReady: function () {
  57. },
  58. onShow: function () {
  59. let userInfo = wx.getStorageSync('userInfo');
  60. let token = wx.getStorageSync('token');
  61. if (userInfo && token) {
  62. this.getCouponList();
  63. this.getTicketDiscountList();
  64. } else {
  65. wx.navigateTo({
  66. url: '/pages/ucenter/userLogin/userLogin'
  67. })
  68. }
  69. },
  70. onHide: function () {
  71. // 页面隐藏
  72. },
  73. onUnload: function () {
  74. // 页面关闭
  75. },
  76. /**
  77. * 查看用户已领取的优惠券
  78. */
  79. getCouponList() {
  80. wx.showLoading({
  81. title: '加载中...',
  82. });
  83. let that = this;
  84. util.request(api.CouponList, { coupon_number: that.data.couponNumber, discStatus: that.data.discStatus}).then(function (res) {
  85. if (res.errno === 0) {
  86. that.setData({
  87. couponList: res.data
  88. });
  89. wx.hideLoading();
  90. }
  91. });
  92. },
  93. /**
  94. * 查看优惠券列表
  95. */
  96. getTicketDiscountList() {
  97. let that = this;
  98. util.request(api.TicketDiscountList, { storeId: wx.getStorageSync('storeId')}).then(function (res) {
  99. if (res.errno === 0) {
  100. // console.log(res.data);
  101. that.setData({
  102. ticketDiscountList: res.data
  103. });
  104. }
  105. });
  106. },
  107. /**
  108. * 兑换优惠券,暂时无用
  109. */
  110. exchangeCoupon() {
  111. var that = this;
  112. if (that.data.couponNumber.length == 0
  113. && that.data.couponNumber == '0') {
  114. wx.showModal({
  115. title: '错误信息',
  116. content: '优惠码不能为空',
  117. showCancel: false
  118. });
  119. return false;
  120. }
  121. util.request(api.CouponExchange, {
  122. coupon_number: that.data.couponNumber
  123. }, 'POST').then(function (res) {
  124. if (res.errno === 0) {
  125. wx.showToast({
  126. title: '兑换成功'
  127. });
  128. that.getCouponList();
  129. } else if (res.errno === 1) {
  130. util.showErrorToast(res.errmsg);
  131. }
  132. });
  133. },
  134. /**
  135. * 优惠券可使用商品
  136. */
  137. linkCoupon(event){
  138. // let url = event.currentTarget.dataset.couponUrl;
  139. let tickDiscId = event.currentTarget.dataset.tickId;
  140. let storeTopicId = event.currentTarget.dataset.storeTopicId;
  141. let storeId = wx.getStorageSync('storeId');
  142. wx.navigateTo({
  143. url: '../ticketDiscountGoods/ticketDiscountGoods?tickDiscId=' + tickDiscId + '&&storeId=' + storeId + '&&storeTopicId=' + storeTopicId
  144. })
  145. },
  146. /**
  147. * 领取优惠券
  148. */
  149. getUserCoupon(event) {
  150. var that = this;
  151. let tickDiscId = event.currentTarget.dataset.couponId;
  152. let storeTopicId = event.currentTarget.dataset.storeTopicId;
  153. let storeId = wx.getStorageSync('storeId');
  154. util.request(api.getUserCoupon, {
  155. tickDiscId: tickDiscId,
  156. storeTopicId: storeTopicId,
  157. storeId: storeId
  158. }, 'POST').then(function (res) {
  159. if (res.errno === 0) {
  160. wx.showToast({
  161. title: '领取成功'
  162. });
  163. that.setData({
  164. discStatus: 0,
  165. tabIndex: 0
  166. });
  167. that.getCouponList();
  168. that.getTicketDiscountList();
  169. } else {
  170. wx.showToast({
  171. title: res.errmsg,
  172. icon: 'none'
  173. })
  174. }
  175. });
  176. },
  177. clearData: function () {
  178. let that = this;
  179. that.setData({
  180. couponNumber: ''
  181. });
  182. },
  183. /**
  184. * 去逛逛
  185. */
  186. toIndexPage: function () {
  187. wx.switchTab({
  188. url: "/pages/index/index"
  189. });
  190. },
  191. getCouponDetail(event) {
  192. // let url = event.currentTarget.dataset.couponUrl;
  193. let couponId = event.currentTarget.dataset.couponId;
  194. let storeTopicId = event.currentTarget.dataset.storeTopicId;
  195. let storeId = wx.getStorageSync('storeId');
  196. if (this.data.discStatus == 0) {
  197. wx.navigateTo({
  198. url: '../couponDetail/couponDetail?couponId=' + couponId + '&&storeId=' + storeId + '&&storeTopicId=' + storeTopicId + "&&isShare=2"
  199. })
  200. }else{
  201. if(this.data.discStatus == 1){
  202. wx.showToast({
  203. title: '该优惠券已使用',
  204. icon: 'none'
  205. })
  206. }else{
  207. wx.showToast({
  208. title: '该优惠券已过期',
  209. icon: 'none'
  210. })
  211. }
  212. }
  213. },
  214. getCouponDetail2(event) {
  215. // let url = event.currentTarget.dataset.couponUrl;
  216. let discId = event.currentTarget.dataset.discId;
  217. let storeTopicId = event.currentTarget.dataset.storeTopicId;
  218. let storeId = wx.getStorageSync('storeId');
  219. wx.navigateTo({
  220. url: '../couponDetail/couponDetail?discId=' + discId + '&&storeId=' + storeId + '&&storeTopicId=' + storeTopicId + "&&isShare=0"
  221. })
  222. },
  223. })