修改库存回显计算,增加多次加菜弹窗确认

This commit is contained in:
2026-04-13 18:13:25 +08:00
parent 129bc1276a
commit d5c42f2092
4 changed files with 313 additions and 101 deletions

View File

@@ -647,7 +647,34 @@
}
});
}
// 封装成 Promise 的确认弹窗
const showConfirmModal = (title, content) => {
return new Promise((resolve) => {
uni.showModal({
title: title,
content: content,
showCancel: true,
cancelText: '取消添加',
confirmText: '继续',
success(res) {
// 确认返回 true取消/关闭返回 false
resolve(res.confirm === true);
}
});
});
};
// 提取合并 orderinfo.detailMap 数组的逻辑
function combineOrderInfoDetailMap(orderinfo) {
if (!orderinfo) return [];
let combinedArray = [];
for (const key in orderinfo.detailMap) {
if (orderinfo.detailMap.hasOwnProperty(key)) {
let subArray = orderinfo.detailMap[key];
combinedArray = [...combinedArray, ...subArray];
}
}
return combinedArray;
}
// 提交选择并执行下一步操作的方法
const submitSelection = async (goods) => {
if (!isProductAvailable(goods.days, goods.startTime,
@@ -664,7 +691,7 @@
if (goods.type == 'package' && goods.groupType != 0 && !allConditionsSatisfied.value) {
return
}
const oldGoodsArr = combineOrderInfoDetailMap(props.orderinfo)
if ((goods.type == 'package' && allConditionsSatisfied.value) || (goods.type ==
'sku' && canSubmit.value)) {
let res = null;
@@ -688,6 +715,30 @@
sku_id = selSku.value.id
}
console.log('goods', goods);
console.log('res',res);
const number=await calculateValue(res?res.number:0, '+', shopCartNumber.value)
console.log('number',number);
console.log('shopCartNumber',shopCartNumber.value);
if(res && number*1===2){
const isConfirm = await showConfirmModal(
'购物车已有该商品,请确认是否重复',
'菜品名称:《' + goods.name + '》'
);
if (!isConfirm) {
return
}
}
if (oldGoodsArr.find(v => v.productId == goods.id)) {
// 等待用户点击
const isConfirm = await showConfirmModal(
'该商品已下单过,请确认是否重复',
'菜品名称:《' + goods.name + '》'
);
if (!isConfirm) {
return
}
}
emits('websocketsendMessage', {
id: res ? res.id : '',
type: 'shopping',
@@ -697,7 +748,7 @@
operate_type: res ? 'edit' : 'add',
product_id: goods.id,
sku_id,
number: res ? await calculateValue(res.cartNumber, '+', shopCartNumber.value) :
number: res ? number:
shopCartNumber.value,
pro_group_info: returnSelectedGroupSnap(),
goods_type: goods.type == 'package' ? 'package' : '',
@@ -708,6 +759,27 @@
})
} else {
let res = cartStore.carts.find(cart => cart.product_id == goods.id && goods.skuList[0].id)
const number=await calculateValue(res?res.number:0, '+', shopCartNumber.value)
console.log('number',number);
if(res && number*1===2){
const isConfirm = await showConfirmModal(
'购物车已有该商品,请确认是否重复',
'菜品名称:《' + goods.name + '》'
);
if (!isConfirm) {
return
}
}
if (oldGoodsArr.find(v => v.productId == goods.id)) {
// 等待用户点击
const isConfirm = await showConfirmModal(
'该商品已下单过,请确认是否重复',
'菜品名称:《' + goods.name + '》'
);
if (!isConfirm) {
return
}
}
emits('websocketsendMessage', {
id: res ? res.id : '',
type: 'shopping',
@@ -717,7 +789,7 @@
operate_type: res ? 'edit' : 'add',
product_id: goods.id,
sku_id: goods.skuList[0].id,
number: res ? await calculateValue(res.cartNumber, '+', shopCartNumber.value) :
number: res ? number:
shopCartNumber.value,
memberPrice: goods.memberPrice,
is_print: 1,