From 663fb5a7ecb421ee51cc8ea7dc9412232199bcc5 Mon Sep 17 00:00:00 2001 From: gyq <875626088@qq.com> Date: Thu, 4 Dec 2025 16:13:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A2=84=E4=B8=8B=E5=8D=95?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E5=BA=97=E9=93=BA=E6=89=AB=E7=A0=81=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/indexs.vue | 2 + pages/product/index.vue | 116 +++++++++++++++++++++++++++++++++------- 2 files changed, 100 insertions(+), 18 deletions(-) diff --git a/pages/index/indexs.vue b/pages/index/indexs.vue index 44d1ea4..72e32a0 100644 --- a/pages/index/indexs.vue +++ b/pages/index/indexs.vue @@ -80,6 +80,7 @@ const scanCodehandle = (i) => { // 预点单 function beforehandOrderHandle() { + popupShow.value = false; let shopUserInfo = uni.cache.get('shopUserInfo'); uni.cache.set('dinersNum', 1); uni.cache.set('tableCode', shopUserInfo.id); @@ -90,6 +91,7 @@ function beforehandOrderHandle() { // 扫码点餐 async function scanOrderHandle() { + popupShow.value = false; const store = productStore(); await store.scanCodeactions(); } diff --git a/pages/product/index.vue b/pages/product/index.vue index cbbe7fa..2d19c32 100644 --- a/pages/product/index.vue +++ b/pages/product/index.vue @@ -540,10 +540,10 @@ - 取消 + 取消 - 确认 + 确认 @@ -578,6 +578,8 @@ import dayjs from 'dayjs'; import isBetween from 'dayjs/plugin/isBetween'; dayjs.extend(isBetween); import { filterNumberInput } from '@/utils/util.js'; +import { APIproductqueryShop } from '@/common/api/member.js'; +import { getDistance } from '@/utils/address.js'; //点单智能推荐 function onBuyClick(item) { @@ -1499,10 +1501,10 @@ async function onMessage(Message) { if (Message.operate_type == 'rottable' && Message.status == 1) { console.log('转桌成功了'); - uni.showToast({ - title: '扫码成功,请下单', - icon: 'none' - }); + // uni.showToast({ + // title: '扫码成功,请下单', + // icon: 'none' + // }); orderType.value = 'scan'; uni.cache.set('tableCode', Message.data.new_table_code); @@ -1511,7 +1513,14 @@ async function onMessage(Message) { showTableInfoPeopleNumPopup.value = false; } - websocketsendMessage(options.initMessage); + const data = { + type: 'shopping', + operate_type: 'init', + table_code: uni.cache.get('tableCode'), + shop_id: uni.cache.get('shopId') + }; + + useSocket.sendMessage(data); } // 清空购物车 @@ -1912,6 +1921,7 @@ const orderType = ref('scan'); // 台桌信息 const showTableInfoPeopleNumPopup = ref(false); const tableInfo = ref(''); +const tableShopInfo = ref(uni.cache.get('shopInfo')); // 选择的人数 const tableInfoPeopleActive = ref(-1); @@ -1940,29 +1950,73 @@ function closeTableInfoPeopleNum() { // 确认选择人数 function tableInfoPeopleNumConfirm() { - uni.cache.set('dinersNum', tableInfoPeopleNum.value); - startUseTable(); + if (tableInfoPeopleNum.value > 0) { + uni.cache.set('dinersNum', tableInfoPeopleNum.value); + startUseTable(); + } else { + uni.showToast({ + title: '请选择就餐人数', + icon: 'none' + }); + } } // 开始换桌 function startUseTable() { - const shopInfo = uni.cache.get('shopInfo'); + tableShopInfo.value = uni.cache.get('shopInfo'); const oldTableCode = uni.cache.get('tableCode'); const cartIds = cartStore.carts.map((item) => item.id); const data = { - type: 'onboc', + type: 'shopping', operate_type: 'rottable', - account: shopInfo.phone, + account: tableShopInfo.value.phone, table_code: oldTableCode, - new_table_code: tableInfo.value.tableCode, + new_table_code: uni.cache.get('shopTable').tableCode, cart_id: cartIds, - shop_id: shopInfo.id + shop_id: tableShopInfo.value.id }; websocketsendMessage(data); } +//计算距离判断是否可以点餐 +async function computedDistance(shopInfo) { + return new Promise((resolve, reject) => { + console.log('店铺经纬度', shopInfo.lat, shopInfo.lng); + console.log('用户经纬度', userStore.location.latitude, userStore.location.longitude); + + const juli = getDistance(userStore.location.latitude, userStore.location.longitude, shopInfo.lat, shopInfo.lng); + const orderFenceDistance = ((shopInfo.orderFenceDistance || 2000) / 2000).toFixed(2); + + console.log('距离', juli); + + if (shopInfo.isOrderFence && juli > orderFenceDistance) { + uni.showModal({ + title: '提示', + confirmText: '重新定位', + content: '抱歉,您当前距离店铺过远,为保障您的用餐体验,请您到店后或在门店附近再下单。若您已在店铺附近,可尝试重新定位', + success: async (res) => { + if (res.confirm) { + console.log('用户点击了确认'); + await userStore.getLocation(); + // computedDistance(); + uni.showToast({ + title: '定位成功,请重新扫码', + icon: 'none' + }); + } else if (res.cancel) { + console.log('用户点击了取消'); + } + } + }); + reject(); + return; + } + resolve(juli); + }); +} + // 预点单扫码下单 function beforehandHandle() { uni.scanCode({ @@ -1970,12 +2024,38 @@ function beforehandHandle() { try { const newTableCode = userStore.getQueryString(res.result, 'code'); - if (shopInfo.isTableFee) { - startUseTable(); + const shopInfoRes = await APIproductqueryShop({ + tableCode: newTableCode + }); + + console.log('shopInfoRes===', shopInfoRes); + + await computedDistance(shopInfoRes.shopInfo); + + if (shopInfoRes.shopInfo.id !== tableShopInfo.value.id) { + uni.showModal({ + title: '注意', + content: '扫码店铺与当前店铺不一致,请重新加载页面', + showCancel: false, + success: async (res) => { + uni.cache.set('tableCode', newTableCode); + await userStore.actionsproductqueryShop(newTableCode); + await userStore.actionsproductqueryProduct(); + useSocket.closeSocket(); + userStore.jumpToOrderPage(); + } + }); } else { await userStore.actionsproductqueryShop(newTableCode); - tableInfo.value = uni.cache.get('shopTable'); - showTableInfoPeopleNumPopup.value = true; + await userStore.actionsproductqueryProduct(); + if (shopInfoRes.shopInfo.isTableFee === 1) { + // 免桌位费,直接换桌 + startUseTable(); + } else { + // 不免桌位费,显示选择人数 + tableInfo.value = uni.cache.get('shopTable'); + showTableInfoPeopleNumPopup.value = true; + } } } catch (error) { console.log(error);