易购添加库存不足提示
This commit is contained in:
parent
389951eeb6
commit
14826e746d
@ -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,
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 加运费
|
// 加运费
|
||||||
|
|||||||
@ -437,26 +437,42 @@ export default {
|
|||||||
},
|
},
|
||||||
//商品数量变化
|
//商品数量变化
|
||||||
handleQuantityChange(val, item) {
|
handleQuantityChange(val, item) {
|
||||||
// 先在前端直接更新数量,确保页面显示及时变化
|
|
||||||
// 注意:这里的val可能是直接的数值,也可能是包含value属性的对象
|
|
||||||
// 我们需要先确定正确的值
|
|
||||||
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"),
|
||||||
|
|||||||
@ -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++;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user