|
...
|
...
|
@@ -128,12 +128,18 @@ Page({ |
|
|
|
let arr = []
|
|
|
|
let currentCoupon = '0'; //没选券 为0 可叠加券1 不可叠加券2
|
|
|
|
let inputValue = parseFloat(this.data.inputValue)
|
|
|
|
let val = 0;
|
|
|
|
let val = 0; //勾选的券 优惠金额的和
|
|
|
|
let descStr = 0; //勾选的券 每满金额的和
|
|
|
|
for (let i = 0, lenI = list.length; i < lenI; ++i) {
|
|
|
|
list[i].checked = false;
|
|
|
|
for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
|
|
|
|
if (list[i].activity_id === values[j]) {
|
|
|
|
val += parseFloat(list[i].price)
|
|
|
|
if (!list[i].desc || list[i].desc == 0) {
|
|
|
|
descStr += parseFloat(list[i].price)
|
|
|
|
} else {
|
|
|
|
descStr += parseFloat(list[i].desc)
|
|
|
|
}
|
|
|
|
arr.push({
|
|
|
|
...list[i]
|
|
|
|
})
|
|
...
|
...
|
@@ -160,25 +166,21 @@ Page({ |
|
|
|
}
|
|
|
|
//选的不可叠加券 其他所有的可叠加券都不可选
|
|
|
|
if (currentCoupon == '2') {
|
|
|
|
list.forEach(item => {
|
|
|
|
if (item.accumulationShow == "1" || !item.checked) {
|
|
|
|
item.showCpupon = '0';
|
|
|
|
list.map((item) => {
|
|
|
|
if (item.checked) {
|
|
|
|
item.showCpupon = '1'
|
|
|
|
} else {
|
|
|
|
item.showCpupon = '1';
|
|
|
|
item.showCpupon = '0'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
//选的可叠加券 其他所有的不可叠加券都不可选
|
|
|
|
if (currentCoupon == '1') {
|
|
|
|
list.forEach(item => {
|
|
|
|
let kyNum = Math.floor(parseFloat(this.data.inputValue)/parseFloat(item.desc))
|
|
|
|
let count = list.reduce((accumulator, obj) => {
|
|
|
|
return item.aid === obj.aid&&obj.checked ? accumulator + 1 : accumulator;
|
|
|
|
}, 0);
|
|
|
|
if (item.accumulationShow == "0" || ((remaining - item.price < 0) && !item.checked)||(!item.checked&&count>=kyNum)) {
|
|
|
|
item.showCpupon = '0';
|
|
|
|
} else if (item.accumulationShow == "1" && item.canCheck == '1') {
|
|
|
|
if (item.checked || (item.accumulationShow == "1" && (inputValue - descStr) >= parseFloat(item.desc) && parseFloat(item.price) <= (inputValue - val))) {
|
|
|
|
item.showCpupon = '1';
|
|
|
|
} else {
|
|
|
|
item.showCpupon = '0';
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
...
|
...
|
@@ -199,8 +201,14 @@ Page({ |
|
|
|
inputValue: e.detail.value,
|
|
|
|
couponArr: list
|
|
|
|
})
|
|
|
|
|
|
|
|
this.colationData()
|
|
|
|
if (e.detail.value == '') {
|
|
|
|
this.setData({
|
|
|
|
discountPrice: '',
|
|
|
|
actualPrice: '',
|
|
|
|
})
|
|
|
|
}else{
|
|
|
|
this.colationData()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 点确认选择
|
|
|
|
checkCertificate() {
|
|
...
|
...
|
@@ -398,13 +406,28 @@ Page({ |
|
|
|
const isValid = validCoupons.some(validCoupon => validCoupon.activity_id == item.activity_id);
|
|
|
|
item.canCheck = isValid ? '1' : '0'; // 如果在 validCoupons 中,设置 canCheck 为 1,否则为 0
|
|
|
|
});
|
|
|
|
// 输入的金额 > 可选券的总优惠金额 勾选所有可选券(未完成)
|
|
|
|
// let yxDesc=0
|
|
|
|
// let yxArr=[]
|
|
|
|
// let yxSum = validCoupons.reduce((pre,cur)=>{
|
|
|
|
// if (cur.accumulationShow==1 && cur.canCheck == '1') {
|
|
|
|
// if (cur.desc==0||!cur.desc) {
|
|
|
|
// yxDesc+=parseFloat(cur.price)
|
|
|
|
// }else{
|
|
|
|
// yxDesc+=parseFloat(cur.desc)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// pre+=parseFloat(cur.price)
|
|
|
|
// yxArr.push(cur)
|
|
|
|
// }
|
|
|
|
// return pre;
|
|
|
|
// },0)
|
|
|
|
// console.log('yxSum',yxSum,'yxDesc',yxDesc,'yxArr',yxArr);
|
|
|
|
console.log('可以勾选的券 && 满足付款条件的券', validCoupons);
|
|
|
|
let list1 = []; // 可叠加的优惠券组合
|
|
|
|
let list2 = []; // 最优惠的不可叠加的优惠券
|
|
|
|
let finalList = []; //最终用的优惠券组合
|
|
|
|
// 计算可叠加的组合
|
|
|
|
let maxDiscount = 0;
|
|
|
|
let numIndex=0
|
|
|
|
let closestSum = -Infinity; // 最接近或等于输入值的和
|
|
|
|
function backtrack(startIndex, currentCombination, currentSum,couponCount) {
|
|
|
|
// 如果当前和等于输入值,直接返回
|
...
|
...
|
|