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

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

@@ -54,4 +54,14 @@ export const productRelated = (data) => {
method: 'get',
data: data
})
}
}
//获取相关推荐商品
export const getConsStock = (data) => {
return request({
url: urlProduct + '/user/product/consStock',
method: 'get',
data: data
})
}

View File

@@ -1,6 +1,6 @@
// const debug = process.env.NODE_ENV == 'development' ? true : false;
// const debug = false; // false线上 true本地
const debug = false; // false线上 true本地
const debug = true; // false线上 true本地
let baseUrl = ''
let baseUrlwws = ''

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,

View File

@@ -58,13 +58,12 @@
限时折扣{{ limitDiscountCountdown }}</view>
<!-- <view class="limitDiscount" v-if="item.is_time_discount">
限时折扣{{ limitDiscountCountdown }}</view> -->
<view class="stock_warning"
v-if="item.isStock&&item.stockNumber<=10&&item.stockNumber>0">
仅剩{{item.stockNumber}}</view>
<view class="stock_warning" v-if="returnStockNumber(item)<=10&&returnStockNumber(item)>0">
仅剩{{returnStockNumber(item)}}</view>
</view>
<view class="vifgoodsImg flex-center"
v-if="item.isSale == 0 || (item.isSaleTime == 0 && !item.isSaleTimeshow) || item.isSoldStock == 1 || (item.isStock == 1 && item.stockNumber <= 0)">
v-if="item.isSale == 0 || (item.isSaleTime == 0 && !item.isSaleTimeshow) || item.isSoldStock == 1 || returnStockNumber(item)<=0">
<image v-if="item.isSale == 0" src="@/static/ztt/icon_goods_yxj.svg"
style="width: 200rpx; height: 100%" mode=""></image>
<image v-else-if="item.isSaleTime == 0 && !item.isSaleTimeshow"
@@ -72,8 +71,8 @@
</image>
<image v-else-if="item.isSoldStock == 1" src="@/static/ztt/icon_goods_sq.svg"
style="width: 200rpx; height: 100%" mode=""></image>
<image v-else-if="item.isStock == 1 && item.stockNumber <= 0"
src="@/static/ztt/icon_goods_kcbz.svg" style="width: 200rpx; height: 100%" mode="">
<image v-else src="@/static/ztt/icon_goods_kcbz.svg" style="width: 200rpx; height: 100%"
mode="">
</image>
</view>
<view class="u-flex u-m-t-32 u-row-between">
@@ -201,13 +200,11 @@
style="width:600rpx;height: 188rpx;"></image>
<view class="absolute swiper-mask" @click.stop="swiperClick(scope.item)">
<view class="share-btn-box" v-if="showShare(scope.item)">
<ymf-share
@shareClick="shareBtnClick(scope.item)"
>
<ymf-share @shareClick="shareBtnClick(scope.item)">
<view class="share-btn">分享</view>
</ymf-share>
</view>
</view>
</view>
@@ -236,16 +233,15 @@
<!-- <view class="limitDiscount" v-if="item1.is_time_discount">
限时折扣{{ limitDiscountCountdown }}</view> -->
<view class="stock_warning"
v-if="item1.isStock&&item1.stockNumber<=10&&item.stockNumber>0">
仅剩{{item1.stockNumber}}</view>
<view class="stock_warning" v-if="returnStockNumber(item1)<=10&&returnStockNumber(item1)>0">
仅剩{{returnStockNumber(item1)}}</view>
</view>
<view class="vifgoodsImg" v-if="
item1.isSale == 0 ||
(item1.isSaleTime == 0 && !item1.isSaleTimeshow) ||
item1.isSoldStock == 1 ||
(item1.isStock == 1 && item1.stockNumber <= 0)
(returnStockNumber(item1)<=0)
">
<image v-if="item1.isSale == 0" src="@/static/ztt/icon_goods_yxj.svg"
style="width: 200rpx; height: 100%" mode=""></image>
@@ -254,9 +250,8 @@
mode=""></image>
<image v-else-if="item1.isSoldStock == 1" src="@/static/ztt/icon_goods_sq.svg"
style="width: 200rpx; height: 100%" mode=""></image>
<image v-else-if="item1.isStock == 1 && item1.stockNumber <= 0"
src="@/static/ztt/icon_goods_kcbz.svg" style="width: 200rpx; height: 100%"
mode=""></image>
<image v-else src="@/static/ztt/icon_goods_kcbz.svg"
style="width: 200rpx; height: 100%" mode=""></image>
</view>
<view v-if="index == '0'" class="topSort" :class="'c' + (index1 + 1)">
@@ -598,7 +593,7 @@
<recommendGoodsModal v-if="isDataLoaded" @onBuyClick="onBuyClick"></recommendGoodsModal>
<view v-for="(item,index) in goodsModalList" :key="index">
<goodsModal :key="index" v-model="item.show" :goods="item.goods" @prveImgs="prveImgs"
<goodsModal :key="index" v-model="item.show" :goods="item.goods" @prveImgs="prveImgs" :orderinfo="orderinfo"
@shareClick="shareClick" @close="goodsModalClose(index)" @websocketsendMessage="websocketsendMessage"
@modalAdd="modalAdd" :GoodsIDInCartNumMap="GoodsIDInCartNumMap"></goodsModal>
</view>
@@ -640,7 +635,7 @@
</view>
</u-popup>
<ymf-share-popup ></ymf-share-popup>
<ymf-share-popup></ymf-share-popup>
</view>
</template>
@@ -663,6 +658,7 @@
APIgroupquery,
APIminiAppinfo,
APIminiAppskuinfo,
getConsStock,
productRelated
} from '@/common/api/product/product.js';
@@ -934,9 +930,9 @@
//左侧导航点击
const leftTap = (index) => {
console.log('topArr.value[index] ',topArr.value[index] );
console.log('store.height',store.height);
console.log('scrollTop',topArr.value[index] - store.height);
console.log('topArr.value[index] ', topArr.value[index]);
console.log('store.height', store.height);
console.log('scrollTop', topArr.value[index] - store.height);
uni.pageScrollTo({
scrollTop: topArr.value[index] - store.height,
duration: 0
@@ -1029,70 +1025,72 @@
/*商品区域轮播图 start*/
const shareSwiperItem=ref(null)
const shareSwiperItem = ref(null)
function swiperClick(item) {
console.log('swiperClick',item);
shareSwiperItem.value=item
const pTag=returnPageTags(item.jumpPagePath)
if(pTag==='pp-list'){
console.log('swiperClick', item);
shareSwiperItem.value = item
const pTag = returnPageTags(item.jumpPagePath)
if (pTag === 'pp-list') {
return uni.navigateTo({
url:item.jumpPagePath+'&shopId='+uni.cache.get('shopId')
url: item.jumpPagePath + '&shopId=' + uni.cache.get('shopId')
})
}
if(pTag==='pp-detail'){
const url=item.jumpPagePath+'&shopId='+uni.cache.get('shopId')+'&'+item.extendParam
if (pTag === 'pp-detail') {
const url = item.jumpPagePath + '&shopId=' + uni.cache.get('shopId') + '&' + item.extendParam
return uni.navigateTo({
url:url.replace('goodsId','id')
url: url.replace('goodsId', 'id')
})
}
if(pTag==='gb-list'){
if (pTag === 'gb-list') {
return uni.navigateTo({
url:item.jumpPagePath+'&shopId='+uni.cache.get('shopId')
url: item.jumpPagePath + '&shopId=' + uni.cache.get('shopId')
})
}
if(pTag==='gb-detail'){
const url=item.jumpPagePath+'&shopId='+uni.cache.get('shopId')+'&'+item.extendParam
if (pTag === 'gb-detail') {
const url = item.jumpPagePath + '&shopId=' + uni.cache.get('shopId') + '&' + item.extendParam
return uni.navigateTo({
url:url.replace('goodsId','wareId')
url: url.replace('goodsId', 'wareId')
})
}
if(pTag==='dis'){
if (pTag === 'dis') {
return uni.navigateTo({
url:item.jumpPagePath+'&shopId='+uni.cache.get('shopId')
url: item.jumpPagePath + '&shopId=' + uni.cache.get('shopId')
})
}
if(pTag==='index'){
if (pTag === 'index') {
return uni.switchTab({
url:item.jumpPagePath+'&shopId='+uni.cache.get('shopId')
url: item.jumpPagePath + '&shopId=' + uni.cache.get('shopId')
})
}
if(pTag==='eat'){
if (pTag === 'eat') {
if (item.extendParam) {
const id=item.extendParam.split('=')[1]
const id = item.extendParam.split('=')[1]
const item = allGoodsArr.value.find(v => v.id == id)
if (item) {
clickspecifications(item)
}
}
}
if(pTag==='point'){
if (pTag === 'point') {
return uni.navigateTo({
url:item.jumpPagePath+'&shopId='+uni.cache.get('shopId')
url: item.jumpPagePath + '&shopId=' + uni.cache.get('shopId')
})
}
if(pTag==='point-detail'){
const url=item.jumpPagePath+'&shopId='+uni.cache.get('shopId')+'&'+item.extendParam
if (pTag === 'point-detail') {
const url = item.jumpPagePath + '&shopId=' + uni.cache.get('shopId') + '&' + item.extendParam
return uni.navigateTo({
url:url.replace('goodsId','id')
url: url.replace('goodsId', 'id')
})
}
}
function showShare(item){
if(item.isShareable&&item.isEnabled){
function showShare(item) {
if (item.isShareable && item.isEnabled) {
return true
}
return false
@@ -1368,6 +1366,7 @@
// 提交选择并执行下一步操作的方法
const submitSelection = async () => {
console.log('submitSelection', submitSelection)
if (!isProductAvailable(specifications.productListitem.days, specifications.productListitem.startTime,
specifications.productListitem.endTime)) {
uni.showToast({
@@ -1392,6 +1391,33 @@
selectedGroupSnap.value = [];
}
console.log('specifications.item', specifications.item);
const number = await calculateValue(res.cartNumber, '+', shopCartNumber.value)
const oldGoodsArr = combineOrderInfoDetailMap(orderinfo.value)
if (oldGoodsArr.find(v => v.productId == specifications.item.id)) {
// 等待用户点击
const isConfirm = await showConfirmModal(
'该商品已下单过,请确认是否重复',
'菜品名称:《' + specifications.item.name + '》'
);
if (!isConfirm) {
return
}
}else{
if (res && number * 1 === 2) {
const isConfirm = await showConfirmModal(
'购物车已有该商品,请确认是否重复',
'菜品名称:《' + specifications.item.name + '》'
);
if (!isConfirm) {
return
}
}
}
websocketsendMessage({
id: res ? res.cartListId : '',
type: 'shopping',
@@ -1401,8 +1427,7 @@
operate_type: res ? 'edit' : 'add',
product_id: specifications.product_id,
sku_id: specifications.sku_id,
number: res ? await calculateValue(res.cartNumber, '+', shopCartNumber.value) :
shopCartNumber.value,
number: res ? number : shopCartNumber.value,
pro_group_info: selectedGroupSnap.value,
goods_type: specifications.item.type == 'package' ? 'package' : '',
memberPrice: specifications.item.memberPrice,
@@ -1414,6 +1439,30 @@
selectedGroupSnap.value = [];
showShopsku.value = false;
} else {
const number = await calculateValue(res.cartNumber, '+', shopCartNumber.value)
const oldGoodsArr = combineOrderInfoDetailMap(orderinfo.value)
if (oldGoodsArr.find(v => v.productId == specifications.item.id)) {
// 等待用户点击
const isConfirm = await showConfirmModal(
'该商品已下单过,请确认是否重复',
'菜品名称:《' + specifications.item.name + '》'
);
if (!isConfirm) {
return
}
}else{
if (res && number * 1 === 2) {
const isConfirm = await showConfirmModal(
'购物车已有该商品,请确认是否重复',
'菜品名称:《' + specifications.item.name + '》'
);
if (!isConfirm) {
return
}
}
}
websocketsendMessage({
id: res ? res.cartListId : '',
type: 'shopping',
@@ -1423,8 +1472,7 @@
operate_type: res ? 'edit' : 'add',
product_id: specifications.product_id,
sku_id: specifications.sku_id,
number: res ? await calculateValue(res.cartNumber, '+', shopCartNumber.value) :
shopCartNumber.value,
number: res ? number : shopCartNumber.value,
memberPrice: specifications.item.memberPrice,
is_print: 1,
product_type: specifications.item.type,
@@ -1558,7 +1606,7 @@
};
// 判断商品是否在可售时间内
const isProductAvailable = async (sellDaysStr, startTimeStr, endTimeStr) => {
if(!sellDaysStr){
if (!sellDaysStr) {
return false
}
// 将后端返回的字符串转换为数组
@@ -1623,6 +1671,23 @@
return true;
}
// 封装成 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);
}
});
});
};
// 单规格
const singleclick = async (item, i) => {
console.log('单规格商品点击事件:', item, i);
@@ -1650,17 +1715,45 @@
} else if (item.suitNum >= cartNumberFloat && i === '-') {
suitNum = item.cartNumber;
}
const number = await calculateValue(item.cartNumber, i, suitNum)
console.log('number', number);
if (i === '+') {
const oldGoodsArr = combineOrderInfoDetailMap(orderinfo.value)
if (oldGoodsArr.find(v => v.productId == item.id)) {
// 等待用户点击
const isConfirm = await showConfirmModal(
'该商品已下单过,请确认是否重复',
'菜品名称:《' + item.name + '》'
);
if (!isConfirm) {
return
}
}else{
if (number * 1 == 2) {
const isConfirm = await showConfirmModal(
'购物车已有该商品,请确认是否重复',
'菜品名称:《' + item.name + '》'
);
if (!isConfirm) {
return
}
}
}
}
const sendMsg = {
type: 'shopping',
suitNum: item.suitNum,
table_code: uni.cache.get('tableCode'),
shop_id: uni.cache.get('shopId'),
operate_type: (await calculateValue(item.cartNumber, i, suitNum)) == 'del' ? 'del' : res ? 'edit' :
'add',
operate_type: number == 'del' ? 'del' : res ? 'edit' : 'add',
product_id: item.id,
sku_id: item.skuId,
memberPrice: item.memberPrice,
number: await calculateValue(item.cartNumber, i, suitNum),
number: number,
is_print: 1,
product_type: item.type,
is_time_discount: showLimitDiscount(item)
@@ -2094,6 +2187,7 @@
const orderinfo = ref({});
const confirmorderref = ref(null);
// 结账
const orderdetail = async () => {
isAutoClose = false;
@@ -2509,7 +2603,7 @@
console.log('options.initMessage', options.initMessage)
const newTableCode = userStore.getQueryString(res.result, 'code');
console.log('newTableCode',newTableCode);
console.log('newTableCode', newTableCode);
const shopInfoRes = await APIproductqueryShop({
tableCode: newTableCode
});
@@ -2567,7 +2661,8 @@
handleMixinOnLoad,
returnQuery,
jsonToUrl,
wxShare,returnPageTags,
wxShare,
returnPageTags,
returnCommonQuery
} from '@/utils/share.js'
// defineOptions({
@@ -2580,39 +2675,42 @@
function shareClick() {
isGoodsShare.value = true
}
function getPage(pageStr){
function getPage(pageStr) {
}
function shareBtnClick(item){
console.log('shareBtnClick',item);
shareSwiperItem.value=item
function shareBtnClick(item) {
console.log('shareBtnClick', item);
shareSwiperItem.value = item
}
function swiperShare(queryJson){
console.log('shareSwiperItem',shareSwiperItem.value);
const pTag=returnPageTags(shareSwiperItem.value.jumpPagePath)
function swiperShare(queryJson) {
console.log('shareSwiperItem', shareSwiperItem.value);
const pTag = returnPageTags(shareSwiperItem.value.jumpPagePath)
let query = jsonToUrl(queryJson)
query +=('&'+shareSwiperItem.value.extendParam)
query += ('&' + shareSwiperItem.value.extendParam)
const shopName = uni.cache.get('shopInfo').shopName || ''
const path=shareSwiperItem.value.jumpPagePath?shareSwiperItem.value.jumpPagePath:'/pages/product/index?type=beforehand'
console.log('path',path);
const json={
imageUrl:shareSwiperItem.value.imageUrl,
path: path+'&'+query,
title:shareSwiperItem.value.name+ (shopName ? `-${shopName}` : ''),
const path = shareSwiperItem.value.jumpPagePath ? shareSwiperItem.value.jumpPagePath :
'/pages/product/index?type=beforehand'
console.log('path', path);
const json = {
imageUrl: shareSwiperItem.value.imageUrl,
path: path + '&' + query,
title: shareSwiperItem.value.name + (shopName ? `-${shopName}` : ''),
}
if(pTag==='pp-detail'){
json.path=json.path.replace('goodsId','id')
if (pTag === 'pp-detail') {
json.path = json.path.replace('goodsId', 'id')
}
if(pTag==='gb-detail'){
json.path=json.path.replace('goodsId','wareId')
if (pTag === 'gb-detail') {
json.path = json.path.replace('goodsId', 'wareId')
}
if(pTag==='point-detail'){
json.path=json.path.replace('goodsId','id')
if (pTag === 'point-detail') {
json.path = json.path.replace('goodsId', 'id')
}
if(pTag.includes('eat')){
if(shareSwiperItem.value.extendParam){
json.path=json.path.replace('goodsId','showGoodsId')
if (pTag.includes('eat')) {
if (shareSwiperItem.value.extendParam) {
json.path = json.path.replace('goodsId', 'showGoodsId')
}
}
return wxShare(json)
@@ -2621,7 +2719,7 @@
async function onShare() {
const queryJson = await returnCommonQuery()
if(shareSwiperItem.value){
if (shareSwiperItem.value) {
return swiperShare(queryJson)
}
let query = jsonToUrl(queryJson)
@@ -2638,7 +2736,7 @@
json.title = shopName
json.imageUrl = uni.cache.get('shopInfo').logo || ''
}
return wxShare({
query,
...json,
@@ -2653,6 +2751,36 @@
const pageOptions = reactive({})
const carouselList = ref([])
async function getConsStocks() {
const res = await getConsStock({
shopId: userStore.shopInfo.id
})
consStockList.value = res || []
}
const consStockList = ref([])
function returnStockNumber(item) {
if(!item.isAutoSoldStock){
return 9999
}
const consList = item.consList
const matchStockList = consStockList.value.filter(v => {
return consList.find(c => c.consInfoId == v.consId)
}).map(v=>{
const cItem=item.consList.find(c=>c.consInfoId==v.consId)
const goodsNumber=Math.floor(v.stockNumber/cItem.surplusStock)
return {
...v,
goodsNumber
}
}).sort((a,b)=>{
return a.goodsNumber-b.goodsNumber
})
const minConsStockNumber=matchStockList[0]?matchStockList[0].goodsNumber:9999
return minConsStockNumber
}
onLoad(async (e) => {
Object.assign(pageOptions, e)
if (e.type) {
@@ -2684,7 +2812,8 @@
}
options.initMessage.shop_id = userStore.shopInfo.id
shopUserInfo.value = userStore.shopUserInfo
//耗材列表
await getConsStocks()
await productqueryProduct();
const extraInitPar = {}
@@ -2728,14 +2857,14 @@
tableCode: uni.cache.get('tableCode')
});
oldOrder.value = res;
nextTick(()=>{
nextTick(() => {
getElementTop();
})
if (res && res.id && shopInfo.registerType == 'after' && !e.noJump) {
toHistory();
return;
}
setTimeout(() => {
// 启动网络监听
useSocket.initNetworkListener();
@@ -2835,7 +2964,7 @@
}
onHide(() => {
isGoodsShare.value = false
shareSwiperItem.value=null
shareSwiperItem.value = null
closeSocket();
});
onUnload(() => {
@@ -4085,11 +4214,12 @@
padding: 32rpx 28rpx;
}
.share-btn-box{
.share-btn-box {
position: absolute;
right: 8rpx;
bottom: 14rpx;
}
.share-btn {
padding: 10rpx 32rpx;