// components/couponWrap/index.js import { parseTime } from '../../utils/util'; import activity from '../../api/activity' Component({ externalClasses: ['class', 'coupon-circule-ex-class', 'coupon-item-ex-class'], /** * 组件的属性列表 */ properties: { couponList: { type: Array, default: [] } }, /** * 组件的初始数据 */ data: { flodMap: { } }, lifetimes: { attached: function() { // this.prepareData() } }, observers: { 'couponList'(dataA) { this.prepareData() }, }, /** * 组件的方法列表 */ methods: { prepareData() { this.data.couponList.forEach(v => { v.validTimesStr = this.validTimes(v) if (typeof (v.type || v.couponType) == "string") { v.type = { value: (v.type || v.couponType) } } else { v.type = v.type || v.couponType } v.title = v.title || v.couponName || v.couponTitle }) this.setData({ list: this.data.couponList }) }, exFoldPanel(e) { const index = e.currentTarget.dataset.index if (this.data.flodMap[index]) { this.data.flodMap[index] = false this.setData({ flodMap: this.data.flodMap }) } else { this.loadCouponData(index) } }, loadCouponData(index) { if (this.data.list[index].isLoadCouponDetail) { this.data.flodMap[index] = true this.setData({ flodMap: this.data.flodMap }) return } activity.getCouponDetailData({ couponId: this.data.list[index].couponId }).then( res => { if (res.code == 200) { const data = res.data || {} Object.assign(this.data.list[index], { description: data.description || '', bindShopType: data.bindShopType || 1, bindGoodsType: data.bindGoodsType || 1, isLoadCouponDetail: true }) this.data.flodMap[index] = true this.setData({ flodMap: this.data.flodMap, list: this.data.list }) } }).catch( _ => { console.log(_)}) }, validTimes(item) { if (item.isSn) { if (item.couponStartTime && item.couponEndTime) { return parseTime(item.couponStartTime, "{y}.{m}.{d}") + " - " + parseTime(item.couponEndTime, "{y}.{m}.{d}") } else { return "" } } const timeCondition = item.timeCondition || {} if (timeCondition.type == "DATE_TYPE_FIXED_TERM") { return "领券当日起" + timeCondition.fixedTerm + "天内有效" } if (timeCondition.type == "DATE_TYPE_FIXED_TIME_RANGE") { return parseTime(timeCondition.beginTimestamp, "{y}.{m}.{d}") + " - " + parseTime(timeCondition.endTimestamp, "{y}.{m}.{d}") } return "" }, toFixStorePage(e) { const couponId = this.data.list[e.currentTarget.dataset.index].couponId; wx.navigateTo({ url: '/pages/welfareMall/couponFitStore/index?couponId=' + couponId, }) }, toFixFoodPage(e) { const couponId = this.data.list[e.currentTarget.dataset.index].couponId; wx.navigateTo({ url: '/pages/welfareMall/couponFitFood/index?couponId=' + couponId, }) } } })