index.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // components/couponWrap/index.js
  2. import { parseTime } from '../../utils/util';
  3. import activity from '../../api/activity'
  4. import {getColor} from '../../utils/user'
  5. Component({
  6. externalClasses: ['class', 'coupon-circule-ex-class', 'coupon-item-ex-class'],
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {
  11. couponList: {
  12. type: Array,
  13. default: []
  14. }
  15. },
  16. /**
  17. * 组件的初始数据
  18. */
  19. data: {
  20. flodMap: {
  21. }
  22. },
  23. lifetimes: {
  24. attached: function() {
  25. // this.prepareData()
  26. }
  27. },
  28. observers: {
  29. 'couponList'(dataA) {
  30. this.prepareData()
  31. },
  32. },
  33. /**
  34. * 组件的方法列表
  35. */
  36. methods: {
  37. async prepareData() {
  38. if (!this.data.couponList || this.data.couponList.length == 0) {
  39. this.data.list = [];
  40. this.data.flodMap = {};
  41. }
  42. this.data.couponList.forEach((v, i) => {
  43. v.validTimesStr = this.validTimes(v)
  44. if (typeof (v.type || v.couponType) == "string") {
  45. v.type = { value: (v.type || v.couponType) }
  46. } else {
  47. v.type = v.type || v.couponType
  48. }
  49. v.title = v.title || v.couponName || v.couponTitle
  50. if (typeof v.couponState == "undefined") {
  51. if (v.payStatus == 4) {
  52. v.stateStr = "已取消"
  53. } else {
  54. v.stateStr = "未支付"
  55. }
  56. } else if (v.couponState == 1) {
  57. v.stateStr = "已使用"
  58. } else if (v.couponState == 2) {
  59. v.stateStr = "已过期"
  60. } else if (v.couponState == 3) {
  61. v.stateStr = "已取消"
  62. } else if (v.couponState == 4) {
  63. v.stateStr = "已停用"
  64. } else if (v.couponState == 5) {
  65. v.stateStr = "转增中"
  66. } else {
  67. v.stateStr = "不可用"
  68. }
  69. if (this.data.list) {
  70. let node = this.data.list[i];
  71. if (node) {
  72. v.description = node.description || '';
  73. v.bindShopType = node.bindShopType || 1;
  74. v.bindGoodsType = node.bindGoodsType || 1;
  75. v.isLoadCouponDetail = node.isLoadCouponDetail || false;
  76. }
  77. }
  78. })
  79. this.setData({
  80. list: this.data.couponList
  81. })
  82. let info = await getColor();
  83. this.setData({
  84. config:info.config
  85. })
  86. },
  87. exFoldPanel(e) {
  88. const index = e.currentTarget.dataset.index
  89. if (this.data.flodMap[index]) {
  90. this.data.flodMap[index] = false
  91. this.setData({
  92. flodMap: this.data.flodMap
  93. })
  94. } else {
  95. this.loadCouponData(index)
  96. }
  97. },
  98. loadCouponData(index) {
  99. if (this.data.list[index].isLoadCouponDetail) {
  100. this.data.flodMap[index] = true
  101. this.setData({
  102. flodMap: this.data.flodMap
  103. })
  104. return
  105. }
  106. activity.getCouponDetailData({ couponId: this.data.list[index].couponId }).then( res => {
  107. if (res.code == 200) {
  108. const data = res.data || {}
  109. Object.assign(this.data.list[index], {
  110. description: data.description || '',
  111. bindShopType: data.bindShopType || 1,
  112. bindGoodsType: data.bindGoodsType || 1,
  113. isLoadCouponDetail: true
  114. })
  115. this.data.flodMap[index] = true
  116. this.setData({
  117. flodMap: this.data.flodMap,
  118. list: this.data.list
  119. })
  120. }
  121. }).catch( _ => { console.log(_)})
  122. },
  123. validTimes(item) {
  124. if (item.isSn) {
  125. if (item.couponStartTime && item.couponEndTime) {
  126. return parseTime(item.couponStartTime, "{y}.{m}.{d}") + " - " + parseTime(item.couponEndTime, "{y}.{m}.{d}")
  127. } else {
  128. return ""
  129. }
  130. }
  131. const timeCondition = item.timeCondition || {}
  132. if (timeCondition.type == "DATE_TYPE_FIXED_TERM") {
  133. return "领券当日起" + timeCondition.fixedTerm + "天内有效"
  134. }
  135. if (timeCondition.type == "DATE_TYPE_FIXED_TIME_RANGE") {
  136. return parseTime(timeCondition.beginTimestamp, "{y}.{m}.{d}") + " - " + parseTime(timeCondition.endTimestamp, "{y}.{m}.{d}")
  137. }
  138. return ""
  139. },
  140. toFixStorePage(e) {
  141. const couponId = this.data.list[e.currentTarget.dataset.index].couponId;
  142. wx.navigateTo({
  143. url: '/pages/welfareMall/couponFitStore/index?couponId=' + couponId,
  144. })
  145. },
  146. toFixFoodPage(e) {
  147. const couponId = this.data.list[e.currentTarget.dataset.index].couponId;
  148. const title = this.data.list[e.currentTarget.dataset.index].title;
  149. wx.navigateTo({
  150. url: '/pages/welfareMall/couponFitFood/index?couponId=' + couponId + "&couponName=" + title + "&bindGoodsType=" + 1,
  151. })
  152. },
  153. toFixFoodPageNo(e) {
  154. const couponId = this.data.list[e.currentTarget.dataset.index].couponId;
  155. const title = this.data.list[e.currentTarget.dataset.index].title;
  156. wx.navigateTo({
  157. url: '/pages/welfareMall/couponFitFood/index?couponId=' + couponId + "&couponName=" + title + "&bindGoodsType=" + 3,
  158. })
  159. }
  160. }
  161. })