完成商品买一赠一的功能

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

View File

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

View File

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