coupon.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const App = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. // 优惠券列表
  8. list: [],
  9. // show
  10. notcont: false
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function(options) {
  16. // 当前页面参数
  17. this.data.options = options;
  18. },
  19. /**
  20. * 生命周期函数--监听页面显示
  21. */
  22. onShow: function() {
  23. // 获取优惠券列表
  24. this.getCouponList();
  25. },
  26. /**
  27. * 获取优惠券列表
  28. */
  29. getCouponList: function() {
  30. let _this = this;
  31. App._get('coupon/lists', {}, function(result) {
  32. _this.setData({
  33. list: result.data.list,
  34. notcont: !result.data.list.length
  35. });
  36. });
  37. },
  38. /**
  39. * 立即领取
  40. */
  41. receive: function(e) {
  42. let _this = this,
  43. couponId = e.currentTarget.dataset.couponId;
  44. App._post_form('user.coupon/receive', {
  45. coupon_id: couponId
  46. }, function(result) {
  47. App.showSuccess(result.msg);
  48. // 获取优惠券列表
  49. _this.getCouponList();
  50. });
  51. },
  52. });