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

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

@@ -8,9 +8,9 @@
:height="height"
:maxCount="maxCount"
>
<template #default v-if="$slots.default">
<!-- <template #default v-if="$slots.default">
<slot></slot>
</template>
</template> -->
</up-upload>
</template>

View File

@@ -42,7 +42,8 @@ async function getProductListAjax() {
mask: true
});
const res = await getProductList();
list.value = res.productList;
console.log('res',res);
list.value = res;
} catch (error) {
console.log(error);
}

View File

@@ -145,7 +145,7 @@
let obj = pageData.types.find(item=> item.value == e)
return obj.name
}
let selArr=[]
getGoods()
/**
* 获取商品列表
@@ -200,7 +200,6 @@
const show = ref(props.modelValue)
let selArr=[]
let $selGoodsMap={}
async function open(arr) {

View File

@@ -75,7 +75,7 @@
<up-radio v-for="(item,index) in tuiStockTypes" :key="index" :label="item.label"
:name="item.key"></up-radio>
</up-radio-group>
<view class="color-red u-m-t-10">当前店铺退菜退库存规则跟随商品分类</view>
<view class="color-red u-m-t-10">当前店铺退菜退库存规则{{nowRefundRule}}</view>
</view>
</view>
@@ -143,7 +143,13 @@
}
}
})
const shopInfo=uni.getStorageSync('shopInfo')
const nowRefundRule=computed(()=>{
if(!shopInfo||!shopInfo.refundMode){
return ''
}
return shopInfo.refundMode==1?'跟随商品分类':'跟随单商品'
})
const pageData = reactive({
isBindGuige: false, //是否绑定至规格
})

View File

@@ -31,7 +31,7 @@
<view class="u-flex u-row-between">
<view>上传图片</view>
</view>
<view class="u-m-t-16">
<view class="u-m-t-16" >
<my-up-upload :maxCount="1" :multiple="false" v-model="form.coverImg"></my-up-upload>
</view>
</view>

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

View File

@@ -12,7 +12,8 @@
</view>
<view class="u-flex">
<view>
<text :class="[data.status]">{{$dict.getDiceName(data.status,'orderStatus')}}{{data.refundType?'['+$dict.getDiceName(data.refundType,'refundType')+']':''}}</text>
<text
:class="[data.status]">{{$dict.getDiceName(data.status,'orderStatus')}}{{data.refundType?'['+$dict.getDiceName(data.refundType,'refundType')+']':''}}</text>
</view>
<view class="line"></view>
<view class=" color-main">
@@ -33,13 +34,18 @@
<view class="" v-for="(item,index) in data.goods" :key="index">
<view class="u-flex u-row-between u-col-top u-m-t-32" v-if="item.productId!=-999">
<view>
<view class=""> {{item.productName}}</view>
<view class="">
<text>{{item.productName}}</text>
</view>
<view class="color-999 u-font-24 u-m-t-8">
{{item.skuName}}
</view>
</view>
<view class="u-flex u-flex-1 u-row-right" style="align-items: center;">
<view style="margin-right: 10rpx;">×{{item.num}}</view>
<view style="margin-right: 10rpx;">
<text>×{{item.num}}</text>
<text class="color-red u-m-l-10 font-bold" v-if="item.returnNum">(退{{item.returnNum}})</text>
</view>
<view class="u-text-right u-relative" :style="computedPriceStyle()">
<text>{{item.unitPrice}}</text>
</view>
@@ -56,7 +62,7 @@
<view class="no-wrap u-m-r-32">打包费</view>
<view>{{data.packFee||0}}</view>
</view>
<view style="height: 32rpx;" ></view>
<view style="height: 32rpx;"></view>
<view class="u-flex u-row-between u-col-top" v-if="data.seatInfo&&data.seatInfo.priceAmount>0">
<view class="no-wrap u-m-r-32">{{data.seatInfo.productName}}</view>
<view>{{data.seatInfo.priceAmount}}</view>
@@ -98,8 +104,13 @@
</template>
<script setup>
import { computed, reactive, ref, watch } from 'vue';
import {
computed,
reactive,
ref,
watch
} from 'vue';
import dayjs from 'dayjs';
import go from '@/commons/utils/go.js'
@@ -126,8 +137,8 @@
let $goodsMap = {}
let goosZhonglei = ref(0)
let goodsNumber = ref(0)
let originAmount = computed(()=>{
let total=0;
let originAmount = computed(() => {
let total = 0;
for (let i in props.data.goods) {
const goods = props.data.goods[i]
if ($goodsMap.hasOwnProperty(goods.productId)) {
@@ -142,17 +153,17 @@
return total
})
const priceSize = 9
let minWidth=ref(36)
let minWidth = ref(36)
function computedPriceStyle() {
return {
'min-width':minWidth.value + 'px'
'min-width': minWidth.value + 'px'
}
}
function goodsMapInit() {
}
goodsMapInit()
watch(() => props.data.goods.length, (newval) => {