|
@@ -128,12 +128,18 @@ Page({ |
|
@@ -128,12 +128,18 @@ Page({ |
|
128
|
let arr = []
|
128
|
let arr = []
|
|
129
|
let currentCoupon = '0'; //没选券 为0 可叠加券1 不可叠加券2
|
129
|
let currentCoupon = '0'; //没选券 为0 可叠加券1 不可叠加券2
|
|
130
|
let inputValue = parseFloat(this.data.inputValue)
|
130
|
let inputValue = parseFloat(this.data.inputValue)
|
|
131
|
- let val = 0;
|
131
|
+ let val = 0; //勾选的券 优惠金额的和
|
|
|
|
132
|
+ let descStr = 0; //勾选的券 每满金额的和
|
|
132
|
for (let i = 0, lenI = list.length; i < lenI; ++i) {
|
133
|
for (let i = 0, lenI = list.length; i < lenI; ++i) {
|
|
133
|
list[i].checked = false;
|
134
|
list[i].checked = false;
|
|
134
|
for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
|
135
|
for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
|
|
135
|
if (list[i].activity_id === values[j]) {
|
136
|
if (list[i].activity_id === values[j]) {
|
|
136
|
val += parseFloat(list[i].price)
|
137
|
val += parseFloat(list[i].price)
|
|
|
|
138
|
+ if (!list[i].desc || list[i].desc == 0) {
|
|
|
|
139
|
+ descStr += parseFloat(list[i].price)
|
|
|
|
140
|
+ } else {
|
|
|
|
141
|
+ descStr += parseFloat(list[i].desc)
|
|
|
|
142
|
+ }
|
|
137
|
arr.push({
|
143
|
arr.push({
|
|
138
|
...list[i]
|
144
|
...list[i]
|
|
139
|
})
|
145
|
})
|
|
@@ -160,25 +166,21 @@ Page({ |
|
@@ -160,25 +166,21 @@ Page({ |
|
160
|
}
|
166
|
}
|
|
161
|
//选的不可叠加券 其他所有的可叠加券都不可选
|
167
|
//选的不可叠加券 其他所有的可叠加券都不可选
|
|
162
|
if (currentCoupon == '2') {
|
168
|
if (currentCoupon == '2') {
|
|
163
|
- list.forEach(item => {
|
|
|
|
164
|
- if (item.accumulationShow == "1" || !item.checked) {
|
|
|
|
165
|
- item.showCpupon = '0';
|
169
|
+ list.map((item) => {
|
|
|
|
170
|
+ if (item.checked) {
|
|
|
|
171
|
+ item.showCpupon = '1'
|
|
166
|
} else {
|
172
|
} else {
|
|
167
|
- item.showCpupon = '1';
|
173
|
+ item.showCpupon = '0'
|
|
168
|
}
|
174
|
}
|
|
169
|
})
|
175
|
})
|
|
170
|
}
|
176
|
}
|
|
171
|
//选的可叠加券 其他所有的不可叠加券都不可选
|
177
|
//选的可叠加券 其他所有的不可叠加券都不可选
|
|
172
|
if (currentCoupon == '1') {
|
178
|
if (currentCoupon == '1') {
|
|
173
|
list.forEach(item => {
|
179
|
list.forEach(item => {
|
|
174
|
- let kyNum = Math.floor(parseFloat(this.data.inputValue)/parseFloat(item.desc))
|
|
|
|
175
|
- let count = list.reduce((accumulator, obj) => {
|
|
|
|
176
|
- return item.aid === obj.aid&&obj.checked ? accumulator + 1 : accumulator;
|
|
|
|
177
|
- }, 0);
|
|
|
|
178
|
- if (item.accumulationShow == "0" || ((remaining - item.price < 0) && !item.checked)||(!item.checked&&count>=kyNum)) {
|
|
|
|
179
|
- item.showCpupon = '0';
|
|
|
|
180
|
- } else if (item.accumulationShow == "1" && item.canCheck == '1') {
|
180
|
+ if (item.checked || (item.accumulationShow == "1" && (inputValue - descStr) >= parseFloat(item.desc) && parseFloat(item.price) <= (inputValue - val))) {
|
|
181
|
item.showCpupon = '1';
|
181
|
item.showCpupon = '1';
|
|
|
|
182
|
+ } else {
|
|
|
|
183
|
+ item.showCpupon = '0';
|
|
182
|
}
|
184
|
}
|
|
183
|
})
|
185
|
})
|
|
184
|
}
|
186
|
}
|
|
@@ -199,8 +201,14 @@ Page({ |
|
@@ -199,8 +201,14 @@ Page({ |
|
199
|
inputValue: e.detail.value,
|
201
|
inputValue: e.detail.value,
|
|
200
|
couponArr: list
|
202
|
couponArr: list
|
|
201
|
})
|
203
|
})
|
|
202
|
-
|
|
|
|
203
|
- this.colationData()
|
204
|
+ if (e.detail.value == '') {
|
|
|
|
205
|
+ this.setData({
|
|
|
|
206
|
+ discountPrice: '',
|
|
|
|
207
|
+ actualPrice: '',
|
|
|
|
208
|
+ })
|
|
|
|
209
|
+ }else{
|
|
|
|
210
|
+ this.colationData()
|
|
|
|
211
|
+ }
|
|
204
|
},
|
212
|
},
|
|
205
|
// 点确认选择
|
213
|
// 点确认选择
|
|
206
|
checkCertificate() {
|
214
|
checkCertificate() {
|
|
@@ -398,13 +406,28 @@ Page({ |
|
@@ -398,13 +406,28 @@ Page({ |
|
398
|
const isValid = validCoupons.some(validCoupon => validCoupon.activity_id == item.activity_id);
|
406
|
const isValid = validCoupons.some(validCoupon => validCoupon.activity_id == item.activity_id);
|
|
399
|
item.canCheck = isValid ? '1' : '0'; // 如果在 validCoupons 中,设置 canCheck 为 1,否则为 0
|
407
|
item.canCheck = isValid ? '1' : '0'; // 如果在 validCoupons 中,设置 canCheck 为 1,否则为 0
|
|
400
|
});
|
408
|
});
|
|
|
|
409
|
+ // 输入的金额 > 可选券的总优惠金额 勾选所有可选券(未完成)
|
|
|
|
410
|
+ // let yxDesc=0
|
|
|
|
411
|
+ // let yxArr=[]
|
|
|
|
412
|
+ // let yxSum = validCoupons.reduce((pre,cur)=>{
|
|
|
|
413
|
+ // if (cur.accumulationShow==1 && cur.canCheck == '1') {
|
|
|
|
414
|
+ // if (cur.desc==0||!cur.desc) {
|
|
|
|
415
|
+ // yxDesc+=parseFloat(cur.price)
|
|
|
|
416
|
+ // }else{
|
|
|
|
417
|
+ // yxDesc+=parseFloat(cur.desc)
|
|
|
|
418
|
+ // }
|
|
|
|
419
|
+
|
|
|
|
420
|
+ // pre+=parseFloat(cur.price)
|
|
|
|
421
|
+ // yxArr.push(cur)
|
|
|
|
422
|
+ // }
|
|
|
|
423
|
+ // return pre;
|
|
|
|
424
|
+ // },0)
|
|
|
|
425
|
+ // console.log('yxSum',yxSum,'yxDesc',yxDesc,'yxArr',yxArr);
|
|
401
|
console.log('可以勾选的券 && 满足付款条件的券', validCoupons);
|
426
|
console.log('可以勾选的券 && 满足付款条件的券', validCoupons);
|
|
402
|
let list1 = []; // 可叠加的优惠券组合
|
427
|
let list1 = []; // 可叠加的优惠券组合
|
|
403
|
let list2 = []; // 最优惠的不可叠加的优惠券
|
428
|
let list2 = []; // 最优惠的不可叠加的优惠券
|
|
404
|
let finalList = []; //最终用的优惠券组合
|
429
|
let finalList = []; //最终用的优惠券组合
|
|
405
|
// 计算可叠加的组合
|
430
|
// 计算可叠加的组合
|
|
406
|
- let maxDiscount = 0;
|
|
|
|
407
|
- let numIndex=0
|
|
|
|
408
|
let closestSum = -Infinity; // 最接近或等于输入值的和
|
431
|
let closestSum = -Infinity; // 最接近或等于输入值的和
|
|
409
|
function backtrack(startIndex, currentCombination, currentSum,couponCount) {
|
432
|
function backtrack(startIndex, currentCombination, currentSum,couponCount) {
|
|
410
|
// 如果当前和等于输入值,直接返回
|
433
|
// 如果当前和等于输入值,直接返回
|