index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. attached: function () {
  24. console.log(this.data.cartId)
  25. },
  26. methods: {
  27. close: function () {
  28. this.triggerEvent('ChangCouponsClone')
  29. },
  30. getCouponUser: function (e) {
  31. var that = this
  32. var id = e.currentTarget.dataset.id
  33. var index = e.currentTarget.dataset.index
  34. var list = that.data.coupon.list
  35. if (list[index].is_use == true && this.data.openType == 0) return true
  36. switch (this.data.openType) {
  37. case 0:
  38. //领取优惠券
  39. setCouponReceive(id).then(res => {
  40. list[index].is_use = true
  41. that.setData({
  42. ['coupon.list']: list
  43. })
  44. app.Tips({
  45. title: '领取成功'
  46. })
  47. that.triggerEvent('ChangCoupons', list[index])
  48. })
  49. break
  50. case 1:
  51. that.triggerEvent('ChangCoupons', index)
  52. break
  53. }
  54. }
  55. }
  56. })