diff --git a/common/api/product/product.js b/common/api/product/product.js
index b6fe9ae..b67066e 100644
--- a/common/api/product/product.js
+++ b/common/api/product/product.js
@@ -54,4 +54,14 @@ export const productRelated = (data) => {
method: 'get',
data: data
})
-}
\ No newline at end of file
+}
+
+//获取相关推荐商品
+export const getConsStock = (data) => {
+ return request({
+ url: urlProduct + '/user/product/consStock',
+ method: 'get',
+ data: data
+ })
+}
+
diff --git a/common/config.js b/common/config.js
index 41cc002..1273981 100644
--- a/common/config.js
+++ b/common/config.js
@@ -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 = ''
diff --git a/pages/product/components/goods-modal.vue b/pages/product/components/goods-modal.vue
index e5304cc..323f9a1 100644
--- a/pages/product/components/goods-modal.vue
+++ b/pages/product/components/goods-modal.vue
@@ -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,
diff --git a/pages/product/index.vue b/pages/product/index.vue
index 5dcb96d..b9b3b74 100644
--- a/pages/product/index.vue
+++ b/pages/product/index.vue
@@ -58,13 +58,12 @@
限时折扣{{ limitDiscountCountdown }}
-
- 仅剩{{item.stockNumber}}份
+
+ 仅剩{{returnStockNumber(item)}}份
+ v-if="item.isSale == 0 || (item.isSaleTime == 0 && !item.isSaleTimeshow) || item.isSoldStock == 1 || returnStockNumber(item)<=0">
-
+
@@ -201,13 +200,11 @@
style="width:600rpx;height: 188rpx;">
-
+
分享
-
+
@@ -236,16 +233,15 @@
-
- 仅剩{{item1.stockNumber}}份
+
+ 仅剩{{returnStockNumber(item1)}}份
@@ -254,9 +250,8 @@
mode="">
-
+
@@ -598,7 +593,7 @@
-
@@ -640,7 +635,7 @@
-
+
@@ -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;