Showing
1 changed file
with
29 additions
and
19 deletions
| @@ -102,24 +102,29 @@ Page({ | @@ -102,24 +102,29 @@ Page({ | ||
| 102 | const values = e.detail.value | 102 | const values = e.detail.value |
| 103 | let arr = [] | 103 | let arr = [] |
| 104 | let currentCoupon = '0'; //没选券 为0 可叠加券1 不可叠加券2 | 104 | let currentCoupon = '0'; //没选券 为0 可叠加券1 不可叠加券2 |
| 105 | + let inputValue = this.data.inputValue * 1 | ||
| 106 | + let val = 0; | ||
| 105 | for (let i = 0, lenI = list.length; i < lenI; ++i) { | 107 | for (let i = 0, lenI = list.length; i < lenI; ++i) { |
| 106 | list[i].checked = false; | 108 | list[i].checked = false; |
| 107 | for (let j = 0, lenJ = values.length; j < lenJ; ++j) { | 109 | for (let j = 0, lenJ = values.length; j < lenJ; ++j) { |
| 108 | if (list[i].activity_id === values[j]) { | 110 | if (list[i].activity_id === values[j]) { |
| 111 | + val += list[i].price * 1 | ||
| 109 | arr.push({ | 112 | arr.push({ |
| 110 | ...list[i] | 113 | ...list[i] |
| 111 | }) | 114 | }) |
| 112 | list[i].checked = true | 115 | list[i].checked = true |
| 113 | if (list[i].accumulationShow == '1') { | 116 | if (list[i].accumulationShow == '1') { |
| 114 | currentCoupon = '1' | 117 | currentCoupon = '1' |
| 118 | + break | ||
| 115 | } else { | 119 | } else { |
| 116 | currentCoupon = '2' | 120 | currentCoupon = '2' |
| 121 | + break | ||
| 117 | } | 122 | } |
| 118 | - break | ||
| 119 | } | 123 | } |
| 120 | } | 124 | } |
| 121 | } | 125 | } |
| 122 | - console.log('没选券为0可叠加券1不可叠加券2', currentCoupon); | 126 | + let remaining = inputValue - val; //剩余金额 |
| 127 | + console.log('没选券为0可叠加券1不可叠加券2', currentCoupon, remaining); | ||
| 123 | //没选券 所有可选的打开 | 128 | //没选券 所有可选的打开 |
| 124 | if (currentCoupon == '0') { | 129 | if (currentCoupon == '0') { |
| 125 | list.forEach(item => { | 130 | list.forEach(item => { |
| @@ -131,16 +136,20 @@ Page({ | @@ -131,16 +136,20 @@ Page({ | ||
| 131 | //选的不可叠加券 其他所有的可叠加券都不可选 | 136 | //选的不可叠加券 其他所有的可叠加券都不可选 |
| 132 | if (currentCoupon == '2') { | 137 | if (currentCoupon == '2') { |
| 133 | list.forEach(item => { | 138 | list.forEach(item => { |
| 134 | - if (item.accumulationShow == "1") { | 139 | + if (item.accumulationShow == "1" || !item.checked) { |
| 135 | item.showCpupon = '0'; | 140 | item.showCpupon = '0'; |
| 141 | + } else { | ||
| 142 | + item.showCpupon = '1'; | ||
| 136 | } | 143 | } |
| 137 | }) | 144 | }) |
| 138 | } | 145 | } |
| 139 | //选的可叠加券 其他所有的不可叠加券都不可选 | 146 | //选的可叠加券 其他所有的不可叠加券都不可选 |
| 140 | if (currentCoupon == '1') { | 147 | if (currentCoupon == '1') { |
| 141 | list.forEach(item => { | 148 | list.forEach(item => { |
| 142 | - if (item.accumulationShow == "0") { | 149 | + if (item.accumulationShow == "0" || (remaining - item.price < 0 && !item.checked)) { |
| 143 | item.showCpupon = '0'; | 150 | item.showCpupon = '0'; |
| 151 | + } else if (item.accumulationShow == "1") { | ||
| 152 | + item.showCpupon = '1'; | ||
| 144 | } | 153 | } |
| 145 | }) | 154 | }) |
| 146 | } | 155 | } |
| @@ -265,11 +274,11 @@ Page({ | @@ -265,11 +274,11 @@ Page({ | ||
| 265 | if (res.ret == '200') { | 274 | if (res.ret == '200') { |
| 266 | console.log('核销成功', str); | 275 | console.log('核销成功', str); |
| 267 | this.setData({ | 276 | this.setData({ |
| 268 | - inputValue:'', | ||
| 269 | - finalList:[], | ||
| 270 | - couponArr:[], | ||
| 271 | - discountPrice:'0.00', | ||
| 272 | - actualPrice:'', | 277 | + inputValue: '', |
| 278 | + finalList: [], | ||
| 279 | + couponArr: [], | ||
| 280 | + discountPrice: '0.00', | ||
| 281 | + actualPrice: '', | ||
| 273 | }) | 282 | }) |
| 274 | this.getCoupon() | 283 | this.getCoupon() |
| 275 | } | 284 | } |
| @@ -280,6 +289,10 @@ Page({ | @@ -280,6 +289,10 @@ Page({ | ||
| 280 | filterCoupons(list) { | 289 | filterCoupons(list) { |
| 281 | const currentDate = new Date(); | 290 | const currentDate = new Date(); |
| 282 | currentDate.setHours(0, 0, 0, 0); | 291 | currentDate.setHours(0, 0, 0, 0); |
| 292 | + let obj = this.data.canSolt | ||
| 293 | + console.log('当前餐段、是不是法定节假日', { | ||
| 294 | + ...obj | ||
| 295 | + }); | ||
| 283 | list.forEach(coupon => { | 296 | list.forEach(coupon => { |
| 284 | const startUseDate = new Date(currentDate); | 297 | const startUseDate = new Date(currentDate); |
| 285 | let endUseDate = new Date(currentDate); | 298 | let endUseDate = new Date(currentDate); |
| @@ -298,8 +311,6 @@ Page({ | @@ -298,8 +311,6 @@ Page({ | ||
| 298 | } | 311 | } |
| 299 | // 今天不是领取当日,但在有效天数内 && 今天是领取当日且可用 && 券是开启状态 | 312 | // 今天不是领取当日,但在有效天数内 && 今天是领取当日且可用 && 券是开启状态 |
| 300 | const isUseDate = (currentDate > startUseDate && currentDate < endUseDate) && coupon.is_open == '1' | 313 | const isUseDate = (currentDate > startUseDate && currentDate < endUseDate) && coupon.is_open == '1' |
| 301 | - let obj = this.data.canSolt | ||
| 302 | - console.log('当前餐段、是不是法定节假日',{...obj}); | ||
| 303 | let selectedValue = true; | 314 | let selectedValue = true; |
| 304 | let str = true | 315 | let str = true |
| 305 | if (coupon.exp_date && coupon.exp_date.week_data && coupon.exp_date.week_data.length > 0) { | 316 | if (coupon.exp_date && coupon.exp_date.week_data && coupon.exp_date.week_data.length > 0) { |
| @@ -355,7 +366,7 @@ Page({ | @@ -355,7 +366,7 @@ Page({ | ||
| 355 | const amount = parseFloat(inputValue); | 366 | const amount = parseFloat(inputValue); |
| 356 | const validCoupons = arr.filter(coupon => (coupon.isOk == '1' && parseFloat(coupon.desc) <= amount)); | 367 | const validCoupons = arr.filter(coupon => (coupon.isOk == '1' && parseFloat(coupon.desc) <= amount)); |
| 357 | // 排序后,优先选择最大优惠的券 | 368 | // 排序后,优先选择最大优惠的券 |
| 358 | - validCoupons.sort((a, b) => parseInt(b.price) - parseInt(a.price)); | 369 | + validCoupons.sort((a, b) => parseFloat(b.price) - parseFloat(a.price)); |
| 359 | arr.forEach(item => { | 370 | arr.forEach(item => { |
| 360 | const isValid = validCoupons.some(validCoupon => validCoupon.activity_id == item.activity_id); | 371 | const isValid = validCoupons.some(validCoupon => validCoupon.activity_id == item.activity_id); |
| 361 | item.canCheck = isValid ? '1' : '0'; // 如果在 validCoupons 中,设置 canCheck 为 1,否则为 0 | 372 | item.canCheck = isValid ? '1' : '0'; // 如果在 validCoupons 中,设置 canCheck 为 1,否则为 0 |
| @@ -371,7 +382,7 @@ Page({ | @@ -371,7 +382,7 @@ Page({ | ||
| 371 | validCoupons.forEach(coupon => { | 382 | validCoupons.forEach(coupon => { |
| 372 | // 可叠加券 | 383 | // 可叠加券 |
| 373 | if (coupon.accumulationShow == '1') { | 384 | if (coupon.accumulationShow == '1') { |
| 374 | - const discountAmount = parseInt(coupon.price); | 385 | + const discountAmount = parseFloat(coupon.price); |
| 375 | // 只有在添加优惠券后剩余金额仍大于或等于0时才添加 | 386 | // 只有在添加优惠券后剩余金额仍大于或等于0时才添加 |
| 376 | if (remainingValue - discountAmount >= 0) { | 387 | if (remainingValue - discountAmount >= 0) { |
| 377 | list1.push(coupon); | 388 | list1.push(coupon); |
| @@ -390,12 +401,12 @@ Page({ | @@ -390,12 +401,12 @@ Page({ | ||
| 390 | // 遍历有效优惠券,寻找不可叠加的优惠券 | 401 | // 遍历有效优惠券,寻找不可叠加的优惠券 |
| 391 | validCoupons.forEach(coupon => { | 402 | validCoupons.forEach(coupon => { |
| 392 | if (coupon.accumulationShow === '0') { | 403 | if (coupon.accumulationShow === '0') { |
| 393 | - const discountAmount = parseInt(coupon.price); | 404 | + const discountAmount = parseFloat(coupon.price); |
| 394 | // 计算实际支付金额 | 405 | // 计算实际支付金额 |
| 395 | const finalAmount = amount - discountAmount; | 406 | const finalAmount = amount - discountAmount; |
| 396 | // 确保实际支付金额不小于0,并且是最优惠的 | 407 | // 确保实际支付金额不小于0,并且是最优惠的 |
| 397 | if (finalAmount >= 0) { | 408 | if (finalAmount >= 0) { |
| 398 | - if (!list2.length || discountAmount > parseInt(coupon.price)) { | 409 | + if (!list2.length || discountAmount > parseFloat(coupon.price)) { |
| 399 | list2.push({ | 410 | list2.push({ |
| 400 | ...coupon | 411 | ...coupon |
| 401 | }); // 更新最优惠的不可叠加券 | 412 | }); // 更新最优惠的不可叠加券 |
| @@ -406,8 +417,8 @@ Page({ | @@ -406,8 +417,8 @@ Page({ | ||
| 406 | console.log('可叠加的优惠券组合2', list1); | 417 | console.log('可叠加的优惠券组合2', list1); |
| 407 | console.log('不可叠加的优惠券', list2); | 418 | console.log('不可叠加的优惠券', list2); |
| 408 | // 计算两个列表的最大优惠值 | 419 | // 计算两个列表的最大优惠值 |
| 409 | - let maxStackableValue = list1.reduce((total, coupon) => total + parseInt(coupon.price), 0); | ||
| 410 | - let maxNonStackableValue = list2.reduce((total, coupon) => total + parseInt(coupon.price), 0); | 420 | + let maxStackableValue = list1.reduce((total, coupon) => total + parseFloat(coupon.price), 0); |
| 421 | + let maxNonStackableValue = list2.reduce((total, coupon) => total + parseFloat(coupon.price), 0); | ||
| 411 | 422 | ||
| 412 | // 比较两个最大值并输出结果 | 423 | // 比较两个最大值并输出结果 |
| 413 | if (maxStackableValue > maxNonStackableValue) { | 424 | if (maxStackableValue > maxNonStackableValue) { |
| @@ -572,7 +583,6 @@ Page({ | @@ -572,7 +583,6 @@ Page({ | ||
| 572 | '2025-10-11', //国庆调整 | 583 | '2025-10-11', //国庆调整 |
| 573 | ]; | 584 | ]; |
| 574 | var curdate = new Date(); | 585 | var curdate = new Date(); |
| 575 | - curdate.setTime(curdate.getTime() + 4 * 24 * 60 * 60 * 1000); | ||
| 576 | var year = curdate.getFullYear(); | 586 | var year = curdate.getFullYear(); |
| 577 | var month = curdate.getMonth() + 1; | 587 | var month = curdate.getMonth() + 1; |
| 578 | var date = curdate.getDate(); | 588 | var date = curdate.getDate(); |
| @@ -584,7 +594,7 @@ Page({ | @@ -584,7 +594,7 @@ Page({ | ||
| 584 | } else { | 594 | } else { |
| 585 | obj.isshow = '0' | 595 | obj.isshow = '0' |
| 586 | } | 596 | } |
| 587 | - console.log('不可用日期信息:餐段、节假日', obj); | 597 | + console.log('不可用日期信息餐段节假日', obj); |
| 588 | if (obj && obj.can && obj.solt) { | 598 | if (obj && obj.can && obj.solt) { |
| 589 | this.setData({ | 599 | this.setData({ |
| 590 | canSolt: { | 600 | canSolt: { |
-
Please register or login to post a comment