Commit 60c7021675dfc7d10633f6dadc6ee3126b6c73c0

Authored by pengye
1 parent cc269b8d

付款页券 默认勾选券、输入为空问题处理

@@ -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 // 如果当前和等于输入值,直接返回
@@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
32 <view slot="modalContent"> 32 <view slot="modalContent">
33 <scroll-view class="couponBox" scroll-y="true"> 33 <scroll-view class="couponBox" scroll-y="true">
34 <checkbox-group bindchange="checkboxChange"> 34 <checkbox-group bindchange="checkboxChange">
35 - <view wx:for="{{couponArr}}" class="couponItems {{item.showCpupon == '0' ? 'couponNo' : ''}}"> 35 + <view wx:for="{{couponArr}}" data-activityId="{{item.activity_id}}" class="couponItems {{item.showCpupon == '0' ? 'couponNo' : ''}}">
36 <view class="itemLeft"> 36 <view class="itemLeft">
37 <view class="priceText" wx:if="{{item.price}}"> 37 <view class="priceText" wx:if="{{item.price}}">
38 <view class="icons font24r">¥</view><text class="priceText">{{item.price}}</text> 38 <view class="icons font24r">¥</view><text class="priceText">{{item.price}}</text>
@@ -40,7 +40,7 @@ @@ -40,7 +40,7 @@
40 <view class="icons font20r" wx:if="{{item.desc!='0'}}">消费满{{item.desc}}元可用</view> 40 <view class="icons font20r" wx:if="{{item.desc!='0'}}">消费满{{item.desc}}元可用</view>
41 <view class="icons font20r" wx:if="{{item.desc=='0'}}">无门槛</view> 41 <view class="icons font20r" wx:if="{{item.desc=='0'}}">无门槛</view>
42 </view> 42 </view>
43 - <view class="itemRight" data-activityId="{{item.activity_id}}"> 43 + <view class="itemRight">
44 <view class="anameText"> 44 <view class="anameText">
45 <text class="font40r">{{item.aname}}</text> 45 <text class="font40r">{{item.aname}}</text>
46 <view class="discountText1 font20r">{{item.accumulationShow == '1' ? '可' : '不可'}}叠加</view> 46 <view class="discountText1 font20r">{{item.accumulationShow == '1' ? '可' : '不可'}}叠加</view>