index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const statusMap = {
  2. default: { text: '去使用', theme: 'primary' },
  3. useless: { text: '已使用', theme: 'default' },
  4. disabled: { text: '已过期', theme: 'default' },
  5. };
  6. Component({
  7. options: {
  8. addGlobalClass: true,
  9. multipleSlots: true, // 在组件定义时的选项中启用多slot支持
  10. },
  11. externalClasses: ['coupon-class'],
  12. properties: {
  13. couponDTO: {
  14. type: Object,
  15. value: {}, // 优惠券数据
  16. },
  17. },
  18. data: {
  19. btnText: '',
  20. btnTheme: '',
  21. },
  22. observers: {
  23. couponDTO: function (couponDTO) {
  24. if (!couponDTO) {
  25. return;
  26. }
  27. const statusInfo = statusMap[couponDTO.status];
  28. this.setData({
  29. btnText: statusInfo.text,
  30. btnTheme: statusInfo.theme,
  31. });
  32. },
  33. },
  34. attached() {},
  35. methods: {
  36. // 跳转到详情页
  37. gotoDetail() {
  38. wx.navigateTo({
  39. url: `/pages/coupon/coupon-detail/index?id=${this.data.couponDTO.key}`,
  40. });
  41. },
  42. // 跳转到商品列表
  43. gotoGoodsList() {
  44. wx.navigateTo({
  45. url: `/pages/coupon/coupon-activity-goods/index?id=${this.data.couponDTO.key}`,
  46. });
  47. },
  48. },
  49. });