getCoupon.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. var app = getApp();
  2. var status = require('../../utils/index.js');
  3. Page({
  4. data: {
  5. list: []
  6. },
  7. coupon_id: '',
  8. onLoad: function (options) {
  9. status.setNavBgColor();
  10. let coupon_id = options.id || '';
  11. this.coupon_id = coupon_id;
  12. },
  13. onShow: function () {
  14. this.getData();
  15. },
  16. getData: function () {
  17. let coupon_id = this.coupon_id;
  18. let token = wx.getStorageSync('token');
  19. app.util.ProReq('user.collect_voucher', {
  20. token,
  21. coupon_id,
  22. }).then(res => {
  23. let list = res.list;
  24. this.setData({ list })
  25. })
  26. .catch(err => {})
  27. },
  28. receiveCoupon: function (event) {
  29. let idx = event.currentTarget.dataset.idx;
  30. var token = wx.getStorageSync('token');
  31. var list = this.data.list;
  32. var that = this;
  33. app.util.request({
  34. url: 'entry/wxapp/index',
  35. data: { controller: 'goods.getQuan', token, quan_id: list[idx].id },
  36. dataType: 'json',
  37. success: function (msg) {
  38. //1 被抢光了 2 已领过 3 领取成功
  39. if (msg.data.code == 0) {
  40. wx.showToast({
  41. title: msg.data.msg || '被抢光了',
  42. icon: 'none'
  43. })
  44. } else if (msg.data.code == 1) {
  45. list[idx].is_nomore = 1;
  46. list[idx].is_use = 1;
  47. that.setData({ list })
  48. wx.showToast({
  49. title: '被抢光了',
  50. icon: 'none'
  51. })
  52. } else if (msg.data.code == 2) {
  53. wx.showToast({
  54. title: '已领取',
  55. icon: 'none'
  56. })
  57. that.getData();
  58. }
  59. else if (msg.data.code == 4) {
  60. wx.showToast({
  61. title: '新人专享',
  62. icon: 'none'
  63. })
  64. }
  65. else if (msg.data.code == 3) {
  66. that.getData();
  67. wx.showToast({
  68. title: '领取成功',
  69. })
  70. } else if (msg.data.code == 4) {
  71. // 未登录
  72. app.util.message('请先登录', '/lionfish_comshop/pages/user/me', 'error');
  73. }
  74. }
  75. })
  76. }
  77. })