易购商品搜索部分添加库存校验

This commit is contained in:
赵毅 2025-10-09 15:44:37 +08:00
parent 41c389743e
commit 9be3eecd0f

View File

@ -78,7 +78,7 @@
{{ getPriceRange(item.commodity_goods_info_list) }} {{ getPriceRange(item.commodity_goods_info_list) }}
</view> </view>
<view class="CateInfo_Item_Money_right" v-if="!(item.commodity_goods_info_list.length > 1)"> <view class="CateInfo_Item_Money_right" v-if="!(item.commodity_goods_info_list.length > 1)">
<u-number-box :min="0" v-model="item.commodity_goods_info_list[0].quantity" <u-number-box :value="item.commodity_goods_info_list[0].quantity || 0" :min="0"
@change="(value) => handleQuantityChange(value, item)"> @change="(value) => handleQuantityChange(value, item)">
<view slot="minus" class="minus"> <view slot="minus" class="minus">
<u-icon name="minus" size="20"></u-icon> <u-icon name="minus" size="20"></u-icon>
@ -128,7 +128,7 @@
<span></span>{{ ite.sales_price }} <span></span>{{ ite.sales_price }}
</view> </view>
<view class="GGItem_Con_Msg_right"> <view class="GGItem_Con_Msg_right">
<u-number-box v-model="ite.quantity" :min="0" <u-number-box :value="ite.quantity || 0" :min="0"
@change="(value) => handleQuantityChange(value, ite)"> @change="(value) => handleQuantityChange(value, ite)">
<view slot="minus" class="minus"> <view slot="minus" class="minus">
<u-icon name="minus" size="20"></u-icon> <u-icon name="minus" size="20"></u-icon>
@ -293,25 +293,49 @@ 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 (item.commodity_goods_info_list && item.commodity_goods_info_list.length) { if (
item.commodity_goods_info_list &&
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 > stockQuantity) {
uni.showToast({
title: "库存不足",
icon: 'none'
});
// UI
this.$nextTick(() => {
this.$set(goodsToUpdate, 'quantity', Math.min(currentQuantity, stockQuantity));
});
return;
}
// 使$set
this.$set(goodsToUpdate, 'quantity', quantity);
const params = { const params = {
user_id: uni.getStorageSync('userId'), user_id: uni.getStorageSync("userId"),
goods_id_and_count: [ goods_id_and_count: [
{ {
goods_id: this.goodsId, goods_id: this.goodsId,
@ -319,24 +343,26 @@ export default {
}, },
], ],
}; };
request(apiArr.updateCar, 'POST', params).then((res) => { //
request(apiArr.updateCar, "POST", params).then((res) => {
console.log(res); console.log(res);
// //
this.getShopCarList(); this.getShopCarList();
// goodsDetail // goodsDetail
setTimeout(() => { setTimeout(() => {
// //
this.syncGoodsQuantities(); this.syncGoodsQuantities();
}, 100); }, 100);
uni.showToast({ uni.showToast({
title: '操作成功!', title: "操作成功!",
success() { }, success() { },
}); });
}); });
}, },
// //
syncGoodsQuantities() { syncGoodsQuantities() {
// //