index.js 5.8 KB

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