试图找出如何制定购买x得到y免费。例如买10送1,买20送2等等。现在我只是使用像这样的公式。当更改为示例时,此公式将不起作用:购买5送1,购买10送2。
Ts
getFreeItem(){
let countTotal;
this.commonService.getOrderList$.subscribe((x) => {
x.filter(item => {
item.forEach((element, i) => {
if (element.freeDealMin !== null) {
item?.reduce((a, b) => {
let aVal = a?.count ? a?.count : a;
let bVal = b?.count ? b?.count : b;
countTotal = aVal + bVal;
return aVal + bVal;
}, 0);
let statusFree = element.freeDealMin/ countTotal;
if (statusFree == 1) {
this.freeDealQty = 1;
}else if (statusFree == 0.5) {
this.freeDealQty = 2;
}else if (statusFree == 0.33333333333) {
this.freeDealQty = 3;
}
}
});
});
});
} https://stackoverflow.com/questions/70074182
复制相似问题