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

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) }}
</view>
<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)">
<view slot="minus" class="minus">
<u-icon name="minus" size="20"></u-icon>
@ -128,7 +128,7 @@
<span></span>{{ ite.sales_price }}
</view>
<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)">
<view slot="minus" class="minus">
<u-icon name="minus" size="20"></u-icon>
@ -293,25 +293,49 @@ export default {
},
//
handleQuantityChange(val, item) {
//
// valvalue
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
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;
// 使$set
this.$set(item.commodity_goods_info_list[0], 'quantity', quantity);
currentQuantity = item.commodity_goods_info_list[0].quantity || 0;
stockQuantity = item.commodity_goods_info_list[0].stock_quantity || 0;
goodsToUpdate = item.commodity_goods_info_list[0];
}
// ite.quantity
else {
this.goodsId = item.id;
// 使$set
this.$set(item, 'quantity', quantity);
currentQuantity = item.quantity || 0;
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 = {
user_id: uni.getStorageSync('userId'),
user_id: uni.getStorageSync("userId"),
goods_id_and_count: [
{
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);
//
//
this.getShopCarList();
// goodsDetail
// goodsDetail
setTimeout(() => {
//
this.syncGoodsQuantities();
}, 100);
uni.showToast({
title: '操作成功!',
title: "操作成功!",
success() { },
});
});
},
//
syncGoodsQuantities() {
//