index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. if (typeof v.couponState == "undefined") {
  46. if (v.payStatus == 4) {
  47. v.stateStr = "已取消"
  48. } else {
  49. v.stateStr = "未支付"
  50. }
  51. } else if (v.couponState == 1) {
  52. v.stateStr = "已使用"
  53. } else if (v.couponState == 2) {
  54. v.stateStr = "已过期"
  55. } else if (v.couponState == 3) {
  56. v.stateStr = "已取消"
  57. } else if (v.couponState == 4) {
  58. v.stateStr = "已停用"
  59. } else if (v.couponState == 5) {
  60. v.stateStr = "转增中"
  61. } else {
  62. v.stateStr = "不可用"
  63. }
  64. })
  65. this.setData({
  66. list: this.data.couponList
  67. })
  68. },
  69. exFoldPanel(e) {
  70. const index = e.currentTarget.dataset.index
  71. if (this.data.flodMap[index]) {
  72. this.data.flodMap[index] = false
  73. this.setData({
  74. flodMap: this.data.flodMap
  75. })
  76. } else {
  77. this.loadCouponData(index)
  78. }
  79. },
  80. loadCouponData(index) {
  81. if (this.data.list[index].isLoadCouponDetail) {
  82. this.data.flodMap[index] = true
  83. this.setData({
  84. flodMap: this.data.flodMap
  85. })
  86. return
  87. }
  88. activity.getCouponDetailData({ couponId: this.data.list[index].couponId }).then( res => {
  89. if (res.code == 200) {
  90. const data = res.data || {}
  91. Object.assign(this.data.list[index], {
  92. description: data.description || '',
  93. bindShopType: data.bindShopType || 1,
  94. bindGoodsType: data.bindGoodsType || 1,
  95. isLoadCouponDetail: true
  96. })
  97. this.data.flodMap[index] = true
  98. this.setData({
  99. flodMap: this.data.flodMap,
  100. list: this.data.list
  101. })
  102. }
  103. }).catch( _ => { console.log(_)})
  104. },
  105. validTimes(item) {
  106. if (item.isSn) {
  107. if (item.couponStartTime && item.couponEndTime) {
  108. return parseTime(item.couponStartTime, "{y}.{m}.{d}") + " - " + parseTime(item.couponEndTime, "{y}.{m}.{d}")
  109. } else {
  110. return ""
  111. }
  112. }
  113. const timeCondition = item.timeCondition || {}
  114. if (timeCondition.type == "DATE_TYPE_FIXED_TERM") {
  115. return "领券当日起" + timeCondition.fixedTerm + "天内有效"
  116. }
  117. if (timeCondition.type == "DATE_TYPE_FIXED_TIME_RANGE") {
  118. return parseTime(timeCondition.beginTimestamp, "{y}.{m}.{d}") + " - " + parseTime(timeCondition.endTimestamp, "{y}.{m}.{d}")
  119. }
  120. return ""
  121. },
  122. toFixStorePage(e) {
  123. const couponId = this.data.list[e.currentTarget.dataset.index].couponId;
  124. wx.navigateTo({
  125. url: '/pages/welfareMall/couponFitStore/index?couponId=' + couponId,
  126. })
  127. },
  128. toFixFoodPage(e) {
  129. const couponId = this.data.list[e.currentTarget.dataset.index].couponId;
  130. const title = this.data.list[e.currentTarget.dataset.index].title;
  131. wx.navigateTo({
  132. url: '/pages/welfareMall/couponFitFood/index?couponId=' + couponId + "&couponName=" + title,
  133. })
  134. }
  135. }
  136. })