新增预点单功能
This commit is contained in:
108
pages/index/components/pageLoading.vue
Normal file
108
pages/index/components/pageLoading.vue
Normal file
@@ -0,0 +1,108 @@
|
||||
<template>
|
||||
<view class="loading-page">
|
||||
<view class="loader"></view>
|
||||
<text class="text">加载中...</text>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup></script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.loading-page {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
background-color: rgba(255, 255, 255, 0.8);
|
||||
backdrop-filter: blur(10px);
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 999;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding-top: 10vh;
|
||||
--color: #111;
|
||||
.text {
|
||||
font-size: 24upx;
|
||||
color: var(--color);
|
||||
}
|
||||
.loader {
|
||||
width: 40px;
|
||||
height: 20px;
|
||||
--c: no-repeat radial-gradient(farthest-side, var(--color) 93%, var(--color));
|
||||
background: var(--c) 0 0, var(--c) 50% 0;
|
||||
background-size: 8px 8px;
|
||||
position: relative;
|
||||
clip-path: inset(-200% -100% 0 0);
|
||||
animation: l6-0 1.5s linear infinite;
|
||||
}
|
||||
.loader:before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 8px;
|
||||
height: 12px;
|
||||
background: var(--color);
|
||||
left: -16px;
|
||||
top: 0;
|
||||
animation: l6-1 1.5s linear infinite, l6-2 0.5s cubic-bezier(0, 200, 0.8, 200) infinite;
|
||||
}
|
||||
.loader:after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 0 0 auto auto;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--color);
|
||||
animation: l6-3 1.5s linear infinite;
|
||||
}
|
||||
@keyframes l6-0 {
|
||||
0%,
|
||||
30% {
|
||||
background-position: 0 0, 50% 0;
|
||||
}
|
||||
33% {
|
||||
background-position: 0 100%, 50% 0;
|
||||
}
|
||||
41%,
|
||||
63% {
|
||||
background-position: 0 0, 50% 0;
|
||||
}
|
||||
66% {
|
||||
background-position: 0 0, 50% 100%;
|
||||
}
|
||||
74%,
|
||||
100% {
|
||||
background-position: 0 0, 50% 0;
|
||||
}
|
||||
}
|
||||
@keyframes l6-1 {
|
||||
90% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
95% {
|
||||
transform: translateY(15px);
|
||||
}
|
||||
100% {
|
||||
transform: translateY(15px);
|
||||
left: calc(100% - 8px);
|
||||
}
|
||||
}
|
||||
@keyframes l6-2 {
|
||||
100% {
|
||||
top: -0.1px;
|
||||
}
|
||||
}
|
||||
@keyframes l6-3 {
|
||||
0%,
|
||||
80%,
|
||||
100% {
|
||||
transform: translate(0);
|
||||
}
|
||||
90% {
|
||||
transform: translate(26px);
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -127,6 +127,8 @@
|
||||
</view>
|
||||
<indexs ref="indexsRef" v-if="showindex == 'shopIndex'" :shopExtend="orderVIP.shopExtendList"></indexs>
|
||||
<!-- <CouponModal></CouponModal> -->
|
||||
<!-- 页面加载动画 -->
|
||||
<pageLoading v-if="showPageLoading" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -136,6 +138,7 @@ import { ref, computed, onMounted, reactive, onBeforeUnmount, watch, getCurrentI
|
||||
import { onLoad, onReady, onShow, onReachBottom, onPageScroll } from '@dcloudio/uni-app';
|
||||
// 获取全局属性
|
||||
const { proxy } = getCurrentInstance();
|
||||
import pageLoading from './components/pageLoading.vue';
|
||||
import swipers from './components/swiper.vue'; //引入轮播
|
||||
import advertisement from './components/advertisement.vue'; //广告
|
||||
import diamond from './components/diamond.vue'; //金刚区
|
||||
@@ -194,7 +197,7 @@ const hometop = async () => {
|
||||
const query = uni.createSelectorQuery().select('#fourcontent');
|
||||
query
|
||||
.boundingClientRect((rect) => {
|
||||
if(rect){
|
||||
if (rect) {
|
||||
elementTop.value = rect.top - store.height;
|
||||
}
|
||||
})
|
||||
@@ -326,16 +329,13 @@ const indexsRef = ref(null);
|
||||
|
||||
onShow(async () => {
|
||||
try {
|
||||
await storeuser.getLocation()
|
||||
await storeuser.getLocation();
|
||||
proxy.$isResolve();
|
||||
const shopId=uni.cache.get('shopId')
|
||||
if(shopId){
|
||||
const shopId = uni.cache.get('shopId');
|
||||
if (shopId) {
|
||||
indexsRef.value.getVipConfig();
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
} catch (error) {}
|
||||
await proxy.$onLaunched;
|
||||
if (uni.cache.get('shopId')) {
|
||||
showindex.value = 'shopIndex';
|
||||
@@ -349,7 +349,14 @@ onShow(async () => {
|
||||
// 获取初始定位高度
|
||||
}
|
||||
});
|
||||
onMounted(async () => {});
|
||||
|
||||
const showPageLoading = ref(true);
|
||||
|
||||
onMounted(async () => {
|
||||
setTimeout(() => {
|
||||
showPageLoading.value = false;
|
||||
}, 800);
|
||||
});
|
||||
|
||||
onReachBottom(() => {
|
||||
onLoadhome();
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
<!-- <view class="contentboxitemright_item flex-between"
|
||||
@click="memberindex('user/member/index')"
|
||||
> -->
|
||||
|
||||
<view class="contentboxitemright_item flex-between" @click="toCharge">
|
||||
<image src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/indexs/Xchong.png" mode="aspectFill"></image>
|
||||
<view class="contentboxitemright_itembox flex-colum">
|
||||
@@ -38,6 +37,24 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<u-popup :show="popupShow" :safe-area-inset-bottom="false" mode="center" @close="popupShow = false">
|
||||
<view class="popup-content">
|
||||
<view class="header-wrap">
|
||||
<text class="t">请选择</text>
|
||||
<view class="close" @click="popupShow = false">
|
||||
<u-icon name="close" size="16" color="#666"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
<view class="btn-content">
|
||||
<view class="btn">
|
||||
<u-button color="#E8AD7B" plain="" shape="circle" @click="beforehandOrderHandle">预点单</u-button>
|
||||
</view>
|
||||
<view class="btn">
|
||||
<u-button color="#E8AD7B" shape="circle" @click="scanOrderHandle">扫码点单</u-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</u-popup>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -55,10 +72,27 @@ const props = defineProps({
|
||||
|
||||
import { productStore } from '@/stores/user.js';
|
||||
|
||||
const scanCodehandle = async (i) => {
|
||||
// 显示弹窗
|
||||
const popupShow = ref(false);
|
||||
const scanCodehandle = (i) => {
|
||||
popupShow.value = true;
|
||||
};
|
||||
|
||||
// 预点单
|
||||
function beforehandOrderHandle() {
|
||||
let shopUserInfo = uni.cache.get('shopUserInfo');
|
||||
uni.cache.set('dinersNum', 1);
|
||||
uni.cache.set('tableCode', shopUserInfo.id);
|
||||
uni.navigateTo({
|
||||
url: '/pages/product/index?type=beforehand'
|
||||
});
|
||||
}
|
||||
|
||||
// 扫码点餐
|
||||
async function scanOrderHandle() {
|
||||
const store = productStore();
|
||||
await store.scanCodeactions();
|
||||
};
|
||||
}
|
||||
|
||||
const memberindex = (url) => {
|
||||
uni.pro.navigateTo(url, {
|
||||
@@ -221,4 +255,39 @@ page {
|
||||
}
|
||||
}
|
||||
}
|
||||
.popup-content {
|
||||
width: 90vw;
|
||||
background-color: #fff;
|
||||
border-radius: 8px;
|
||||
.header-wrap {
|
||||
height: 64px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
border-bottom: 1px solid #ececec;
|
||||
padding: 0 28upx;
|
||||
.t {
|
||||
font-size: 32upx;
|
||||
color: #333;
|
||||
}
|
||||
.close {
|
||||
$size: 60upx;
|
||||
width: $size;
|
||||
height: $size;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
.btn-content {
|
||||
height: 86px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 60upx;
|
||||
.btn {
|
||||
width: 248upx;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -914,7 +914,7 @@
|
||||
console.log('init', listinfo);
|
||||
if (options.shopId) {
|
||||
// 每次进来全局更新shopId
|
||||
uni.cache.set('shopId', options.shopId, 30)
|
||||
uni.cache.set('shopId', options.shopId)
|
||||
uni.$on('returnData', handleReturnData);
|
||||
}
|
||||
// * 获取会员信息
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -575,7 +575,7 @@
|
||||
orderId.value = options.orderId
|
||||
if (options.shopId) {
|
||||
// 每次进来全局更新shopId
|
||||
uni.cache.set('shopId', options.shopId, 30)
|
||||
uni.cache.set('shopId', options.shopId)
|
||||
uni.$on('returnData', handleReturnData);
|
||||
}
|
||||
// * 获取会员信息
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -291,7 +291,7 @@
|
||||
dataform.queueId = getApp().globalData.queueId
|
||||
}
|
||||
// #endif
|
||||
uni.cache.set('shopId', dataform.shopId, 30)
|
||||
uni.cache.set('shopId', dataform.shopId)
|
||||
await nextTick()
|
||||
getQueueUpTablList();
|
||||
})
|
||||
|
||||
@@ -343,7 +343,7 @@
|
||||
// #endif
|
||||
|
||||
if (options.shopId) {
|
||||
uni.cache.set('shopId', options.shopId, 30)
|
||||
uni.cache.set('shopId', options.shopId)
|
||||
infoForn.shopId = options.shopId ? options.shopId : uni.cache.get('shopId')
|
||||
}
|
||||
asyncshopUserInfo()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
855
stores/user.js
855
stores/user.js
@@ -1,432 +1,461 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { APIuserlogin, APIuser } from "@/common/api/api.js";
|
||||
import {
|
||||
APIproductqueryShop,
|
||||
APIusershopInfodetail,
|
||||
APIshopUserInfo,
|
||||
defineStore
|
||||
} from "pinia";
|
||||
import {
|
||||
ref
|
||||
} from "vue";
|
||||
import {
|
||||
APIuserlogin,
|
||||
APIuser
|
||||
} from "@/common/api/api.js";
|
||||
import {
|
||||
APIproductqueryShop,
|
||||
APIusershopInfodetail,
|
||||
APIshopUserInfo,
|
||||
} from "@/common/api/member.js";
|
||||
import { getDistance } from "@/utils/address.js";
|
||||
import { APIgeocodelocation } from "@/common/api/api.js";
|
||||
import {
|
||||
getDistance
|
||||
} from "@/utils/address.js";
|
||||
import {
|
||||
APIgeocodelocation
|
||||
} from "@/common/api/api.js";
|
||||
|
||||
export const Storelogin = defineStore("login", {
|
||||
state: () => ({
|
||||
token: "",
|
||||
miniAppOpenId: "",
|
||||
userInfo: "",
|
||||
shopInfo: {},
|
||||
}),
|
||||
actions: {
|
||||
async getShopInfo(shopId) {
|
||||
const shopRes = await APIusershopInfodetail({
|
||||
shopId,
|
||||
});
|
||||
console.log(shopRes);
|
||||
},
|
||||
actionslogin() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.login({
|
||||
provider: "weixin",
|
||||
success: (data) => {
|
||||
// 微信小程序环境
|
||||
uni.getUserInfo({
|
||||
provider: "weixin",
|
||||
success: async (infoRes) => {
|
||||
let res = await APIuserlogin({
|
||||
code: data.code, //临时登录凭证
|
||||
rawData: infoRes.rawData,
|
||||
source: "wechat",
|
||||
});
|
||||
if (res) {
|
||||
this.token = res.token;
|
||||
this.miniAppOpenId = res.userInfo.miniAppOpenId;
|
||||
this.userInfo = res.userInfo;
|
||||
uni.cache.set("token", res.token);
|
||||
uni.cache.set("userInfo", res.userInfo);
|
||||
uni.cache.set("followIndex", res.followIndex || "");
|
||||
}
|
||||
resolve(true);
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(false);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
my.getAuthCode({
|
||||
scopes: "auth_base",
|
||||
success: async (data) => {
|
||||
// 支付宝小程序环境
|
||||
// my.getAuthUserInfo({
|
||||
// success: async (infoRes) => {
|
||||
let res = await APIuserlogin({
|
||||
code: data.authCode, //临时登录凭证
|
||||
// rawData: JSON.stringify(infoRes),
|
||||
source: "alipay",
|
||||
});
|
||||
if (res) {
|
||||
this.token = res.token;
|
||||
this.miniAppOpenId = res.userInfo.miniAppOpenId;
|
||||
this.userInfo = res.userInfo;
|
||||
uni.cache.set("token", res.token);
|
||||
uni.cache.set("openId", res.userInfo.alipayOpenId);
|
||||
uni.cache.set("userInfo", res.userInfo);
|
||||
resolve(true);
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
reject(false);
|
||||
},
|
||||
});
|
||||
// #endif
|
||||
});
|
||||
},
|
||||
},
|
||||
state: () => ({
|
||||
token: "",
|
||||
miniAppOpenId: "",
|
||||
userInfo: "",
|
||||
shopInfo: {},
|
||||
}),
|
||||
actions: {
|
||||
async getShopInfo(shopId) {
|
||||
const shopRes = await APIusershopInfodetail({
|
||||
shopId,
|
||||
});
|
||||
console.log(shopRes);
|
||||
},
|
||||
actionslogin() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.login({
|
||||
provider: "weixin",
|
||||
success: (data) => {
|
||||
// 微信小程序环境
|
||||
uni.getUserInfo({
|
||||
provider: "weixin",
|
||||
success: async (infoRes) => {
|
||||
let res = await APIuserlogin({
|
||||
code: data.code, //临时登录凭证
|
||||
rawData: infoRes.rawData,
|
||||
source: "wechat",
|
||||
});
|
||||
if (res) {
|
||||
this.token = res.token;
|
||||
this.miniAppOpenId = res.userInfo
|
||||
.miniAppOpenId;
|
||||
this.userInfo = res.userInfo;
|
||||
uni.cache.set("token", res.token);
|
||||
uni.cache.set("userInfo", res.userInfo);
|
||||
uni.cache.set("followIndex", res
|
||||
.followIndex || "");
|
||||
}
|
||||
resolve(true);
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(false);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
my.getAuthCode({
|
||||
scopes: "auth_base",
|
||||
success: async (data) => {
|
||||
// 支付宝小程序环境
|
||||
// my.getAuthUserInfo({
|
||||
// success: async (infoRes) => {
|
||||
let res = await APIuserlogin({
|
||||
code: data.authCode, //临时登录凭证
|
||||
// rawData: JSON.stringify(infoRes),
|
||||
source: "alipay",
|
||||
});
|
||||
if (res) {
|
||||
this.token = res.token;
|
||||
this.miniAppOpenId = res.userInfo.miniAppOpenId;
|
||||
this.userInfo = res.userInfo;
|
||||
uni.cache.set("token", res.token);
|
||||
uni.cache.set("openId", res.userInfo.alipayOpenId);
|
||||
uni.cache.set("userInfo", res.userInfo);
|
||||
resolve(true);
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
reject(false);
|
||||
},
|
||||
});
|
||||
// #endif
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const productStore = defineStore("product", {
|
||||
state: () => ({
|
||||
location: {
|
||||
latitude: "",
|
||||
longitude: "",
|
||||
},
|
||||
shopInfo: {
|
||||
shopId: "",
|
||||
isOrderFence: 0,
|
||||
},
|
||||
}),
|
||||
actions: {
|
||||
getLocation() {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log("获取经纬度");
|
||||
uni.getLocation({
|
||||
type: "wgs84",
|
||||
altitude: true,
|
||||
isHighAccuracy: true,
|
||||
success: (res) => {
|
||||
console.log("获取经纬度成功", res);
|
||||
state: () => ({
|
||||
location: {
|
||||
latitude: "",
|
||||
longitude: "",
|
||||
},
|
||||
shopInfo: {
|
||||
shopId: "",
|
||||
isOrderFence: 0,
|
||||
},
|
||||
}),
|
||||
actions: {
|
||||
getLocation() {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log("获取经纬度");
|
||||
uni.getLocation({
|
||||
type: "wgs84",
|
||||
altitude: true,
|
||||
isHighAccuracy: true,
|
||||
success: (res) => {
|
||||
console.log("获取经纬度成功", res);
|
||||
|
||||
this.location = res;
|
||||
this.APIgeocodelocation();
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error("获取经纬度失败", err);
|
||||
reject(err);
|
||||
},
|
||||
});
|
||||
});
|
||||
},
|
||||
async APIgeocodelocation() {
|
||||
let successres = await APIgeocodelocation({
|
||||
lng: this.location.longitude,
|
||||
lat: this.location.latitude,
|
||||
});
|
||||
if (successres) {
|
||||
let datastorage = {
|
||||
country: successres.addressComponent.country, // "中国"
|
||||
province: successres.addressComponent.province, //province: "陕西省"
|
||||
address: successres.addressComponent.city, //district: "西安市"
|
||||
district: successres.addressComponent.district, //district: "未央区"
|
||||
lng: this.location.longitude,
|
||||
lat: this.location.latitude,
|
||||
};
|
||||
uni.cache.set("getLocationstorage", datastorage);
|
||||
}
|
||||
},
|
||||
getQueryString(url, name) {
|
||||
//解码
|
||||
var reg = new RegExp("(^|&|/?)" + name + "=([^&|/?]*)(&|/?|$)", "i");
|
||||
var r = url.substr(1).match(reg);
|
||||
if (r != null) {
|
||||
return r[2];
|
||||
}
|
||||
return null;
|
||||
},
|
||||
this.location = res;
|
||||
this.APIgeocodelocation();
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error("获取经纬度失败", err);
|
||||
reject(err);
|
||||
},
|
||||
});
|
||||
});
|
||||
},
|
||||
async APIgeocodelocation() {
|
||||
let successres = await APIgeocodelocation({
|
||||
lng: this.location.longitude,
|
||||
lat: this.location.latitude,
|
||||
});
|
||||
if (successres) {
|
||||
let datastorage = {
|
||||
country: successres.addressComponent.country, // "中国"
|
||||
province: successres.addressComponent.province, //province: "陕西省"
|
||||
address: successres.addressComponent.city, //district: "西安市"
|
||||
district: successres.addressComponent.district, //district: "未央区"
|
||||
lng: this.location.longitude,
|
||||
lat: this.location.latitude,
|
||||
};
|
||||
uni.cache.set("getLocationstorage", datastorage);
|
||||
}
|
||||
},
|
||||
getQueryString(url, name) {
|
||||
//解码
|
||||
var reg = new RegExp("(^|&|/?)" + name + "=([^&|/?]*)(&|/?|$)", "i");
|
||||
var r = url.substr(1).match(reg);
|
||||
if (r != null) {
|
||||
return r[2];
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* 扫码请求
|
||||
* @param {*} q
|
||||
* @returns
|
||||
*/
|
||||
async scanCodeactions(q) {
|
||||
console.log("扫码内容", q);
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (q) {
|
||||
console.log(q);
|
||||
let tableCode = "";
|
||||
// #ifdef MP-WEIXIN
|
||||
tableCode = this.getQueryString(decodeURIComponent(q), "code");
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
tableCode = q;
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
tableCode = q.tableCode;
|
||||
// #endif
|
||||
console.log(tableCode);
|
||||
// 储存卓玛
|
||||
uni.cache.set("tableCode", tableCode);
|
||||
if (tableCode) {
|
||||
console.log("台桌码", uni.cache.get("tableCode"));
|
||||
let data = await this.actionsproductqueryShop(tableCode);
|
||||
/**
|
||||
* 扫码请求
|
||||
* @param {*} q
|
||||
* @returns
|
||||
*/
|
||||
async scanCodeactions(q) {
|
||||
console.log("扫码内容", q);
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (q) {
|
||||
console.log(q);
|
||||
let tableCode = "";
|
||||
// #ifdef MP-WEIXIN
|
||||
tableCode = this.getQueryString(decodeURIComponent(q), "code");
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
tableCode = q;
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
tableCode = q.tableCode;
|
||||
// #endif
|
||||
console.log(tableCode);
|
||||
// 储存卓玛
|
||||
uni.cache.set("tableCode", tableCode);
|
||||
if (tableCode) {
|
||||
console.log("台桌码", uni.cache.get("tableCode"));
|
||||
let data = await this.actionsproductqueryShop(tableCode);
|
||||
|
||||
console.log("data", data);
|
||||
// -4请求登录
|
||||
if (data.code == "500") {
|
||||
if (await this.actionslogin()) {
|
||||
// 成功 接着在调用
|
||||
await this.actionsproductqueryShop();
|
||||
}
|
||||
}
|
||||
console.log("data", data);
|
||||
// -4请求登录
|
||||
if (data.code == "500") {
|
||||
if (await this.actionslogin()) {
|
||||
// 成功 接着在调用
|
||||
await this.actionsproductqueryShop();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.shopInfo.isOrderFence == 0) {
|
||||
this.jumpToOrderPage();
|
||||
return;
|
||||
}
|
||||
const canGetLocation = await this.openLocationAuth();
|
||||
if (canGetLocation) {
|
||||
const canOrder = await this.computedDistance();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// #ifdef APP || MP-WEIXIN || MP-ALIPAY
|
||||
uni.scanCode({
|
||||
success: async (res) => {
|
||||
let tableCode = this.getQueryString(
|
||||
decodeURIComponent(res.result),
|
||||
"code"
|
||||
);
|
||||
// 储存卓玛
|
||||
uni.cache.set("tableCode", tableCode);
|
||||
if (tableCode) {
|
||||
let data = await this.actionsproductqueryShop();
|
||||
if (!data) {
|
||||
uni.showToast({
|
||||
title: "店铺已过期或其他问题,请联系商家",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
// -4请求登录
|
||||
const store = Storelogin();
|
||||
if (data.code == "-4") {
|
||||
if (await store.actionslogin()) {
|
||||
// 成功 接着在调用
|
||||
await this.actionsproductqueryShop();
|
||||
}
|
||||
}
|
||||
if (this.shopInfo.isOrderFence == 0) {
|
||||
this.jumpToOrderPage();
|
||||
return;
|
||||
}
|
||||
const canGetLocation = await this.openLocationAuth();
|
||||
if (canGetLocation) {
|
||||
const canOrder = await this.computedDistance();
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log(res);
|
||||
},
|
||||
});
|
||||
// #endif
|
||||
}
|
||||
});
|
||||
},
|
||||
async openLocationAuth() {
|
||||
try {
|
||||
// 1. 检查当前位置授权状态
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.getSetting({
|
||||
success: (settingRes) => {
|
||||
if (settingRes.authSetting["scope.userLocation"]) {
|
||||
// 2. 已授权:直接获取位置
|
||||
resolve(true);
|
||||
} else if (
|
||||
settingRes.authSetting["scope.userLocation"] === undefined
|
||||
) {
|
||||
// 3. 未请求过授权:发起授权请求
|
||||
uni
|
||||
.authorize({ scope: "scope.userLocation" })
|
||||
.then((authRes) => {
|
||||
if (authRes.errMsg === "authorize:ok") {
|
||||
// 授权成功后获取位置
|
||||
resolve(true);
|
||||
} else {
|
||||
reject(false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 4. 已拒绝授权:提示用户去设置页开启
|
||||
uni.showModal({
|
||||
title: "开启定位",
|
||||
content: "请允许“零点八零”使用您的位置,方便您进入店铺点餐",
|
||||
confirmText: "开启定位",
|
||||
cancelText: "取消",
|
||||
success: (modalRes) => {
|
||||
if (modalRes.confirm) {
|
||||
// 跳转微信小程序授权设置页
|
||||
uni.openSetting({
|
||||
success: async (openRes) => {
|
||||
// 用户在设置页开启授权后,再次获取位置
|
||||
if (openRes.authSetting["scope.userLocation"]) {
|
||||
resolve(true);
|
||||
} else {
|
||||
reject(false);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err);
|
||||
},
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("位置授权失败:", err);
|
||||
uni.showToast({ title: "授权失败,请稍后重试", icon: "none" });
|
||||
}
|
||||
},
|
||||
//计算距离判断是否可以点餐
|
||||
async computedDistance() {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log("店铺经纬度", this.shopInfo.lat, this.shopInfo.lng);
|
||||
console.log(
|
||||
"用户经纬度",
|
||||
this.location.latitude,
|
||||
this.location.longitude
|
||||
);
|
||||
if (this.shopInfo.isOrderFence == 0) {
|
||||
this.jumpToOrderPage();
|
||||
return;
|
||||
}
|
||||
const canGetLocation = await this.openLocationAuth();
|
||||
if (canGetLocation) {
|
||||
const canOrder = await this.computedDistance();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// #ifdef APP || MP-WEIXIN || MP-ALIPAY
|
||||
uni.scanCode({
|
||||
success: async (res) => {
|
||||
let tableCode = this.getQueryString(
|
||||
decodeURIComponent(res.result),
|
||||
"code"
|
||||
);
|
||||
// 储存卓玛
|
||||
uni.cache.set("tableCode", tableCode);
|
||||
if (tableCode) {
|
||||
let data = await this.actionsproductqueryShop();
|
||||
if (!data) {
|
||||
uni.showToast({
|
||||
title: "店铺已过期或其他问题,请联系商家",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
// -4请求登录
|
||||
const store = Storelogin();
|
||||
if (data.code == "-4") {
|
||||
if (await store.actionslogin()) {
|
||||
// 成功 接着在调用
|
||||
await this.actionsproductqueryShop();
|
||||
}
|
||||
}
|
||||
if (this.shopInfo.isOrderFence == 0) {
|
||||
this.jumpToOrderPage();
|
||||
return;
|
||||
}
|
||||
const canGetLocation = await this
|
||||
.openLocationAuth();
|
||||
if (canGetLocation) {
|
||||
const canOrder = await this.computedDistance();
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log(res);
|
||||
},
|
||||
});
|
||||
// #endif
|
||||
}
|
||||
});
|
||||
},
|
||||
async openLocationAuth() {
|
||||
try {
|
||||
// 1. 检查当前位置授权状态
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.getSetting({
|
||||
success: (settingRes) => {
|
||||
if (settingRes.authSetting["scope.userLocation"]) {
|
||||
// 2. 已授权:直接获取位置
|
||||
resolve(true);
|
||||
} else if (
|
||||
settingRes.authSetting["scope.userLocation"] ===
|
||||
undefined
|
||||
) {
|
||||
// 3. 未请求过授权:发起授权请求
|
||||
uni
|
||||
.authorize({
|
||||
scope: "scope.userLocation"
|
||||
})
|
||||
.then((authRes) => {
|
||||
if (authRes.errMsg === "authorize:ok") {
|
||||
// 授权成功后获取位置
|
||||
resolve(true);
|
||||
} else {
|
||||
reject(false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 4. 已拒绝授权:提示用户去设置页开启
|
||||
uni.showModal({
|
||||
title: "开启定位",
|
||||
content: "请允许“零点八零”使用您的位置,方便您进入店铺点餐",
|
||||
confirmText: "开启定位",
|
||||
cancelText: "取消",
|
||||
success: (modalRes) => {
|
||||
if (modalRes.confirm) {
|
||||
// 跳转微信小程序授权设置页
|
||||
uni.openSetting({
|
||||
success: async (
|
||||
openRes
|
||||
) => {
|
||||
// 用户在设置页开启授权后,再次获取位置
|
||||
if (openRes
|
||||
.authSetting[
|
||||
"scope.userLocation"
|
||||
]) {
|
||||
resolve(
|
||||
true
|
||||
);
|
||||
} else {
|
||||
reject(
|
||||
false
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err);
|
||||
},
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("位置授权失败:", err);
|
||||
uni.showToast({
|
||||
title: "授权失败,请稍后重试",
|
||||
icon: "none"
|
||||
});
|
||||
}
|
||||
},
|
||||
//计算距离判断是否可以点餐
|
||||
async computedDistance() {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log("店铺经纬度", this.shopInfo.lat, this.shopInfo.lng);
|
||||
console.log(
|
||||
"用户经纬度",
|
||||
this.location.latitude,
|
||||
this.location.longitude
|
||||
);
|
||||
|
||||
const juli = getDistance(
|
||||
this.location.latitude,
|
||||
this.location.longitude,
|
||||
this.shopInfo.lat,
|
||||
this.shopInfo.lng
|
||||
);
|
||||
const orderFenceDistance = (
|
||||
(this.shopInfo.orderFenceDistance || 2000) / 2000
|
||||
).toFixed(2);
|
||||
const juli = getDistance(
|
||||
this.location.latitude,
|
||||
this.location.longitude,
|
||||
this.shopInfo.lat,
|
||||
this.shopInfo.lng
|
||||
);
|
||||
const orderFenceDistance = (
|
||||
(this.shopInfo.orderFenceDistance || 2000) / 2000
|
||||
).toFixed(2);
|
||||
|
||||
console.log("距离", juli);
|
||||
console.log("距离", juli);
|
||||
|
||||
if (this.shopInfo.isOrderFence && juli > orderFenceDistance) {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
confirmText: "重新定位",
|
||||
content:
|
||||
"抱歉,您当前距离店铺过远,为保障您的用餐体验,请您到店后或在门店附近再下单。若您已在店铺附近,可尝试重新定位",
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
console.log("用户点击了确认");
|
||||
await this.getLocation();
|
||||
this.computedDistance();
|
||||
} else if (res.cancel) {
|
||||
console.log("用户点击了取消");
|
||||
}
|
||||
},
|
||||
});
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
this.jumpToOrderPage();
|
||||
resolve(juli);
|
||||
});
|
||||
},
|
||||
// 跳转点餐页面
|
||||
jumpToOrderPage() {
|
||||
// 是否免除桌位费 0否1是
|
||||
if (this.shopInfo.isTableFee == 0) {
|
||||
uni.reLaunch({
|
||||
url: "/pages/product/choosetable",
|
||||
});
|
||||
} else {
|
||||
uni.reLaunch({
|
||||
url: "/pages/product/index",
|
||||
});
|
||||
}
|
||||
},
|
||||
if (this.shopInfo.isOrderFence && juli > orderFenceDistance) {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
confirmText: "重新定位",
|
||||
content: "抱歉,您当前距离店铺过远,为保障您的用餐体验,请您到店后或在门店附近再下单。若您已在店铺附近,可尝试重新定位",
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
console.log("用户点击了确认");
|
||||
await this.getLocation();
|
||||
this.computedDistance();
|
||||
} else if (res.cancel) {
|
||||
console.log("用户点击了取消");
|
||||
}
|
||||
},
|
||||
});
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
this.jumpToOrderPage();
|
||||
resolve(juli);
|
||||
});
|
||||
},
|
||||
// 跳转点餐页面
|
||||
jumpToOrderPage() {
|
||||
// 是否免除桌位费 0否1是
|
||||
if (this.shopInfo.isTableFee == 0) {
|
||||
uni.reLaunch({
|
||||
url: "/pages/product/choosetable",
|
||||
});
|
||||
} else {
|
||||
uni.reLaunch({
|
||||
url: "/pages/product/index",
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// /通过桌码获取当前店铺信息
|
||||
actionsproductqueryShop(tableCode) {
|
||||
console.log("台桌码", tableCode);
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// try {
|
||||
try {
|
||||
let res = await APIproductqueryShop({
|
||||
tableCode: tableCode ? tableCode : uni.cache.get("tableCode"),
|
||||
});
|
||||
if (res) {
|
||||
res.shopInfo.isVip = res.vip ? "1" : "0";
|
||||
res.shopTable.shopExtendMap = res.shopExtendMap;
|
||||
this.shopInfo = res.shopInfo;
|
||||
// 店铺信息
|
||||
uni.cache.set("shopTable", res.shopTable);
|
||||
// 台桌信息
|
||||
uni.cache.set("shopInfo", res.shopInfo);
|
||||
uni.cache.set("shopId", res.shopTable.shopId, 30);
|
||||
// /通过桌码获取当前店铺信息
|
||||
actionsproductqueryShop(tableCode) {
|
||||
console.log("台桌码", tableCode);
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// try {
|
||||
try {
|
||||
let res = await APIproductqueryShop({
|
||||
tableCode: tableCode ? tableCode : uni.cache.get("tableCode"),
|
||||
});
|
||||
if (res) {
|
||||
res.shopInfo.isVip = res.vip ? "1" : "0";
|
||||
res.shopTable.shopExtendMap = res.shopExtendMap;
|
||||
this.shopInfo = res.shopInfo;
|
||||
// 店铺信息
|
||||
uni.cache.set("shopTable", res.shopTable);
|
||||
// 台桌信息
|
||||
uni.cache.set("shopInfo", res.shopInfo);
|
||||
// uni.cache.set("shopId", res.shopTable.shopId, 30);
|
||||
uni.cache.set("shopId", res.shopTable.shopId);
|
||||
|
||||
resolve(res);
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: "通过桌码获取当前店铺信息失败",
|
||||
icon: "none",
|
||||
});
|
||||
console.error("通过桌码获取当前店铺信息失败", res);
|
||||
reject();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
reject();
|
||||
//TODO handle the exception
|
||||
}
|
||||
resolve(res);
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: "通过桌码获取当前店铺信息失败",
|
||||
icon: "none",
|
||||
});
|
||||
console.error("通过桌码获取当前店铺信息失败", res);
|
||||
reject();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
reject();
|
||||
//TODO handle the exception
|
||||
}
|
||||
|
||||
// } catch (e) {
|
||||
// reject(false)
|
||||
// }
|
||||
});
|
||||
},
|
||||
// } catch (e) {
|
||||
// reject(false)
|
||||
// }
|
||||
});
|
||||
},
|
||||
|
||||
// 通过shopId 获取店铺会员信息
|
||||
actionsproductqueryProduct() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let res = await APIshopUserInfo();
|
||||
uni.cache.set("shopUserInfo", res);
|
||||
uni.cache.set("orderVIP", res);
|
||||
uni.cache.set("ordershopUserInfo", res.shopInfo);
|
||||
resolve(res);
|
||||
} catch (e) {
|
||||
reject(false);
|
||||
}
|
||||
});
|
||||
},
|
||||
// 通过shopId 获取店铺会员信息
|
||||
actionsproductqueryProduct() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let res = await APIshopUserInfo();
|
||||
uni.cache.set("shopUserInfo", res);
|
||||
uni.cache.set("orderVIP", res);
|
||||
uni.cache.set("ordershopUserInfo", res.shopInfo);
|
||||
resolve(res);
|
||||
} catch (e) {
|
||||
reject(false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 用户信息获取
|
||||
actionsAPIuser() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let res = null;
|
||||
// 获取店铺用户会员信息
|
||||
if (uni.cache.get("shopId")) {
|
||||
res = await this.actionsproductqueryProduct();
|
||||
} else {
|
||||
res = await APIuser();
|
||||
uni.cache.set("userInfo", res);
|
||||
}
|
||||
console.log("actionsAPIuser res", res);
|
||||
resolve(res);
|
||||
} catch (e) {
|
||||
reject(false);
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
// 用户信息获取
|
||||
actionsAPIuser() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let res = null;
|
||||
// 获取店铺用户会员信息
|
||||
if (uni.cache.get("shopId")) {
|
||||
res = await this.actionsproductqueryProduct();
|
||||
} else {
|
||||
res = await APIuser();
|
||||
uni.cache.set("userInfo", res);
|
||||
}
|
||||
console.log("actionsAPIuser res", res);
|
||||
resolve(res);
|
||||
} catch (e) {
|
||||
reject(false);
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user