完成商品买一赠一的功能

This commit is contained in:
赵毅 2025-10-21 16:40:41 +08:00
parent 1f7eebd66a
commit 7d6cff8a62
3 changed files with 45 additions and 38 deletions

View File

@ -462,10 +462,10 @@ export default {
});
item.count = 0
} else {
item.count--
item.count -= item.is_one_one === 1 ? 2 : 1;
}
} else {
item.count--
item.count -= item.is_one_one === 1 ? 2 : 1;
}
// 0carList
@ -496,11 +496,11 @@ export default {
if (currentTime >= startTime && currentTime <= endTime) {
if (item.count == 0) {
item.count += item.commodity_goods_info.min_order_quantity
item.count += item.is_one_one === 1 ? 2 : 1;
} else {
if (item.count >= item.commodity_goods_info.stock_quantity) {
if (item.count >= item.purchase_limit) {
uni.showToast({
title: '库存不足',
title: '您选择的数量已达到最大限购量',
icon: 'none'
});
return
@ -514,7 +514,7 @@ export default {
}
}
}
item.count++;
item.count += item.is_one_one === 1 ? 2 : 1;
this.changeCart(item);
},
//
@ -543,7 +543,7 @@ export default {
let total = 0;
this.orderList1.forEach(goods => {
// 使item.price
total += goods.price * goods.count;
total += goods.price * (goods.is_one_one === 1 ? goods.count / 2 : goods.count);
});
//
return total.toFixed(2);
@ -551,7 +551,7 @@ export default {
let total = 0;
this.orderList2.forEach(goods => {
// 使item.price
total += goods.price * goods.count;
total += goods.price * (goods.is_one_one === 1 ? goods.count / 2 : goods.count);
this.totalPrice = total.toFixed(2);
});
//

View File

@ -147,25 +147,23 @@ export default {
increaseQuantity(index) {
const item = this.goodsList[index]
if (item.quantity == 0) {
item.quantity += item.min_order_quantity || 1
this.carNum += item.min_order_quantity || 1
if (item.one_one === 1) {
item.quantity += 2
this.carNum += 2
} else {
item.quantity += 1
this.carNum += 1
}
} else {
if (item.quantity == item.total_stock) {
if (item.quantity == (item.one_one === 1 ? item.purchase_limit * 2 : item.purchase_limit)) {
uni.showToast({
title: '库存不足',
title: '您选择的数量已达到最大限购量',
icon: 'none'
});
return
}
if (item.quantity == item.max_limit_quantity) {
uni.showToast({
title: '一次最多购买' + item.max_limit_quantity + '件',
icon: 'none'
});
return
}
item.quantity++;
this.carNum++;
item.quantity = item.one_one === 1 ? item.quantity + 2 : item.quantity + 1;
this.carNum = item.one_one === 1 ? this.carNum + 2 : this.carNum + 1;
}
const params = {
goods_id_and_count: [
@ -173,6 +171,8 @@ export default {
goods_id: item.goods_id,
count: item.quantity,
price: item.promotional_price,
is_one_one: item.one_one,
purchase_limit: item.purchase_limit,
},
],
adver_id: item.adver_id
@ -183,9 +183,9 @@ export default {
decreaseQuantity(index) {
const item = this.goodsList[index]
if (item.quantity > 0) {
if (item.quantity == (item.min_order_quantity || 1)) {
item.quantity = 0
this.carNum = 0
if (item.one_one === 1) {
item.quantity = item.quantity - 2
this.carNum = this.carNum - 2
} else {
item.quantity--;
this.carNum--;
@ -197,6 +197,8 @@ export default {
goods_id: item.goods_id,
count: item.quantity,
price: item.promotional_price,
is_one_one: item.one_one,
purchase_limit: item.purchase_limit,
},
],
adver_id: item.adver_id

View File

@ -516,7 +516,12 @@ export default {
// } else {
// total += goods.commodity_goods_info.sales_price * goods.count;
// }
total += goods.price * goods.count
if(goods.is_one_one === 1) {
total += goods.price * (goods.count / 2)
} else {
total += goods.price * goods.count
}
}
});
});
@ -593,8 +598,8 @@ export default {
that.deleteCarItem(carItem, goodsIndex, item);
} else {
//
this.shopCarTotal = Math.max(0, this.shopCarTotal - 1);
carItem.count = carItem.count - 1;
this.shopCarTotal = carItem.is_one_one === 1 ? Math.max(0, that.shopCarTotal - 2) : Math.max(0, that.shopCarTotal - 1);
carItem.count = carItem.is_one_one === 1 ? carItem.count - 2 : carItem.count - 1;
this.handleQuantityChange(carItem.count, carItem);
// 0
@ -617,12 +622,12 @@ export default {
currentTime <= new Date(carItem.commodity_goods_info.group_buy_activity_info?.end_time).getTime();
if (isGroupBuyActive) {
if (carItem.count == 0) {
carItem.count = carItem.commodity_goods_info.min_order_quantity
this.shopCarTotal += carItem.commodity_goods_info.min_order_quantity;
carItem.count = carItem.is_one_one === 1 ? 2 : 1
this.shopCarTotal += carItem.is_one_one === 1 ? 2 : 1;
} else {
if (carItem.count == carItem.commodity_goods_info.total_stock) {
if (carItem.count == carItem.purchase_limit) {
uni.showToast({
title: '库存不足',
title: '您选择的数量已达到最大限购量',
icon: 'none'
});
return
@ -634,19 +639,19 @@ export default {
});
return
}
carItem.count++;
this.shopCarTotal++;
carItem.count += carItem.is_one_one === 1 ? 2 : 1;
this.shopCarTotal += carItem.is_one_one === 1 ? 2 : 1;
}
} else {
if (carItem.count >= carItem.commodity_goods_info.stock_quantity) {
if (carItem.count >= carItem.purchase_limit) {
uni.showToast({
title: '库存不足',
title: '您选择的数量已达到最大限购量',
icon: 'none'
});
return
}
carItem.count++;
this.shopCarTotal++;
carItem.count += carItem.is_one_one === 1 ? 2 : 1;
this.shopCarTotal += carItem.is_one_one === 1 ? 2 : 1;
}
const item = carItem.commodity_cart_and_goods_model;