index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {
  2. setCouponReceive
  3. } from '../../api/api.js';
  4. const app = getApp();
  5. Component({
  6. properties: {
  7. coupon: {
  8. type: Object,
  9. value: {
  10. list: [],
  11. statusTile: ''
  12. },
  13. },
  14. cartId: {
  15. type: String,
  16. value: '',
  17. },
  18. //打开状态 0=领取优惠券,1=使用优惠券
  19. openType: {
  20. type: Number,
  21. value: 0,
  22. }
  23. },
  24. data: {},
  25. attached: function () {
  26. console.log(this.data.cartId)
  27. },
  28. methods: {
  29. close: function () {
  30. this.triggerEvent('ChangCouponsClone');
  31. },
  32. getCouponUser: function (e) {
  33. var that = this;
  34. var id = e.currentTarget.dataset.id;
  35. var index = e.currentTarget.dataset.index;
  36. var list = that.data.coupon.list;
  37. if (list[index].is_use == true && this.data.openType == 0) return true;
  38. switch (this.data.openType) {
  39. case 0:
  40. //领取优惠券
  41. setCouponReceive(id).then(res => {
  42. list[index].is_use = true;
  43. that.setData({
  44. ['coupon.list']: list
  45. });
  46. app.Tips({
  47. title: '领取成功'
  48. });
  49. that.triggerEvent('ChangCoupons', list[index]);
  50. });
  51. break;
  52. case 1:
  53. that.triggerEvent('ChangCoupons', index);
  54. break;
  55. }
  56. },
  57. }
  58. })