易购添加库存不足提示

This commit is contained in:
赵毅 2025-09-05 15:57:03 +08:00
parent 389951eeb6
commit 14826e746d
4 changed files with 69 additions and 17 deletions

View File

@ -515,20 +515,35 @@ export default {
addCar() { addCar() {
let that = this; let that = this;
//
const currentGoods = this.info.commodity_goods_info_list[this.currentGGIndex];
//
const currentQuantity = currentGoods.cart_count ? currentGoods.cart_count.count : 0;
const stockQuantity = currentGoods.stock_quantity || 0;
//
if (currentQuantity >= stockQuantity) {
uni.showToast({
title: "库存不足",
icon: "none",
duration: 2000
});
return;
}
// //
let goods_id_and_count = []; let goods_id_and_count = [];
this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = { this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = {
count: 1, count: currentQuantity + 1,
}; };
this.info.commodity_goods_info_list.forEach((item) => { this.info.commodity_goods_info_list.forEach((item) => {
console.log(item.cart_count);
goods_id_and_count.push({ goods_id_and_count.push({
goods_id: item.id, goods_id: item.id,
count: item.cart_count ? item.cart_count.count : 0, count: item.cart_count ? item.cart_count.count : 0,
}); });
}); });
console.log(goods_id_and_count);
// update // update
request(apiArr.updateCar, "POST", { request(apiArr.updateCar, "POST", {
goods_id_and_count, goods_id_and_count,

View File

@ -168,8 +168,8 @@
</view> </view>
</view> </view>
<!-- 运费 --> <!-- 运费 -->
<view class="goods-desc" style="margin-top: 10rpx;">运费 {{ <!-- <view class="goods-desc" style="margin-top: 10rpx;">运费 {{
item.commodity_goods_info.freight }}</view> item.commodity_goods_info.freight }}</view> -->
</view> </view>
<view class="quantity-control"> <view class="quantity-control">
<view class="decrease-btn" @tap.stop="decreaseQuantity(item)">-</view> <view class="decrease-btn" @tap.stop="decreaseQuantity(item)">-</view>
@ -420,14 +420,24 @@ export default {
} }
}, },
increaseQuantity(item) { increaseQuantity(item) {
console.log("🚀 ~ increaseQuantity ~ item:", item)
const currentTime = new Date().getTime(); const currentTime = new Date().getTime();
const startTime = new Date(item.commodity_goods_info.group_buy_activity_info?.start_time).getTime(); const startTime = new Date(item.commodity_goods_info.group_buy_activity_info?.start_time).getTime();
const endTime = new Date(item.commodity_goods_info.group_buy_activity_info?.end_time).getTime(); const endTime = new Date(item.commodity_goods_info.group_buy_activity_info?.end_time).getTime();
if (item.count >= item.commodity_goods_info.stock_quantity) {
uni.showToast({
title: '库存不足',
icon: 'none'
});
return
}
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.commodity_goods_info.min_order_quantity
} else { } else {
if (item.count == item.commodity_goods_info.total_stock) { if (item.count >= item.commodity_goods_info.stock_quantity) {
uni.showToast({ uni.showToast({
title: '库存不足', title: '库存不足',
icon: 'none' icon: 'none'
@ -474,9 +484,11 @@ export default {
const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.start_time).getTime(); const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.start_time).getTime();
const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.end_time).getTime(); const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.end_time).getTime();
if (currentTime >= startTime && currentTime <= endTime) { if (currentTime >= startTime && currentTime <= endTime) {
total += goods.commodity_goods_info.group_buy_price * goods.count + goods.commodity_goods_info.freight; // total += goods.commodity_goods_info.group_buy_price * goods.count + goods.commodity_goods_info.freight;
total += goods.commodity_goods_info.group_buy_price * goods.count;
} else { } else {
total += goods.commodity_goods_info.sales_price * goods.count + goods.commodity_goods_info.freight; // total += goods.commodity_goods_info.sales_price * goods.count + goods.commodity_goods_info.freight;
total += goods.commodity_goods_info.sales_price * goods.count;
} }
}); });
// //
@ -488,9 +500,11 @@ export default {
const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.start_time).getTime(); const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.start_time).getTime();
const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.end_time).getTime(); const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.end_time).getTime();
if (currentTime >= startTime && currentTime <= endTime) { if (currentTime >= startTime && currentTime <= endTime) {
total += goods.commodity_goods_info.group_buy_price * goods.count + goods.commodity_goods_info.freight; // total += goods.commodity_goods_info.group_buy_price * goods.count + goods.commodity_goods_info.freight;
total += goods.commodity_goods_info.group_buy_price * goods.count;
} else { } else {
total += goods.commodity_goods_info.sales_price * goods.count + goods.commodity_goods_info.freight; // total += goods.commodity_goods_info.sales_price * goods.count + goods.commodity_goods_info.freight;
total += goods.commodity_goods_info.sales_price * goods.count;
} }
}); });
// //

View File

@ -437,26 +437,42 @@ export default {
}, },
// //
handleQuantityChange(val, item) { handleQuantityChange(val, item) {
//
// valvalue
//
const quantity = typeof val === 'object' && val !== null && 'value' in val ? val.value : val; const quantity = typeof val === 'object' && val !== null && 'value' in val ? val.value : val;
//
let currentQuantity = 0;
let stockQuantity = 0;
let goodsToUpdate = null;
// items.commodity_goods_info_list[0].quantity // items.commodity_goods_info_list[0].quantity
if ( if (
item.commodity_goods_info_list && item.commodity_goods_info_list &&
item.commodity_goods_info_list.length item.commodity_goods_info_list.length
) { ) {
this.goodsId = item.commodity_goods_info_list[0].id; this.goodsId = item.commodity_goods_info_list[0].id;
// 使$set currentQuantity = item.commodity_goods_info_list[0].quantity || 0;
this.$set(item.commodity_goods_info_list[0], 'quantity', quantity); stockQuantity = item.commodity_goods_info_list[0].stock_quantity || 0;
goodsToUpdate = item.commodity_goods_info_list[0];
} }
// ite.quantity // ite.quantity
else { else {
this.goodsId = item.id; this.goodsId = item.id;
// 使$set currentQuantity = item.quantity || 0;
this.$set(item, 'quantity', quantity); stockQuantity = item.stock_quantity || 0;
goodsToUpdate = item;
} }
//
if (quantity > currentQuantity && currentQuantity >= stockQuantity) {
uni.showToast({
title: "库存不足",
icon: 'none'
});
return;
}
// 使$set
this.$set(goodsToUpdate, 'quantity', quantity);
const params = { const params = {
user_id: uni.getStorageSync("userId"), user_id: uni.getStorageSync("userId"),

View File

@ -617,6 +617,13 @@ export default {
this.shopCarTotal++; this.shopCarTotal++;
} }
} else { } else {
if (carItem.count >= carItem.commodity_goods_info.stock_quantity) {
uni.showToast({
title: '库存不足',
icon: 'none'
});
return
}
carItem.count++; carItem.count++;
this.shopCarTotal++; this.shopCarTotal++;
} }