index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // components/couponWrap/index.js
  2. import { parseTime } from '../../utils/util';
  3. import activity from '../../api/activity'
  4. Component({
  5. externalClasses: ['class', 'coupon-circule-ex-class', 'coupon-item-ex-class'],
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. couponList: {
  11. type: Array,
  12. default: []
  13. }
  14. },
  15. /**
  16. * 组件的初始数据
  17. */
  18. data: {
  19. flodMap: {
  20. }
  21. },
  22. lifetimes: {
  23. attached: function() {
  24. // this.prepareData()
  25. }
  26. },
  27. observers: {
  28. 'couponList'(dataA) {
  29. this.prepareData()
  30. },
  31. },
  32. /**
  33. * 组件的方法列表
  34. */
  35. methods: {
  36. prepareData() {
  37. this.data.couponList.forEach(v => {
  38. v.validTimesStr = this.validTimes(v)
  39. if (typeof (v.type || v.couponType) == "string") {
  40. v.type = { value: (v.type || v.couponType) }
  41. } else {
  42. v.type = v.type || v.couponType
  43. }
  44. v.title = v.title || v.couponName || v.couponTitle
  45. })
  46. this.setData({
  47. list: this.data.couponList
  48. })
  49. },
  50. exFoldPanel(e) {
  51. const index = e.currentTarget.dataset.index
  52. if (this.data.flodMap[index]) {
  53. this.data.flodMap[index] = false
  54. this.setData({
  55. flodMap: this.data.flodMap
  56. })
  57. } else {
  58. this.loadCouponData(index)
  59. }
  60. },
  61. loadCouponData(index) {
  62. if (this.data.list[index].isLoadCouponDetail) {
  63. this.data.flodMap[index] = true
  64. this.setData({
  65. flodMap: this.data.flodMap
  66. })
  67. return
  68. }
  69. activity.getCouponDetailData({ couponId: this.data.list[index].couponId }).then( res => {
  70. if (res.code == 200) {
  71. const data = res.data || {}
  72. Object.assign(this.data.list[index], {
  73. description: data.description || '',
  74. bindShopType: data.bindShopType || 1,
  75. bindGoodsType: data.bindGoodsType || 1,
  76. isLoadCouponDetail: true
  77. })
  78. this.data.flodMap[index] = true
  79. this.setData({
  80. flodMap: this.data.flodMap,
  81. list: this.data.list
  82. })
  83. }
  84. }).catch( _ => { console.log(_)})
  85. },
  86. validTimes(item) {
  87. if (item.isSn) {
  88. if (item.couponStartTime && item.couponEndTime) {
  89. return parseTime(item.couponStartTime, "{y}.{m}.{d}") + " - " + parseTime(item.couponEndTime, "{y}.{m}.{d}")
  90. } else {
  91. return ""
  92. }
  93. }
  94. const timeCondition = item.timeCondition || {}
  95. if (timeCondition.type == "DATE_TYPE_FIXED_TERM") {
  96. return "领券当日起" + timeCondition.fixedTerm + "天内有效"
  97. }
  98. if (timeCondition.type == "DATE_TYPE_FIXED_TIME_RANGE") {
  99. return parseTime(timeCondition.beginTimestamp, "{y}.{m}.{d}") + " - " + parseTime(timeCondition.endTimestamp, "{y}.{m}.{d}")
  100. }
  101. return ""
  102. },
  103. toFixStorePage(e) {
  104. const couponId = this.data.list[e.currentTarget.dataset.index].couponId;
  105. wx.navigateTo({
  106. url: '/pages/welfareMall/couponFitStore/index?couponId=' + couponId,
  107. })
  108. },
  109. toFixFoodPage(e) {
  110. const couponId = this.data.list[e.currentTarget.dataset.index].couponId;
  111. wx.navigateTo({
  112. url: '/pages/welfareMall/couponFitFood/index?couponId=' + couponId,
  113. })
  114. }
  115. }
  116. })