index.js
2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { IMG_URL } from '~/config';
Component({
/**
* 组件的属性列表
*/
properties: {
show: Boolean,
goodsId: {
type: Number,
observer: function (val) {
if (val) {
this.getGoodscouponList(val);
}
},
},
couponsId:Number
},
/**
* 组件的初始数据
*/
data: {
IMG_URL: IMG_URL,
currentIndex: 0,
current: null
},
/**
* 组件的方法列表
*/
methods: {
selectCoupons(e) {
const { index } = e.currentTarget.dataset
this.setData({
currentIndex: index
})
},
cancel() {
this.setData({
show: false
})
},
comfirm() {
const { couponData, currentIndex } = this.data
this.triggerEvent('getCoupons', couponData[currentIndex])
this.cancel()
},
async getGoodscouponList(id) {
const authStatus = await wx.p.router.intercept(false)
if (authStatus) return
let currentIndex = 0
wx.p.api.shopmallApi
.getEquitycouponList({
id,
couponType: 8
})
.then(({ code, data, message }) => {
let list =
data &&
data.map(item => {
item.denomination = wx.p.format.decimal(item.denomination / 100, 2)
if (item.effectiveEndTime || item.effectiveStartTime) {
item.effectiveEndTime = new Date(item.effectiveEndTime).format('yyyy.MM.dd')
item.effectiveStartTime = new Date(item.effectiveStartTime).format('yyyy.MM.dd')
}
return item
})
if (list.length) {
if(this.data.couponsId){
let flag = false
list.forEach((el,index)=>{
if(el.couponId==this.data.couponsId){
flag = true
this.triggerEvent('getCoupons', el)
currentIndex = index
}
})
if(!flag){
this.triggerEvent('getCoupons', list[0])
}
}else{
this.triggerEvent('getCoupons', list[0])
}
}
this.setData({
couponData: list,
currentIndex
})
})
},
}
})