This commit is contained in:
2025-12-04 17:15:01 +08:00
2 changed files with 100 additions and 18 deletions

View File

@@ -80,6 +80,7 @@ const scanCodehandle = (i) => {
// 预点单 // 预点单
function beforehandOrderHandle() { function beforehandOrderHandle() {
popupShow.value = false;
let shopUserInfo = uni.cache.get('shopUserInfo'); let shopUserInfo = uni.cache.get('shopUserInfo');
uni.cache.set('dinersNum', 1); uni.cache.set('dinersNum', 1);
uni.cache.set('tableCode', shopUserInfo.id); uni.cache.set('tableCode', shopUserInfo.id);
@@ -90,6 +91,7 @@ function beforehandOrderHandle() {
// 扫码点餐 // 扫码点餐
async function scanOrderHandle() { async function scanOrderHandle() {
popupShow.value = false;
const store = productStore(); const store = productStore();
await store.scanCodeactions(); await store.scanCodeactions();
} }

View File

@@ -540,10 +540,10 @@
</view> </view>
<view class="sn-footer-wrap"> <view class="sn-footer-wrap">
<view class="btn"> <view class="btn">
<u-button plain shape="circle" @click="closeTableInfoPeopleNum">取消</u-button> <u-button plain shape="circle" size="large" @click="closeTableInfoPeopleNum">取消</u-button>
</view> </view>
<view class="btn"> <view class="btn">
<u-button type="primary" shape="circle" @click="tableInfoPeopleNumConfirm">确认</u-button> <u-button type="primary" size="large" shape="circle" @click="tableInfoPeopleNumConfirm">确认</u-button>
</view> </view>
</view> </view>
</view> </view>
@@ -578,6 +578,8 @@ import dayjs from 'dayjs';
import isBetween from 'dayjs/plugin/isBetween'; import isBetween from 'dayjs/plugin/isBetween';
dayjs.extend(isBetween); dayjs.extend(isBetween);
import { filterNumberInput } from '@/utils/util.js'; import { filterNumberInput } from '@/utils/util.js';
import { APIproductqueryShop } from '@/common/api/member.js';
import { getDistance } from '@/utils/address.js';
//点单智能推荐 //点单智能推荐
function onBuyClick(item) { function onBuyClick(item) {
@@ -1499,10 +1501,10 @@ async function onMessage(Message) {
if (Message.operate_type == 'rottable' && Message.status == 1) { if (Message.operate_type == 'rottable' && Message.status == 1) {
console.log('转桌成功了'); console.log('转桌成功了');
uni.showToast({ // uni.showToast({
title: '扫码成功,请下单', // title: '扫码成功,请下单',
icon: 'none' // icon: 'none'
}); // });
orderType.value = 'scan'; orderType.value = 'scan';
uni.cache.set('tableCode', Message.data.new_table_code); uni.cache.set('tableCode', Message.data.new_table_code);
@@ -1511,7 +1513,14 @@ async function onMessage(Message) {
showTableInfoPeopleNumPopup.value = false; 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 showTableInfoPeopleNumPopup = ref(false);
const tableInfo = ref(''); const tableInfo = ref('');
const tableShopInfo = ref(uni.cache.get('shopInfo'));
// 选择的人数 // 选择的人数
const tableInfoPeopleActive = ref(-1); const tableInfoPeopleActive = ref(-1);
@@ -1940,29 +1950,73 @@ function closeTableInfoPeopleNum() {
// 确认选择人数 // 确认选择人数
function tableInfoPeopleNumConfirm() { function tableInfoPeopleNumConfirm() {
uni.cache.set('dinersNum', tableInfoPeopleNum.value); if (tableInfoPeopleNum.value > 0) {
startUseTable(); uni.cache.set('dinersNum', tableInfoPeopleNum.value);
startUseTable();
} else {
uni.showToast({
title: '请选择就餐人数',
icon: 'none'
});
}
} }
// 开始换桌 // 开始换桌
function startUseTable() { function startUseTable() {
const shopInfo = uni.cache.get('shopInfo'); tableShopInfo.value = uni.cache.get('shopInfo');
const oldTableCode = uni.cache.get('tableCode'); const oldTableCode = uni.cache.get('tableCode');
const cartIds = cartStore.carts.map((item) => item.id); const cartIds = cartStore.carts.map((item) => item.id);
const data = { const data = {
type: 'onboc', type: 'shopping',
operate_type: 'rottable', operate_type: 'rottable',
account: shopInfo.phone, account: tableShopInfo.value.phone,
table_code: oldTableCode, table_code: oldTableCode,
new_table_code: tableInfo.value.tableCode, new_table_code: uni.cache.get('shopTable').tableCode,
cart_id: cartIds, cart_id: cartIds,
shop_id: shopInfo.id shop_id: tableShopInfo.value.id
}; };
websocketsendMessage(data); 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() { function beforehandHandle() {
uni.scanCode({ uni.scanCode({
@@ -1970,12 +2024,38 @@ function beforehandHandle() {
try { try {
const newTableCode = userStore.getQueryString(res.result, 'code'); const newTableCode = userStore.getQueryString(res.result, 'code');
if (shopInfo.isTableFee) { const shopInfoRes = await APIproductqueryShop({
startUseTable(); 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 { } else {
await userStore.actionsproductqueryShop(newTableCode); await userStore.actionsproductqueryShop(newTableCode);
tableInfo.value = uni.cache.get('shopTable'); await userStore.actionsproductqueryProduct();
showTableInfoPeopleNumPopup.value = true; if (shopInfoRes.shopInfo.isTableFee === 1) {
// 免桌位费,直接换桌
startUseTable();
} else {
// 不免桌位费,显示选择人数
tableInfo.value = uni.cache.get('shopTable');
showTableInfoPeopleNumPopup.value = true;
}
} }
} catch (error) { } catch (error) {
console.log(error); console.log(error);