|
...
|
...
|
@@ -736,49 +736,127 @@ Page({ |
|
|
|
return (this.data.dataStr < (item.useEtime * 1) || item.aexpiration.valid_forever == '1');
|
|
|
|
})
|
|
|
|
list.sort((a, b) => {
|
|
|
|
return (a.etime * 1) - (b.etime * 1)
|
|
|
|
if (a.aexpiration.valid_forever == '1' && b.aexpiration.valid_forever != '1') return 1;
|
|
|
|
if (a.aexpiration.valid_forever != '1' && b.aexpiration.valid_forever == '1') return -1;
|
|
|
|
return (a.useEtime * 1) - (b.useEtime * 1)
|
|
|
|
})
|
|
|
|
let couponArr = list
|
|
|
|
// 相同aid的券合并成一张,用加减号选择张数
|
|
|
|
let couponGroup = {}
|
|
|
|
let couponList = []
|
|
|
|
couponArr.forEach(item => {
|
|
|
|
let key = item.aid ? item.aid : item.activity_id
|
|
|
|
if (couponGroup[key]) {
|
|
|
|
couponGroup[key].num = (couponGroup[key].num * 1) + 1
|
|
|
|
couponGroup[key].activityIds.push(item.activity_id)
|
|
|
|
} else {
|
|
|
|
item.num = 1
|
|
|
|
item.checkedNum = 0
|
|
|
|
item.activityIds = [item.activity_id]
|
|
|
|
couponGroup[key] = item
|
|
|
|
couponList.push(item)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
couponArr = couponList
|
|
|
|
// 单次使用数量限制,0表示不限制,默认0;合并完成后统一计算
|
|
|
|
couponArr.forEach(item => {
|
|
|
|
let useLimit = item.single_use_limit ? (item.single_use_limit * 1) : 0
|
|
|
|
item.maxNum = (useLimit > 0 && useLimit < item.num) ? useLimit : item.num
|
|
|
|
})
|
|
|
|
console.log('couponArr----',couponArr);
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
couponArr
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 勾选券
|
|
|
|
checkboxChange(e) {
|
|
|
|
console.log('checkbox发生change事件,携带value值为:', e.detail.value)
|
|
|
|
// 加减号选择券的张数
|
|
|
|
changeCouponNum(e) {
|
|
|
|
let type = e.currentTarget.dataset.type;
|
|
|
|
let aid = e.currentTarget.dataset.aid;
|
|
|
|
const list = this.data.couponArr
|
|
|
|
let item = list.find(i => i.aid == aid)
|
|
|
|
if (!item) return
|
|
|
|
if (type == 'plus') {
|
|
|
|
if (item.canAdd != '1') return
|
|
|
|
item.checkedNum = (item.checkedNum * 1) + 1
|
|
|
|
}
|
|
|
|
if (type == 'minus') {
|
|
|
|
if (item.checkedNum <= 0) return
|
|
|
|
item.checkedNum = (item.checkedNum * 1) - 1
|
|
|
|
}
|
|
|
|
this.refreshCouponState()
|
|
|
|
},
|
|
|
|
// 加减号中间输入框:只允许正整数或0,且不能超过当前可用张数
|
|
|
|
numInputChange(e) {
|
|
|
|
let aid = e.currentTarget.dataset.aid;
|
|
|
|
let val = (e.detail.value || '').replace(/[^\d]/g, ''); // 只保留数字
|
|
|
|
const list = this.data.couponArr
|
|
|
|
let item = list.find(i => i.aid == aid)
|
|
|
|
if (!item) return
|
|
|
|
let maxSelect = this.getMaxSelectNum(item)
|
|
|
|
let num = val === '' ? 0 : parseInt(val, 10)
|
|
|
|
if (isNaN(num)) num = 0
|
|
|
|
if (num > maxSelect) num = maxSelect
|
|
|
|
item.checkedNum = num
|
|
|
|
this.refreshCouponState()
|
|
|
|
},
|
|
|
|
// 计算某张券当前最多可以选到的张数
|
|
|
|
getMaxSelectNum(item) {
|
|
|
|
const list = this.data.couponArr
|
|
|
|
let inputValue = parseFloat(this.data.inputValue)
|
|
|
|
let descStr = 0
|
|
|
|
let val = 0
|
|
|
|
list.forEach(i => {
|
|
|
|
if (i.checkedNum > 0 && i.aid != item.aid) {
|
|
|
|
let d = parseFloat(i.desc) || 0
|
|
|
|
if (d > 0) descStr += d * i.checkedNum
|
|
|
|
val += parseFloat(i.price) * i.checkedNum
|
|
|
|
}
|
|
|
|
})
|
|
|
|
let itemDesc = parseFloat(item.desc) || 0
|
|
|
|
let itemPrice = parseFloat(item.price)
|
|
|
|
let maxSelect = item.maxNum
|
|
|
|
if (item.accumulationShow != '1' && maxSelect > 1) maxSelect = 1
|
|
|
|
if (inputValue > 0) {
|
|
|
|
if (itemDesc > 0) {
|
|
|
|
let byDesc = Math.floor((inputValue - descStr) / itemDesc)
|
|
|
|
if (byDesc < maxSelect) maxSelect = byDesc
|
|
|
|
} else {
|
|
|
|
// 无门槛券:满减门槛之和小于输入金额时才能叠加
|
|
|
|
if (descStr >= inputValue) {
|
|
|
|
maxSelect = 0
|
|
|
|
} else {
|
|
|
|
let byPrice = Math.floor((inputValue - val) / itemPrice)
|
|
|
|
if (byPrice < maxSelect) maxSelect = byPrice
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (maxSelect < 0) maxSelect = 0
|
|
|
|
return maxSelect
|
|
|
|
},
|
|
|
|
// 根据选择的券张数刷新券的可选状态
|
|
|
|
refreshCouponState() {
|
|
|
|
const list = this.data.couponArr
|
|
|
|
const values = e.detail.value
|
|
|
|
let arr = []
|
|
|
|
let currentCoupon = '0'; //没选券 为0 可叠加券1 不可叠加券2
|
|
|
|
let inputValue = parseFloat(this.data.inputValue)
|
|
|
|
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]
|
|
|
|
})
|
|
|
|
list[i].checked = true
|
|
|
|
if (list[i].accumulationShow == '1') {
|
|
|
|
currentCoupon = '1'
|
|
|
|
break
|
|
|
|
} else {
|
|
|
|
currentCoupon = '2'
|
|
|
|
break
|
|
|
|
}
|
|
|
|
list.forEach(item => {
|
|
|
|
if (item.checkedNum > 0) {
|
|
|
|
val += parseFloat(item.price) * item.checkedNum
|
|
|
|
let itemDesc = parseFloat(item.desc) || 0
|
|
|
|
if (itemDesc > 0) {
|
|
|
|
descStr += itemDesc * item.checkedNum
|
|
|
|
}
|
|
|
|
if (item.accumulationShow != '1') {
|
|
|
|
currentCoupon = '2'
|
|
|
|
} else {
|
|
|
|
currentCoupon = '1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
let remaining = inputValue - val; //剩余金额
|
|
|
|
console.log('没选券为0可叠加券1不可叠加券2', currentCoupon, remaining);
|
|
|
|
//没选券 所有可选的打开
|
|
...
|
...
|
@@ -792,7 +870,7 @@ Page({ |
|
|
|
//选的不可叠加券 其他所有的可叠加券都不可选
|
|
|
|
if (currentCoupon == '2') {
|
|
|
|
list.map((item) => {
|
|
|
|
if (item.checked) {
|
|
|
|
if (item.checkedNum > 0) {
|
|
|
|
item.showCpupon = '1'
|
|
|
|
} else {
|
|
|
|
item.showCpupon = '0'
|
|
...
|
...
|
@@ -802,17 +880,79 @@ Page({ |
|
|
|
//选的可叠加券 其他所有的不可叠加券都不可选
|
|
|
|
if (currentCoupon == '1') {
|
|
|
|
list.forEach(item => {
|
|
|
|
if (item.checked || (item.accumulationShow == "1" && (inputValue - descStr) >= parseFloat(item.desc) && parseFloat(item.price) <= (inputValue - val))) {
|
|
|
|
if (item.checkedNum > 0 || (item.accumulationShow == "1" && parseFloat(item.price) <= (inputValue - val) && (((parseFloat(item.desc) || 0) > 0 && (inputValue - descStr) >= parseFloat(item.desc)) || ((parseFloat(item.desc) || 0) === 0 && descStr < inputValue)))) {
|
|
|
|
item.showCpupon = '1';
|
|
|
|
} else {
|
|
|
|
item.showCpupon = '0';
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
let finalList = list.filter(i=>{return i.checked})
|
|
|
|
this.setData({
|
|
|
|
couponArr: list,
|
|
|
|
finalList
|
|
|
|
let finalList = []
|
|
|
|
list.forEach(item => {
|
|
|
|
if (item.checkedNum > 0) {
|
|
|
|
for (let k = 0; k < item.checkedNum; k++) {
|
|
|
|
finalList.push({
|
|
|
|
...item,
|
|
|
|
activity_id: item.activityIds[k]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.updateCanAdd()
|
|
|
|
if (inputValue) {
|
|
|
|
let discountPrice = 0;
|
|
|
|
finalList.forEach(i => {
|
|
|
|
discountPrice += parseFloat(i.price)
|
|
|
|
})
|
|
|
|
discountPrice = discountPrice.toFixed(2)
|
|
|
|
console.log('优惠金额----', discountPrice);
|
|
|
|
let actualPrice = (inputValue - discountPrice - this.data.consumeDiscount).toFixed(2)
|
|
|
|
let myBalance = this.data.myBalance * 1;
|
|
|
|
let balancePay = (this.data.payType == '1' && actualPrice > myBalance) ? myBalance : actualPrice;
|
|
|
|
let soothPrice = this.data.payType == '1' ? (actualPrice - balancePay).toFixed(2) : actualPrice;
|
|
|
|
this.setData({
|
|
|
|
couponArr: list,
|
|
|
|
finalList,
|
|
|
|
discountPrice,
|
|
|
|
actualPrice,
|
|
|
|
balancePay,
|
|
|
|
soothPrice,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
|
|
couponArr: list,
|
|
|
|
finalList
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 计算每张券还能不能继续加:满减门槛之和不能超过输入金额
|
|
|
|
updateCanAdd() {
|
|
|
|
const list = this.data.couponArr
|
|
|
|
let inputValue = parseFloat(this.data.inputValue)
|
|
|
|
let descStr = 0
|
|
|
|
let val = 0
|
|
|
|
list.forEach(item => {
|
|
|
|
if (item.checkedNum > 0) {
|
|
|
|
let itemDesc = parseFloat(item.desc) || 0
|
|
|
|
let itemPrice = parseFloat(item.price)
|
|
|
|
if (itemDesc > 0) descStr += itemDesc * item.checkedNum
|
|
|
|
val += itemPrice * item.checkedNum
|
|
|
|
}
|
|
|
|
})
|
|
|
|
list.forEach(item => {
|
|
|
|
item.canAdd = '0'
|
|
|
|
// 不可叠加的券最多只能选一张
|
|
|
|
let maxSelect = item.accumulationShow == '1' ? item.maxNum : 1
|
|
|
|
if (item.showCpupon == '1' && item.checkedNum < maxSelect) {
|
|
|
|
let itemDesc = parseFloat(item.desc) || 0
|
|
|
|
let itemPrice = parseFloat(item.price)
|
|
|
|
if (itemDesc > 0) {
|
|
|
|
if (descStr + itemDesc <= inputValue) item.canAdd = '1'
|
|
|
|
} else {
|
|
|
|
// 无门槛券:满减门槛之和小于输入金额时才能叠加
|
|
|
|
if (descStr < inputValue && val + itemPrice <= inputValue) item.canAdd = '1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 输入金额
|
|
...
|
...
|
@@ -821,7 +961,7 @@ Page({ |
|
|
|
let list = this.data.couponArr;
|
|
|
|
// 所有的券重置
|
|
|
|
list.forEach(i => {
|
|
|
|
i.checked = false;
|
|
|
|
i.checkedNum = 0;
|
|
|
|
i.showCpupon = '0'
|
|
|
|
})
|
|
|
|
this.setData({
|
|
...
|
...
|
@@ -867,11 +1007,11 @@ Page({ |
|
|
|
if (!inputValue) return
|
|
|
|
let list = this.data.couponArr;
|
|
|
|
list = list.filter(i => {
|
|
|
|
return i.checked
|
|
|
|
return i.checkedNum > 0
|
|
|
|
})
|
|
|
|
let price = 0;
|
|
|
|
list.forEach(i => {
|
|
|
|
price += parseFloat(i.price)
|
|
|
|
price += parseFloat(i.price) * i.checkedNum
|
|
|
|
})
|
|
|
|
console.log('优惠金额----', price);
|
|
|
|
let val = parseFloat(this.data.inputValue);
|
|
...
|
...
|
@@ -1235,9 +1375,7 @@ Page({ |
|
|
|
let list1 = []; // 可叠加的优惠券组合
|
|
|
|
let list2 = []; // 最优惠的不可叠加的优惠券
|
|
|
|
let finalList = []; //最终用的优惠券组合
|
|
|
|
// 计算可叠加的组合
|
|
|
|
let remainingPrice = amount; // 剩余金额
|
|
|
|
let totalDiscount = 0; // 总优惠金额
|
|
|
|
let selectCount = {}; // 每种券选中的张数
|
|
|
|
// 1. 优先排序 desc 为空或为 0 的,再根据 price 从大到小排序,再根据满减条件 desc 从大到小排序
|
|
|
|
stackingCoupons.sort((a, b) => {
|
|
|
|
if (a.desc === '0' || a.desc === '') return -1; // 优先选择 desc 为空或为 0 的
|
|
...
|
...
|
@@ -1246,35 +1384,82 @@ Page({ |
|
|
|
return parseFloat(b.desc) - parseFloat(a.desc); // 按满减条件 desc 从大到小
|
|
|
|
});
|
|
|
|
console.log('排序后的可叠加券列表',stackingCoupons);
|
|
|
|
// 2. 从排序后的券中选择
|
|
|
|
for (let coupon of stackingCoupons) {
|
|
|
|
let couponDesc = parseFloat(coupon.desc);
|
|
|
|
let couponPrice = parseFloat(coupon.price);
|
|
|
|
let kyNum = Math.floor(remainingPrice / couponDesc);// 计算券可用张数
|
|
|
|
if (couponDesc === 0) {// 如果满减条件为 0,直接选择
|
|
|
|
list1.push(coupon);
|
|
|
|
remainingPrice -= couponPrice; // 减去价格
|
|
|
|
totalDiscount += couponPrice; // 计算优惠金额
|
|
|
|
continue;
|
|
|
|
// 2. 可叠加满减券:先选满减门槛最大的券,再叠加其他可用的券(门槛之和不能超过输入金额)
|
|
|
|
let thresholdDescSum = 0
|
|
|
|
let maxThresholdValue = 0
|
|
|
|
let thresholdCoupons = stackingCoupons.filter(coupon => (parseFloat(coupon.desc) || 0) > 0)
|
|
|
|
// 按满减门槛从大到小排序,门槛相同再按优惠金额从大到小
|
|
|
|
thresholdCoupons.sort((a, b) => {
|
|
|
|
if (parseFloat(b.desc) !== parseFloat(a.desc)) return parseFloat(b.desc) - parseFloat(a.desc)
|
|
|
|
return parseFloat(b.price) - parseFloat(a.price)
|
|
|
|
})
|
|
|
|
thresholdCoupons.forEach(coupon => {
|
|
|
|
let couponDesc = parseFloat(coupon.desc) || 0
|
|
|
|
let couponPrice = parseFloat(coupon.price)
|
|
|
|
let maxCopies = Math.floor((amount - thresholdDescSum) / couponDesc)
|
|
|
|
if (maxCopies > coupon.maxNum) maxCopies = coupon.maxNum
|
|
|
|
if (maxCopies > 0) {
|
|
|
|
selectCount[coupon.aid] = maxCopies
|
|
|
|
thresholdDescSum += couponDesc * maxCopies
|
|
|
|
maxThresholdValue += couponPrice * maxCopies
|
|
|
|
}
|
|
|
|
})
|
|
|
|
list1 = stackingCoupons.filter(i => (selectCount[i.aid] || 0) > 0)
|
|
|
|
console.log('可叠加优惠券组合', list1);
|
|
|
|
// 3. 无门槛可叠加券:满减门槛之和小于输入金额时可以叠加,等于时和满减组合取优惠更大的
|
|
|
|
// 先算无门槛券单独使用的优惠总额
|
|
|
|
let noDescValue = 0
|
|
|
|
let noDescCount = {}
|
|
|
|
stackingCoupons.forEach(coupon => {
|
|
|
|
let couponDesc = parseFloat(coupon.desc) || 0
|
|
|
|
let couponPrice = parseFloat(coupon.price)
|
|
|
|
if (couponDesc === 0 && couponPrice > 0) {
|
|
|
|
let num = Math.floor((amount - noDescValue) / couponPrice)
|
|
|
|
if (num > coupon.maxNum) num = coupon.maxNum
|
|
|
|
if (num > 0) {
|
|
|
|
noDescCount[coupon.aid] = num
|
|
|
|
noDescValue += couponPrice * num
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 如果剩余金额足够,选择券
|
|
|
|
if (remainingPrice > couponDesc || remainingPrice == couponDesc) {
|
|
|
|
// 计算实际使用的张数,不能超过 kyNum
|
|
|
|
let usedCount = Math.min(kyNum, 1); // 假设每次只使用一张
|
|
|
|
let potentialDiscount = couponDesc * usedCount; // 计算潜在的优惠金额
|
|
|
|
if ((totalDiscount + potentialDiscount < amount) || (totalDiscount + potentialDiscount == amount)) {// 检查总优惠金额是否会超过总金额
|
|
|
|
list1.push(coupon);
|
|
|
|
remainingPrice -= couponPrice * usedCount; // 减去价格
|
|
|
|
totalDiscount += potentialDiscount; // 计算优惠金额
|
|
|
|
})
|
|
|
|
let maxStackableValue = maxThresholdValue
|
|
|
|
if (thresholdDescSum < amount) {
|
|
|
|
// 可以叠加:无门槛券按剩余优惠额度叠加上去
|
|
|
|
stackingCoupons.forEach(coupon => {
|
|
|
|
let couponDesc = parseFloat(coupon.desc) || 0
|
|
|
|
let couponPrice = parseFloat(coupon.price)
|
|
|
|
if (couponDesc === 0 && couponPrice > 0) {
|
|
|
|
let num = Math.floor((amount - maxStackableValue) / couponPrice)
|
|
|
|
if (num > coupon.maxNum) num = coupon.maxNum
|
|
|
|
if (num > 0) {
|
|
|
|
selectCount[coupon.aid] = num
|
|
|
|
maxStackableValue += couponPrice * num
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
list1 = stackingCoupons.filter(i => (selectCount[i.aid] || 0) > 0)
|
|
|
|
} else if (noDescValue > maxThresholdValue) {
|
|
|
|
// 门槛等于输入金额,不能叠加,取无门槛券或满减券中优惠更大的
|
|
|
|
list1 = stackingCoupons.filter(i => (noDescCount[i.aid] || 0) > 0)
|
|
|
|
selectCount = noDescCount
|
|
|
|
maxStackableValue = noDescValue
|
|
|
|
} else if (noDescValue == maxThresholdValue && noDescValue > 0) {
|
|
|
|
// 优惠相同取最早到期
|
|
|
|
let listThreshold = stackingCoupons.filter(i => (selectCount[i.aid] || 0) > 0)
|
|
|
|
let listNoDesc = stackingCoupons.filter(i => (noDescCount[i.aid] || 0) > 0)
|
|
|
|
let min1 = listThreshold.length > 0 ? Math.min(...listThreshold.map(item => item.useEtime)) : Infinity
|
|
|
|
let min2 = listNoDesc.length > 0 ? Math.min(...listNoDesc.map(item => item.useEtime)) : Infinity
|
|
|
|
if (min2 < min1) {
|
|
|
|
list1 = listNoDesc
|
|
|
|
selectCount = noDescCount
|
|
|
|
}
|
|
|
|
// 如果剩余金额已经小于等于 0,停止选择
|
|
|
|
if (remainingPrice < 0 || remainingPrice == 0) break;
|
|
|
|
}
|
|
|
|
let stackList = list1
|
|
|
|
let stackCount = selectCount
|
|
|
|
// 遍历有效优惠券,寻找不可叠加的优惠券
|
|
|
|
let maxNonStackableValue = 0
|
|
|
|
validCoupons.forEach(coupon => {
|
|
|
|
if (coupon.accumulationShow === '0') {
|
|
|
|
if (coupon.accumulationShow != '1') {
|
|
|
|
const discountAmount = parseFloat(coupon.price);
|
|
|
|
// 计算实际支付金额
|
|
|
|
const finalAmount = amount - discountAmount;
|
|
...
|
...
|
@@ -1287,27 +1472,25 @@ Page({ |
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
console.log('可叠加优惠券组合', list1);
|
|
|
|
console.log('不可叠加的优惠券', list2);
|
|
|
|
// 计算两个列表的最大优惠值
|
|
|
|
let maxStackableValue = list1.reduce((total, coupon) => total + parseFloat(coupon.price), 0);
|
|
|
|
console.log('可叠加优惠券组合总金额', maxStackableValue);
|
|
|
|
console.log('不可叠加的优惠券总金额', maxNonStackableValue);
|
|
|
|
// 比较两个最大值并输出结果
|
|
|
|
if (maxStackableValue > maxNonStackableValue) {
|
|
|
|
finalList = list1
|
|
|
|
finalList = stackList
|
|
|
|
} else if (maxStackableValue < maxNonStackableValue) {
|
|
|
|
finalList = list2
|
|
|
|
} else {
|
|
|
|
console.log(`两者的优惠值相同: ${maxStackableValue}`);
|
|
|
|
let copiedList1 = JSON.parse(JSON.stringify(list1));
|
|
|
|
let copiedList1 = JSON.parse(JSON.stringify(stackList));
|
|
|
|
let copiedList2 = JSON.parse(JSON.stringify(list2));
|
|
|
|
let minList1 = copiedList1.length > 0 ? Math.min(...copiedList1.map(item => item.useEtime)) : Infinity;
|
|
|
|
let minList2 = copiedList2.length > 0 ? Math.min(...copiedList2.map(item => item.useEtime)) : Infinity;
|
|
|
|
// 判断最小的 useEtime 是在 list1 还是 list2
|
|
|
|
if (minList1 <= minList2) {
|
|
|
|
console.log('最小的在 list1 中', list1);
|
|
|
|
finalList = list1
|
|
|
|
console.log('最小的在 list1 中', stackList);
|
|
|
|
finalList = stackList
|
|
|
|
} else {
|
|
|
|
console.log('最小的在 list2 中', list2);
|
|
|
|
finalList = list2
|
|
...
|
...
|
@@ -1320,19 +1503,32 @@ Page({ |
|
|
|
let target = arr.findIndex(obj => obj.activity_id === coupon.activity_id);
|
|
|
|
if (target>-1) {
|
|
|
|
arr[target].showCpupon = 1;
|
|
|
|
arr[target].checked = true;
|
|
|
|
discountPrice += parseFloat(coupon.price); // 使用 parseFloat 确保类型正确
|
|
|
|
arr[target].checkedNum = stackCount[coupon.aid] || 1;
|
|
|
|
discountPrice += parseFloat(coupon.price) * (stackCount[coupon.aid] || 1); // 使用 parseFloat 确保类型正确
|
|
|
|
}
|
|
|
|
console.log('选中的券', {
|
|
|
|
...coupon
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// 根据选中的张数展开最终券列表
|
|
|
|
finalList = []
|
|
|
|
arr.forEach(item => {
|
|
|
|
if (item.checkedNum > 0) {
|
|
|
|
for (let k = 0; k < item.checkedNum; k++) {
|
|
|
|
finalList.push({
|
|
|
|
...item,
|
|
|
|
activity_id: item.activityIds[k]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
discountPrice = discountPrice.toFixed(2)
|
|
|
|
console.log('总优惠金额:', discountPrice);
|
|
|
|
console.log('消费金抵扣:',this.data.consumeDiscount);
|
|
|
|
this.setData({
|
|
|
|
discountPrice,
|
|
|
|
});
|
|
|
|
this.updateCanAdd()
|
|
|
|
return {
|
|
|
|
arr,
|
|
|
|
discountPrice,
|
|
...
|
...
|
@@ -1425,42 +1621,83 @@ Page({ |
|
|
|
let obj = this.checkTimeInInterval(currentTime, lunchDis, lunchDinnerList);
|
|
|
|
//节假日数组
|
|
|
|
var holidays = [
|
|
|
|
'2025-1-1', // 元旦
|
|
|
|
'2025-1-28', // 春节
|
|
|
|
'2025-1-29', // 春节
|
|
|
|
'2025-1-30', // 春节
|
|
|
|
'2025-1-31', // 春节
|
|
|
|
'2025-2-1', // 春节
|
|
|
|
'2025-2-2', // 春节
|
|
|
|
'2025-2-3', // 春节
|
|
|
|
'2025-2-4', // 春节
|
|
|
|
'2025-4-4', //清明
|
|
|
|
'2025-4-5', //清明
|
|
|
|
'2025-4-6', //清明
|
|
|
|
'2025-5-1', // 劳动节
|
|
|
|
'2025-5-2', // 劳动节
|
|
|
|
'2025-5-3', // 劳动节
|
|
|
|
'2025-5-4', // 劳动节
|
|
|
|
'2025-5-5', // 劳动节
|
|
|
|
'2025-5-31', // 端午节
|
|
|
|
'2025-6-1', // 端午节
|
|
|
|
'2025-6-2', // 端午节
|
|
|
|
'2025-10-1', // 国庆节、中秋节
|
|
|
|
'2025-10-2', // 国庆节、中秋节
|
|
|
|
'2025-10-3', // 国庆节、中秋节
|
|
|
|
'2025-10-4', // 国庆节、中秋节
|
|
|
|
'2025-10-5', // 国庆节、中秋节
|
|
|
|
'2025-10-6', // 国庆节、中秋节
|
|
|
|
'2025-10-7', // 国庆节、中秋节
|
|
|
|
'2025-10-8', // 国庆节、中秋节
|
|
|
|
'2026-1-1', // 元旦
|
|
|
|
'2026-1-2', // 元旦
|
|
|
|
'2026-1-3', // 元旦
|
|
|
|
'2026-2-15', // 春节
|
|
|
|
'2026-2-16', // 春节
|
|
|
|
'2026-2-17', // 春节
|
|
|
|
'2026-2-18', // 春节
|
|
|
|
'2026-2-19', // 春节
|
|
|
|
'2026-2-20', // 春节
|
|
|
|
'2026-2-21', // 春节
|
|
|
|
'2026-2-22', // 春节
|
|
|
|
'2026-2-23', // 春节
|
|
|
|
'2026-4-4', //清明
|
|
|
|
'2026-4-5', //清明
|
|
|
|
'2026-4-6', //清明
|
|
|
|
'2026-5-1', // 劳动节
|
|
|
|
'2026-5-2', // 劳动节
|
|
|
|
'2026-5-3', // 劳动节
|
|
|
|
'2026-5-4', // 劳动节
|
|
|
|
'2026-5-5', // 劳动节
|
|
|
|
'2026-6-19', // 端午节
|
|
|
|
'2026-6-20', // 端午节
|
|
|
|
'2026-6-21', // 端午节
|
|
|
|
'2026-9-25', // 中秋节
|
|
|
|
'2026-9-26', // 中秋节
|
|
|
|
'2026-9-27', // 中秋节
|
|
|
|
'2026-10-1', // 国庆节
|
|
|
|
'2026-10-2', // 国庆节
|
|
|
|
'2026-10-3', // 国庆节
|
|
|
|
'2026-10-4', // 国庆节
|
|
|
|
'2026-10-5', // 国庆节
|
|
|
|
'2026-10-6', // 国庆节
|
|
|
|
'2026-10-7', // 国庆节
|
|
|
|
'2027-1-1', // 元旦
|
|
|
|
'2027-1-2', // 元旦
|
|
|
|
'2027-1-3', // 元旦
|
|
|
|
'2027-2-5', // 春节
|
|
|
|
'2027-2-6', // 春节
|
|
|
|
'2027-2-7', // 春节
|
|
|
|
'2027-2-8', // 春节
|
|
|
|
'2027-2-9', // 春节
|
|
|
|
'2027-2-10', // 春节
|
|
|
|
'2027-2-11', // 春节
|
|
|
|
'2027-2-12', // 春节
|
|
|
|
'2027-2-13', // 春节
|
|
|
|
'2027-4-3', //清明
|
|
|
|
'2027-4-4', //清明
|
|
|
|
'2027-4-5', //清明
|
|
|
|
'2027-5-1', // 劳动节
|
|
|
|
'2027-5-2', // 劳动节
|
|
|
|
'2027-5-3', // 劳动节
|
|
|
|
'2027-5-4', // 劳动节
|
|
|
|
'2027-5-5', // 劳动节
|
|
|
|
'2027-6-9', // 端午节
|
|
|
|
'2027-9-15', // 中秋节
|
|
|
|
'2027-10-1', // 国庆节
|
|
|
|
'2027-10-2', // 国庆节
|
|
|
|
'2027-10-3', // 国庆节
|
|
|
|
'2027-10-4', // 国庆节
|
|
|
|
'2027-10-5', // 国庆节
|
|
|
|
'2027-10-6', // 国庆节
|
|
|
|
'2027-10-7', // 国庆节
|
|
|
|
];
|
|
|
|
//周末上班日期数组
|
|
|
|
var nWeekend = [
|
|
|
|
'2025-1-26', //春节调整
|
|
|
|
'2025-2-8', //春节调整
|
|
|
|
'2025-4-27', //五一调整
|
|
|
|
'2025-9-28', //国庆调整
|
|
|
|
'2025-10-11', //国庆调整
|
|
|
|
'2026-1-4', //元旦调整
|
|
|
|
'2026-2-14', //春节调整
|
|
|
|
'2026-2-28', //春节调整
|
|
|
|
'2026-5-9', //五一调整
|
|
|
|
'2026-9-20', //国庆调整
|
|
|
|
'2026-10-10', //国庆调整
|
|
|
|
'2027-1-31', //春节调整
|
|
|
|
'2027-2-14', //春节调整
|
|
|
|
'2027-4-25', //五一调整
|
|
|
|
'2027-5-8', //五一调整
|
|
|
|
'2027-9-26', //国庆调整
|
|
|
|
'2027-10-9', //国庆调整
|
|
|
|
];
|
|
|
|
var curdate = new Date();
|
|
|
|
var year = curdate.getFullYear();
|
|
...
|
...
|
@@ -1644,4 +1881,4 @@ Page({ |
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}) |
|
|
\ No newline at end of file |
|
|
|
}) |
...
|
...
|
|