index.js 1.2 KB

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