优化预下单不同店铺扫码逻辑
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -540,10 +540,10 @@
|
||||
</view>
|
||||
<view class="sn-footer-wrap">
|
||||
<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 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>
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user