修复库存回显问题,修复多次加菜弹窗问题

This commit is contained in:
2026-04-13 18:12:46 +08:00
parent 2db9f6811a
commit dbe74f6486
8 changed files with 92 additions and 81 deletions

View File

@@ -3,7 +3,7 @@
<up-image :src="data.coverImg" mode="aspectFill" :width="img.width" :height="img.height"></up-image>
<view class="info u-flex u-row-between u-col-top u-flex-col">
<view class="limit-discount" v-if="is_time_discount">限时折扣</view>
<view class="nowStockerNumber" v-if="nowStockerNumber<=10">
<view class="nowStockerNumber" v-if="data.isAutoSoldStock&&nowStockerNumber<=10&&nowStockerNumber>0">
剩余库存{{nowStockerNumber}}
</view>
<view>
@@ -172,7 +172,7 @@
})
// 1. 筛选匹配的耗材列表
// 1. 筛选匹配的耗材列表,增加对应商品数量
const conslist=computed(()=>{
if(props.consStockList.length<=0){
return []
@@ -181,37 +181,27 @@
return props.data.consList.find(i =>{
return i.consInfoId == v.consId
});
});
})
// 2. 找到 stockNumber 最小的那一项
const minConsItem=computed(()=>{
if(conslist.value.length<=0){
return null
}
return conslist.value.reduce((prev, current) => {
return prev.stockNumber < current.stockNumber ? prev : current;
});
})
// 3. 找到和 minItem 的 consId 一样的那个消耗配置项
const targetCons=computed(()=>{
if(!minConsItem.value){
return null
}
return props.data.consList.find(i => i.consInfoId == minConsItem.value.consId);
}).map(v=>{
const cItem=props.data.consList.find(c=>c.consInfoId==v.consId)
const goodsNumber=Math.floor(v.stockNumber/cItem.surplusStock)
console.log('props.data',props.data.name);
console.log('goodsNumber',goodsNumber);
return {
...v,
goodsNumber
}
}).sort((a,b)=>{
return a.goodsNumber-b.goodsNumber
})
})
const nowStockerNumber=computed(()=>{
if(!targetCons.value||!minConsItem.value){
return 9999
}
return Math.floor(minConsItem.value.stockNumber/targetCons.value.surplusStock)
return conslist.value[0]?conslist.value[0].goodsNumber:9999
})
function consStockisFull(item) {
// 无数据直接返回 true或按你需求返回 false
if (!conslist.value.length) return true;
if(!minConsItem.value)return true;
if(!targetCons.value) return true;
if(!item.isAutoSoldStock){
return true
}
// 4. 判断:最小库存 > 每份消耗库存 → 返回 true否则 false
if (nowStockerNumber.value>=1) {

View File

@@ -407,9 +407,9 @@
initCart();
}
const allHistoryOrder=ref([])
const allHistoryOrder = ref([])
/**
* 获取订单详情
*/
@@ -432,7 +432,7 @@
console.log("data.historyOrder===", data.historyOrder);
allHistoryOrder.value = data.historyOrder.map((item) => {
allHistoryOrder.value = data.historyOrder.map((item) => {
return [...item.info];
}).flat();
@@ -838,29 +838,34 @@
//更新
let cartItem = cars[goodsInCarIndex];
let number = isAdd ? cartItem.number + 1 : +cartItem.number - 1;
if(isAdd){
if (number == 2 ) {
// 等待用户点击
const isConfirm = await showConfirmModal(
'购物车已有该商品,请确认是否重复',
'菜名名称:《' + $goods.name + '》'
);
if (!isConfirm) {
return
}
}
if(allHistoryOrder.value.find(v=>v.productId==$goods.id)){
if (isAdd) {
if (allHistoryOrder.value.find(v => v.productId == $goods.id)) {
// 等待用户点击
const isConfirm = await showConfirmModal(
'该商品已下单过,请确认是否重复',
'菜名称:《' + $goods.name + '》'
'菜名称:《' + $goods.name + '》'
);
if (!isConfirm) {
return
}
}else{
if (number == 2) {
// 等待用户点击
const isConfirm = await showConfirmModal(
'购物车已有该商品,请确认是否重复',
'菜品名称:《' + $goods.name + '》'
);
if (!isConfirm) {
return
}
}
}
}
if (!isAdd) {
if (number === 0 || number < suitNum) {
//移除
@@ -889,7 +894,7 @@
data.isGoodsAdd = false;
setSearchGoods(searchGoodsIndex, number);
} else {
// 不影响之前的代码 称重suit单独处理
if ($goods.type == "weight" && showCurrentInput) {
suitNum = showCurrentInput;
@@ -901,11 +906,11 @@
return;
}
}
if(allHistoryOrder.value.find(v=>v.productId==$goods.id)){
if (allHistoryOrder.value.find(v => v.productId == $goods.id)) {
// 等待用户点击
const isConfirm = await showConfirmModal(
'该商品已下单过,请确认是否重复',
'菜名称:《' + $goods.name + '》'
'菜名称:《' + $goods.name + '》'
);
if (!isConfirm) {
return
@@ -1144,28 +1149,27 @@
let cartId = carGoods.id;
let suitNum = goods.skuList[0].suitNum || 1;
let newNumber = carGoods.number * 1 + suitNum;
if (newNumber == 2&&carGoods.number<newNumber) {
if (allHistoryOrder.value.find(v => v.productId == goods.id)) {
// 等待用户点击
const isConfirm = await showConfirmModal(
'请确认当前菜品是否已上菜?',
'菜名名称' + goods.name + ''
'该商品已下单过,请确认是否重复',
'菜品名称:《' + goods.name + '》'
);
if (!isConfirm) {
return
}
if(allHistoryOrder.value.find(v=>v.productId==goods.id)){
}else{
if (newNumber == 2 && carGoods.number < newNumber) {
// 等待用户点击
const isConfirm = await showConfirmModal(
'该商品已下单过,请确认是否重复',
'菜名称:《' + goods.name + '》'
'购物车已有该商品,请确认是否重复?',
'菜名称:《' + goods.name + '》'
);
if (!isConfirm) {
return
}
}
}
editCart({
id: cartId,
@@ -1181,12 +1185,12 @@
);
data.isGoodsAdd = false;
} else {
if(allHistoryOrder.value.find(v=>v.productId==goods.id)){
if (allHistoryOrder.value.find(v => v.productId == goods.id)) {
// 等待用户点击
const isConfirm = await showConfirmModal(
'该商品已下单过,请确认是否重复',
'菜名称:《' + goods.name + '》'
'菜名称:《' + goods.name + '》'
);
if (!isConfirm) {
return