2 Commits

Author SHA1 Message Date
b637a6dea9 优化判断库存 2026-04-22 10:21:58 +08:00
d5c42f2092 修改库存回显计算,增加多次加菜弹窗确认 2026-04-13 18:13:43 +08:00
4 changed files with 354 additions and 297 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,11 @@
限时折扣{{ 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="showStockNumber(item)&& !showNoBuy(item)">
仅剩{{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)">
<view class="vifgoodsImg flex-center" v-if="showNoBuy(item)">
<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 +70,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 +199,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,17 +232,11 @@
<!-- <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="showStockNumber(item1)&&!showNoBuy(item1)">
仅剩{{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)
">
<view class="vifgoodsImg" v-if="showNoBuy(item1)">
<image v-if="item1.isSale == 0" src="@/static/ztt/icon_goods_yxj.svg"
style="width: 200rpx; height: 100%" mode=""></image>
<image v-else-if="item1.isSaleTime == 0 && !item1.isSaleTimeshow"
@@ -254,9 +244,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)">
@@ -401,193 +390,7 @@
</view>
<!-- 规格 -->
<up-popup :show="showShopsku" :round="20" mode="bottom" @close="(showShopsku = false), (pagemetashow = false)">
<view class="shop_sku">
<scroll-view scroll-y style="max-height: 60vh; width: 100%">
<view class="positionabsolute">
<up-icon name="close-circle" @click="
showShopsku = false;
pagemetashow = false;
" color="#000" size="25"></up-icon>
</view>
<up-swiper :list="specifications.item.images" @change="swiperChange" :current="swiperCurrent"
radius="6px" height="250"
@click="prveImgs(specifications.item.images, specifications.item.images[swiperCurrent])">
<!-- <template v-slot:default="{item}">
<image :src=item></image>
</templte> -->
</up-swiper>
<view class="shop_sku_name">{{ specifications.item.name }}</view>
<view class="shop_sku_description" v-if="isSkuGoods">
{{ specifications.item.shortTitle ? specifications.item.shortTitle : '' }}
</view>
<view v-if="specifications.item.type != 'package'">
<view class="shop_sku_box" v-for="(specOptions, specType) in specifications.item.selectSpecInfo"
:key="specType">
<view class="shop_sku_box_name">
{{ specType }}
</view>
<view class="flex-start">
<view class="shop_sku_box_item" v-for="option in specOptions" :key="option"
@click="selectSpec(specType, option)" :class="{
shop_sku_box_item_selected: isSkuSelected(specType, option)
}">
{{ option }}
<view class="shop_sku_box_item_tip"
v-if="specifications.item.result && specifications.item.result.isSoldStock == 1 && selectedSpecs[specType] === option">
<view>售罄</view>
</view>
<view class="shop_sku_box_item_tip"
v-if="specifications.item.result == 'kong' && canSubmit == false && selectedSpecs[specType] === option">
<view>已下架</view>
</view>
</view>
</view>
</view>
</view>
<!-- 套餐 -->
<view v-else>
<view class="shop_sku_box">
<view v-for="(setmenu, setmenuindex) in specifications.item.groupSnap" :key="setmenuindex">
<view class="shop_sku_box_name">{{ setmenu.title }} {{ setmenu.count }}
选{{ setmenu.number }}</view>
<view class="flex-start">
<view class="shop_sku_box_item" v-for="(option, goodsid) in setmenu.goods"
:key="goodsid" @click="goodsidClick(setmenuindex, option, goodsid)" :class="{
shop_sku_box_item_selected: isOptionSelected(setmenuindex, option)
}" :disabled="isMaxSelected(setmenuindex) && !isOptionSelected(setmenuindex, option)">
{{ option.proName }}
<text v-if="option.unitName">/{{ option.unitName }}</text>
<view class="shop_sku_box_item_tip" v-if="specifications.item.isSoldStock == 1">
<view>售罄</view>
</view>
</view>
</view>
</view>
</view>
</view>
<!-- 推荐搭配 -->
<view class="u-m-t-48 u-p-30">
<view class="font-bold u-font-32 ">推荐搭配</view>
<view class="u-flex recommand-goods">
<view class=" item" v-for="(item,index) in 6" :key="index">
<up-image width="210rpx" height="210rpx" radius="12rpx"></up-image>
<view class="info">
<view class="u-line-2 name u-m-t-10 u-font-32 font-500">
商品名
</view>
<view class="u-flex u-row-between">
<view class="font-bold">
<text class="u-font-24">¥</text>
<text class="u-font-32">40</text>
</view>
<view class="btn">
<up-icon name="plus-circle-fill" color="#E9AB7A" size="25"></up-icon>
</view>
</view>
</view>
</view>
</view>
</view>
</scroll-view>
<!-- 占位 -->
<view class="shop_bottom">
<view class="flex-between">
<view class="price price-sku"
v-if="specifications.item.type != 'package' && specifications.item.result">
<text class="i">¥</text>
<view class="num">
<GoodsPrice :limitDiscount="cartStore.limitTimeDiscount"
:cart="specifications.item.result" :shopUserInfo="shopUserInfo"
:shopInfo="shopInfo"></GoodsPrice>
</view>
<text class="num" v-if="false">
{{
shopUserInfo.isVip == 1 && shopUserInfo.isMemberPrice == 1
? specifications.item.result.memberPrice || specifications.item.result.salePrice
: specifications.item.result.salePrice
}}
</text>
<text class="i"
v-if="specifications.item.unitName">/{{ specifications.item.unitName }}</text>
<text
v-if="specifications.item.result.suitNum > 1">「{{ specifications.item.result.suitNum }}{{ specifications.item.result.unitName }}起点」</text>
</view>
<view class="price price-package" v-else>
<text class="i">¥</text>
<view class="num">
<GoodsPrice :limitDiscount="cartStore.limitTimeDiscount" :cart="specifications.item"
:shopUserInfo="shopUserInfo" :shopInfo="shopInfo"></GoodsPrice>
</view>
<text class="num" v-if="false">
{{
shopUserInfo.isVip == 1 && shopUserInfo.isMemberPrice == 1
? specifications.item.memberPrice || specifications.item.salePrice
: specifications.item.salePrice
}}
</text>
<text class="i"
v-if="specifications.item.unitName">/{{ specifications.item.unitName }}</text>
<text
v-if="specifications.item.suitNum > 1">「{{ specifications.item.suitNum }}{{ specifications.item.unitName }}起点」</text>
</view>
<view class="operation-wrap"
v-if="specifications.item.type != 'package'&&stockNumberIsFull(specifications.item)">
<view class="btn">
<up-icon name="minus-circle-fill" color="#E9AB7A" size="25"
v-if="shopCartNumber > 0"></up-icon>
<view class="btnClick" @click="shopCart('-')"></view>
</view>
<text class="num">{{ shopCartNumber }}</text>
<view class="btn">
<up-icon name="plus-circle-fill" color="#E9AB7A" size="25"></up-icon>
<view class="btnClick" @click="shopCart('+')"></view>
</view>
</view>
</view>
<view class="shop_skuselect flex-start" v-if="selectedSpecsStr">
<view class="shop_skuselectname">{{ selectedSpecsStr }}</view>
</view>
<template v-if="!stockNumberIsFull(specifications.item)">
<view class="addShopping">
库存不足
</view>
</template>
<template v-else>
<template v-if="isSkuGoods">
<view v-if="specifications.item.type == 'package'" class="addShopping"
:class="shopCartNumber > 0 && allConditionsSatisfied ? 'active' : ''"
@click="submitSelection()">
{{ skuBtnText }}
</view>
<view v-else class="addShopping" :class="shopCartNumber > 0 && canSubmit ? 'active' : ''"
@click="submitSelection()">
{{ skuBtnText }}
</view>
</template>
<template v-else>
<view class="addShopping" :class="shopCartNumber > 0 ? 'active' : ''"
@click="submitSelection()">
{{ skuBtnText }}
</view>
</template>
</template>
</view>
</view>
</up-popup>
<view class="history_order" @click="toHistory"
v-if="shopInfo && shopInfo.registerType == 'after' && orderinfo.id">
<image class="img" src="@/static/history.png" mode=""></image>
@@ -598,7 +401,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 +443,7 @@
</view>
</u-popup>
<ymf-share-popup ></ymf-share-popup>
<ymf-share-popup></ymf-share-popup>
</view>
</template>
@@ -663,6 +466,7 @@
APIgroupquery,
APIminiAppinfo,
APIminiAppskuinfo,
getConsStock,
productRelated
} from '@/common/api/product/product.js';
@@ -758,6 +562,32 @@
productStore
} from '@/stores/user.js';
// 是否显示禁止购买
function showNoBuy(item) {
if (item.isSale == 0) {
return true
}
if (item.isSaleTime == 0 && !item.isSaleTimeshow) {
return true
}
if (item.isSoldStock == 1) {
return true
}
if(item.type==="single"){
const sku=item.skuList[0]
if(!sku){
return true
}
if(sku&&returnStockNumber(item)<sku.suitNum){
return true
}
}
if (returnStockNumber(item) <= 0) {
return true
}
return false
}
const storeMemberpay = Memberpay();
const store = useNavbarStore();
// 动态更新导航栏配置
@@ -934,9 +764,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,77 +859,77 @@
/*商品区域轮播图 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
}
/*商品区域轮播图 end*/
// 点击详情
const showShopsku = ref(false);
// 规格信息
const specifications = reactive({
@@ -1368,6 +1198,7 @@
// 提交选择并执行下一步操作的方法
const submitSelection = async () => {
console.log('submitSelection', submitSelection)
if (!isProductAvailable(specifications.productListitem.days, specifications.productListitem.startTime,
specifications.productListitem.endTime)) {
uni.showToast({
@@ -1392,6 +1223,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 +1259,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,
@@ -1412,8 +1269,31 @@
});
// 清空套餐选中
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,14 +1303,12 @@
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,
is_time_discount: showLimitDiscount(specifications.item)
});
showShopsku.value = false;
return;
}
@@ -1545,7 +1423,6 @@
.filter(([_, value]) => value.length > 0));
// 给默认数量
specifications.item.amountcartNumber = 0;
// showShopsku.value = true;
goodsModalList.value.push({
show: true,
goods: {
@@ -1558,7 +1435,7 @@
};
// 判断商品是否在可售时间内
const isProductAvailable = async (sellDaysStr, startTimeStr, endTimeStr) => {
if(!sellDaysStr){
if (!sellDaysStr) {
return false
}
// 将后端返回的字符串转换为数组
@@ -1623,6 +1500,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 +1544,53 @@
} else if (item.suitNum >= cartNumberFloat && i === '-') {
suitNum = item.cartNumber;
}
const number = await calculateValue(item.cartNumber, i, suitNum)
const goodsStockNumber = returnStockNumber(item)
console.log('number', number);
if (i === '+') {
if (goodsStockNumber < suitNum) {
return uni.showToast({
title: '库存不足',
icon: 'none'
})
}
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 +2024,7 @@
const orderinfo = ref({});
const confirmorderref = ref(null);
// 结账
const orderdetail = async () => {
isAutoClose = false;
@@ -2509,7 +2440,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 +2498,8 @@
handleMixinOnLoad,
returnQuery,
jsonToUrl,
wxShare,returnPageTags,
wxShare,
returnPageTags,
returnCommonQuery
} from '@/utils/share.js'
// defineOptions({
@@ -2580,39 +2512,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 +2556,7 @@
async function onShare() {
const queryJson = await returnCommonQuery()
if(shareSwiperItem.value){
if (shareSwiperItem.value) {
return swiperShare(queryJson)
}
let query = jsonToUrl(queryJson)
@@ -2638,7 +2573,7 @@
json.title = shopName
json.imageUrl = uni.cache.get('shopInfo').logo || ''
}
return wxShare({
query,
...json,
@@ -2653,6 +2588,42 @@
const pageOptions = reactive({})
const carouselList = ref([])
async function getConsStocks() {
const res = await getConsStock({
shopId: userStore.shopInfo.id
})
consStockList.value = res || []
}
const consStockList = ref([])
// 是否显示剩余库存数量
function showStockNumber(item) {
return !item.isSoldStock && returnStockNumber(item) <= 10 && returnStockNumber(item) > 0
}
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) {
@@ -2728,14 +2699,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();
@@ -2822,6 +2793,9 @@
// if(!topArr.value.length){
// getElementTop()
// }
//耗材列表
await getConsStocks()
});
//是否自动关闭socket
@@ -2835,7 +2809,7 @@
}
onHide(() => {
isGoodsShare.value = false
shareSwiperItem.value=null
shareSwiperItem.value = null
closeSocket();
});
onUnload(() => {
@@ -4085,11 +4059,12 @@
padding: 32rpx 28rpx;
}
.share-btn-box{
.share-btn-box {
position: absolute;
right: 8rpx;
bottom: 14rpx;
}
.share-btn {
padding: 10rpx 32rpx;