Commit b1e08d47d0a0de2ad22e898f49e46bf416ce5a47

Authored by pengye
1 parent 10c4c215

优惠券扫码购买页5

... ... @@ -102,24 +102,29 @@ Page({
const values = e.detail.value
let arr = []
let currentCoupon = '0'; //没选券 为0 可叠加券1 不可叠加券2
let inputValue = this.data.inputValue * 1
let val = 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 += list[i].price * 1
arr.push({
...list[i]
})
list[i].checked = true
if (list[i].accumulationShow == '1') {
currentCoupon = '1'
break
} else {
currentCoupon = '2'
break
}
break
}
}
}
console.log('没选券为0可叠加券1不可叠加券2', currentCoupon);
let remaining = inputValue - val; //剩余金额
console.log('没选券为0可叠加券1不可叠加券2', currentCoupon, remaining);
//没选券 所有可选的打开
if (currentCoupon == '0') {
list.forEach(item => {
... ... @@ -131,16 +136,20 @@ Page({
//选的不可叠加券 其他所有的可叠加券都不可选
if (currentCoupon == '2') {
list.forEach(item => {
if (item.accumulationShow == "1") {
if (item.accumulationShow == "1" || !item.checked) {
item.showCpupon = '0';
} else {
item.showCpupon = '1';
}
})
}
//选的可叠加券 其他所有的不可叠加券都不可选
if (currentCoupon == '1') {
list.forEach(item => {
if (item.accumulationShow == "0") {
if (item.accumulationShow == "0" || (remaining - item.price < 0 && !item.checked)) {
item.showCpupon = '0';
} else if (item.accumulationShow == "1") {
item.showCpupon = '1';
}
})
}
... ... @@ -265,11 +274,11 @@ Page({
if (res.ret == '200') {
console.log('核销成功', str);
this.setData({
inputValue:'',
finalList:[],
couponArr:[],
discountPrice:'0.00',
actualPrice:'',
inputValue: '',
finalList: [],
couponArr: [],
discountPrice: '0.00',
actualPrice: '',
})
this.getCoupon()
}
... ... @@ -280,6 +289,10 @@ Page({
filterCoupons(list) {
const currentDate = new Date();
currentDate.setHours(0, 0, 0, 0);
let obj = this.data.canSolt
console.log('当前餐段、是不是法定节假日', {
...obj
});
list.forEach(coupon => {
const startUseDate = new Date(currentDate);
let endUseDate = new Date(currentDate);
... ... @@ -298,8 +311,6 @@ Page({
}
// 今天不是领取当日,但在有效天数内 && 今天是领取当日且可用 && 券是开启状态
const isUseDate = (currentDate > startUseDate && currentDate < endUseDate) && coupon.is_open == '1'
let obj = this.data.canSolt
console.log('当前餐段、是不是法定节假日',{...obj});
let selectedValue = true;
let str = true
if (coupon.exp_date && coupon.exp_date.week_data && coupon.exp_date.week_data.length > 0) {
... ... @@ -355,7 +366,7 @@ Page({
const amount = parseFloat(inputValue);
const validCoupons = arr.filter(coupon => (coupon.isOk == '1' && parseFloat(coupon.desc) <= amount));
// 排序后,优先选择最大优惠的券
validCoupons.sort((a, b) => parseInt(b.price) - parseInt(a.price));
validCoupons.sort((a, b) => parseFloat(b.price) - parseFloat(a.price));
arr.forEach(item => {
const isValid = validCoupons.some(validCoupon => validCoupon.activity_id == item.activity_id);
item.canCheck = isValid ? '1' : '0'; // 如果在 validCoupons 中,设置 canCheck 为 1,否则为 0
... ... @@ -371,7 +382,7 @@ Page({
validCoupons.forEach(coupon => {
// 可叠加券
if (coupon.accumulationShow == '1') {
const discountAmount = parseInt(coupon.price);
const discountAmount = parseFloat(coupon.price);
// 只有在添加优惠券后剩余金额仍大于或等于0时才添加
if (remainingValue - discountAmount >= 0) {
list1.push(coupon);
... ... @@ -390,12 +401,12 @@ Page({
// 遍历有效优惠券,寻找不可叠加的优惠券
validCoupons.forEach(coupon => {
if (coupon.accumulationShow === '0') {
const discountAmount = parseInt(coupon.price);
const discountAmount = parseFloat(coupon.price);
// 计算实际支付金额
const finalAmount = amount - discountAmount;
// 确保实际支付金额不小于0,并且是最优惠的
if (finalAmount >= 0) {
if (!list2.length || discountAmount > parseInt(coupon.price)) {
if (!list2.length || discountAmount > parseFloat(coupon.price)) {
list2.push({
...coupon
}); // 更新最优惠的不可叠加券
... ... @@ -406,8 +417,8 @@ Page({
console.log('可叠加的优惠券组合2', list1);
console.log('不可叠加的优惠券', list2);
// 计算两个列表的最大优惠值
let maxStackableValue = list1.reduce((total, coupon) => total + parseInt(coupon.price), 0);
let maxNonStackableValue = list2.reduce((total, coupon) => total + parseInt(coupon.price), 0);
let maxStackableValue = list1.reduce((total, coupon) => total + parseFloat(coupon.price), 0);
let maxNonStackableValue = list2.reduce((total, coupon) => total + parseFloat(coupon.price), 0);
// 比较两个最大值并输出结果
if (maxStackableValue > maxNonStackableValue) {
... ... @@ -572,7 +583,6 @@ Page({
'2025-10-11', //国庆调整
];
var curdate = new Date();
curdate.setTime(curdate.getTime() + 4 * 24 * 60 * 60 * 1000);
var year = curdate.getFullYear();
var month = curdate.getMonth() + 1;
var date = curdate.getDate();
... ... @@ -584,7 +594,7 @@ Page({
} else {
obj.isshow = '0'
}
console.log('不可用日期信息:餐段、节假日', obj);
console.log('不可用日期信息餐段节假日', obj);
if (obj && obj.can && obj.solt) {
this.setData({
canSolt: {
... ...