index.js 1.3 KB

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