buyFreeCoupon.js
5.2 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// pack-activity/pack/buyFreeCoupon.js
import util from '../../utils/util';
import App from '../../utils/api';
Page({
/**
* 页面的初始数据
*/
data: {
options: {},
available: '1', //输入金额够优惠券最低消费1 不够0
couponArr: [], //所有券列表
dataStr: Date.now() * 1 / 1000,
},
couponModal: '',
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.couponModal = this.selectComponent("#couponModal");
this.couponModal.showModal()
this.setData({
...options
})
if (options.sid) {
this.getSellerDetail(options.sid)
}
},
// 打开优惠券弹框
showCouponModal() {
this.couponModal.showModal()
},
// 关闭优惠券弹框
closeCouponModal() {
this.couponModal.closeModal()
},
// 获取店铺名称
getSellerDetail(sid) {
App.Customer.GetSellerDetail({
sid
}).then(res => {
let data = res.data;
this.setData({
seller: {
seller_image: data.seller_image,
sellername: data.sellername
}
})
this.getCoupon()
})
},
// 点确认选择
checkCertificate() {
console.log('1111111111');
this.closeCouponModal()
},
// 获取所有优惠券列表
getCoupon() {
App.Activity.ActivityListByOpenid().then(res => {
if (res.ret == 200 && res.data && res.data.length > 0) {
let list = res.data.filter(item => {
return this.data.dataStr < (item.etime * 1) && item.is_open == '1'
})
list.forEach(detail => {
detail.stringifyUse = detail.use ? JSON.stringify(detail.use) : '';
detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : '';
detail.arule = detail.arule ? util.determine(detail.arule) : '';
if (detail.exp_date && detail.exp_date.week_data) {
let noon = this.hasConsecutiveSelect(detail.exp_date.week_data, '1').rArr.join('、')
let nig = this.hasConsecutiveSelect(detail.exp_date.week_data, '2').rArr.join('、')
if (noon) noon = '午餐:' + noon
if (nig) nig = '晚餐:' + nig
detail.noonText = noon;
detail.nigText = nig;
}
detail.checked = false;
detail.endDateStr = util.unixtoTime(detail.stime, 'YYYY-MM-DD') + '至' + util.unixtoTime(detail.etime, 'YYYY-MM-DD')
})
console.log(list);
let couponArr = list
this.setData({
couponArr
})
}
})
},
checkboxChange(e) {
console.log('checkbox发生change事件,携带value值为:', e.detail.value)
},
// 输入金额
bindKeyInput(e) {
this.setData({
inputValue: e.detail.value
})
},
// 处理优惠券不可用日期数据
hasConsecutiveSelect(arr, type) {
let firstTitle = null;
let lastTitle = null;
let rArr = []
let num = 0
for (let i = 0; i < arr.length; i++) {
let str = type == '1' ? arr[i].selectNoon : arr[i].selectNig
if (str) {
rArr.push(arr[i].title)
num++
if (num == 1) {
firstTitle = arr[i].title
}
if (num >= 5) {
lastTitle = arr[i].title
}
if (num >= 5 && i >= (arr.length - 1)) {
let fi = rArr.findIndex((item) => {
return item == firstTitle
})
rArr.splice(fi, num, firstTitle + '至' + lastTitle)
num = 0
}
} else {
if (num < 5) {
num = 0
firstTitle = null;
lastTitle = null;
} else {
let fi = rArr.findIndex((item) => {
return item == firstTitle
})
rArr.splice(fi, num, firstTitle + '至' + lastTitle)
num = 0
}
}
}
return {
rArr,
lastTitle,
firstTitle
};
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})