新增预点单功能
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>
|
</view>
|
||||||
<indexs ref="indexsRef" v-if="showindex == 'shopIndex'" :shopExtend="orderVIP.shopExtendList"></indexs>
|
<indexs ref="indexsRef" v-if="showindex == 'shopIndex'" :shopExtend="orderVIP.shopExtendList"></indexs>
|
||||||
<!-- <CouponModal></CouponModal> -->
|
<!-- <CouponModal></CouponModal> -->
|
||||||
|
<!-- 页面加载动画 -->
|
||||||
|
<pageLoading v-if="showPageLoading" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -136,6 +138,7 @@ import { ref, computed, onMounted, reactive, onBeforeUnmount, watch, getCurrentI
|
|||||||
import { onLoad, onReady, onShow, onReachBottom, onPageScroll } from '@dcloudio/uni-app';
|
import { onLoad, onReady, onShow, onReachBottom, onPageScroll } from '@dcloudio/uni-app';
|
||||||
// 获取全局属性
|
// 获取全局属性
|
||||||
const { proxy } = getCurrentInstance();
|
const { proxy } = getCurrentInstance();
|
||||||
|
import pageLoading from './components/pageLoading.vue';
|
||||||
import swipers from './components/swiper.vue'; //引入轮播
|
import swipers from './components/swiper.vue'; //引入轮播
|
||||||
import advertisement from './components/advertisement.vue'; //广告
|
import advertisement from './components/advertisement.vue'; //广告
|
||||||
import diamond from './components/diamond.vue'; //金刚区
|
import diamond from './components/diamond.vue'; //金刚区
|
||||||
@@ -194,7 +197,7 @@ const hometop = async () => {
|
|||||||
const query = uni.createSelectorQuery().select('#fourcontent');
|
const query = uni.createSelectorQuery().select('#fourcontent');
|
||||||
query
|
query
|
||||||
.boundingClientRect((rect) => {
|
.boundingClientRect((rect) => {
|
||||||
if(rect){
|
if (rect) {
|
||||||
elementTop.value = rect.top - store.height;
|
elementTop.value = rect.top - store.height;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -326,16 +329,13 @@ const indexsRef = ref(null);
|
|||||||
|
|
||||||
onShow(async () => {
|
onShow(async () => {
|
||||||
try {
|
try {
|
||||||
await storeuser.getLocation()
|
await storeuser.getLocation();
|
||||||
proxy.$isResolve();
|
proxy.$isResolve();
|
||||||
const shopId=uni.cache.get('shopId')
|
const shopId = uni.cache.get('shopId');
|
||||||
if(shopId){
|
if (shopId) {
|
||||||
indexsRef.value.getVipConfig();
|
indexsRef.value.getVipConfig();
|
||||||
}
|
}
|
||||||
|
} catch (error) {}
|
||||||
} catch (error) {
|
|
||||||
|
|
||||||
}
|
|
||||||
await proxy.$onLaunched;
|
await proxy.$onLaunched;
|
||||||
if (uni.cache.get('shopId')) {
|
if (uni.cache.get('shopId')) {
|
||||||
showindex.value = 'shopIndex';
|
showindex.value = 'shopIndex';
|
||||||
@@ -349,7 +349,14 @@ onShow(async () => {
|
|||||||
// 获取初始定位高度
|
// 获取初始定位高度
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
onMounted(async () => {});
|
|
||||||
|
const showPageLoading = ref(true);
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
showPageLoading.value = false;
|
||||||
|
}, 800);
|
||||||
|
});
|
||||||
|
|
||||||
onReachBottom(() => {
|
onReachBottom(() => {
|
||||||
onLoadhome();
|
onLoadhome();
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
<!-- <view class="contentboxitemright_item flex-between"
|
<!-- <view class="contentboxitemright_item flex-between"
|
||||||
@click="memberindex('user/member/index')"
|
@click="memberindex('user/member/index')"
|
||||||
> -->
|
> -->
|
||||||
|
|
||||||
<view class="contentboxitemright_item flex-between" @click="toCharge">
|
<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>
|
<image src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/indexs/Xchong.png" mode="aspectFill"></image>
|
||||||
<view class="contentboxitemright_itembox flex-colum">
|
<view class="contentboxitemright_itembox flex-colum">
|
||||||
@@ -38,6 +37,24 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</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>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -55,10 +72,27 @@ const props = defineProps({
|
|||||||
|
|
||||||
import { productStore } from '@/stores/user.js';
|
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();
|
const store = productStore();
|
||||||
await store.scanCodeactions();
|
await store.scanCodeactions();
|
||||||
};
|
}
|
||||||
|
|
||||||
const memberindex = (url) => {
|
const memberindex = (url) => {
|
||||||
uni.pro.navigateTo(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>
|
</style>
|
||||||
|
|||||||
@@ -914,7 +914,7 @@
|
|||||||
console.log('init', listinfo);
|
console.log('init', listinfo);
|
||||||
if (options.shopId) {
|
if (options.shopId) {
|
||||||
// 每次进来全局更新shopId
|
// 每次进来全局更新shopId
|
||||||
uni.cache.set('shopId', options.shopId, 30)
|
uni.cache.set('shopId', options.shopId)
|
||||||
uni.$on('returnData', handleReturnData);
|
uni.$on('returnData', handleReturnData);
|
||||||
}
|
}
|
||||||
// * 获取会员信息
|
// * 获取会员信息
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -575,7 +575,7 @@
|
|||||||
orderId.value = options.orderId
|
orderId.value = options.orderId
|
||||||
if (options.shopId) {
|
if (options.shopId) {
|
||||||
// 每次进来全局更新shopId
|
// 每次进来全局更新shopId
|
||||||
uni.cache.set('shopId', options.shopId, 30)
|
uni.cache.set('shopId', options.shopId)
|
||||||
uni.$on('returnData', handleReturnData);
|
uni.$on('returnData', handleReturnData);
|
||||||
}
|
}
|
||||||
// * 获取会员信息
|
// * 获取会员信息
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -291,7 +291,7 @@
|
|||||||
dataform.queueId = getApp().globalData.queueId
|
dataform.queueId = getApp().globalData.queueId
|
||||||
}
|
}
|
||||||
// #endif
|
// #endif
|
||||||
uni.cache.set('shopId', dataform.shopId, 30)
|
uni.cache.set('shopId', dataform.shopId)
|
||||||
await nextTick()
|
await nextTick()
|
||||||
getQueueUpTablList();
|
getQueueUpTablList();
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -343,7 +343,7 @@
|
|||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
if (options.shopId) {
|
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')
|
infoForn.shopId = options.shopId ? options.shopId : uni.cache.get('shopId')
|
||||||
}
|
}
|
||||||
asyncshopUserInfo()
|
asyncshopUserInfo()
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
853
stores/user.js
853
stores/user.js
@@ -1,432 +1,461 @@
|
|||||||
import { defineStore } from "pinia";
|
|
||||||
import { ref } from "vue";
|
|
||||||
import { APIuserlogin, APIuser } from "@/common/api/api.js";
|
|
||||||
import {
|
import {
|
||||||
APIproductqueryShop,
|
defineStore
|
||||||
APIusershopInfodetail,
|
} from "pinia";
|
||||||
APIshopUserInfo,
|
import {
|
||||||
|
ref
|
||||||
|
} from "vue";
|
||||||
|
import {
|
||||||
|
APIuserlogin,
|
||||||
|
APIuser
|
||||||
|
} from "@/common/api/api.js";
|
||||||
|
import {
|
||||||
|
APIproductqueryShop,
|
||||||
|
APIusershopInfodetail,
|
||||||
|
APIshopUserInfo,
|
||||||
} from "@/common/api/member.js";
|
} from "@/common/api/member.js";
|
||||||
import { getDistance } from "@/utils/address.js";
|
import {
|
||||||
import { APIgeocodelocation } from "@/common/api/api.js";
|
getDistance
|
||||||
|
} from "@/utils/address.js";
|
||||||
|
import {
|
||||||
|
APIgeocodelocation
|
||||||
|
} from "@/common/api/api.js";
|
||||||
|
|
||||||
export const Storelogin = defineStore("login", {
|
export const Storelogin = defineStore("login", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
token: "",
|
token: "",
|
||||||
miniAppOpenId: "",
|
miniAppOpenId: "",
|
||||||
userInfo: "",
|
userInfo: "",
|
||||||
shopInfo: {},
|
shopInfo: {},
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
async getShopInfo(shopId) {
|
async getShopInfo(shopId) {
|
||||||
const shopRes = await APIusershopInfodetail({
|
const shopRes = await APIusershopInfodetail({
|
||||||
shopId,
|
shopId,
|
||||||
});
|
});
|
||||||
console.log(shopRes);
|
console.log(shopRes);
|
||||||
},
|
},
|
||||||
actionslogin() {
|
actionslogin() {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
uni.login({
|
uni.login({
|
||||||
provider: "weixin",
|
provider: "weixin",
|
||||||
success: (data) => {
|
success: (data) => {
|
||||||
// 微信小程序环境
|
// 微信小程序环境
|
||||||
uni.getUserInfo({
|
uni.getUserInfo({
|
||||||
provider: "weixin",
|
provider: "weixin",
|
||||||
success: async (infoRes) => {
|
success: async (infoRes) => {
|
||||||
let res = await APIuserlogin({
|
let res = await APIuserlogin({
|
||||||
code: data.code, //临时登录凭证
|
code: data.code, //临时登录凭证
|
||||||
rawData: infoRes.rawData,
|
rawData: infoRes.rawData,
|
||||||
source: "wechat",
|
source: "wechat",
|
||||||
});
|
});
|
||||||
if (res) {
|
if (res) {
|
||||||
this.token = res.token;
|
this.token = res.token;
|
||||||
this.miniAppOpenId = res.userInfo.miniAppOpenId;
|
this.miniAppOpenId = res.userInfo
|
||||||
this.userInfo = res.userInfo;
|
.miniAppOpenId;
|
||||||
uni.cache.set("token", res.token);
|
this.userInfo = res.userInfo;
|
||||||
uni.cache.set("userInfo", res.userInfo);
|
uni.cache.set("token", res.token);
|
||||||
uni.cache.set("followIndex", res.followIndex || "");
|
uni.cache.set("userInfo", res.userInfo);
|
||||||
}
|
uni.cache.set("followIndex", res
|
||||||
resolve(true);
|
.followIndex || "");
|
||||||
},
|
}
|
||||||
fail: (err) => {
|
resolve(true);
|
||||||
reject(false);
|
},
|
||||||
},
|
fail: (err) => {
|
||||||
});
|
reject(false);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
// #endif
|
},
|
||||||
// #ifdef MP-ALIPAY
|
});
|
||||||
my.getAuthCode({
|
// #endif
|
||||||
scopes: "auth_base",
|
// #ifdef MP-ALIPAY
|
||||||
success: async (data) => {
|
my.getAuthCode({
|
||||||
// 支付宝小程序环境
|
scopes: "auth_base",
|
||||||
// my.getAuthUserInfo({
|
success: async (data) => {
|
||||||
// success: async (infoRes) => {
|
// 支付宝小程序环境
|
||||||
let res = await APIuserlogin({
|
// my.getAuthUserInfo({
|
||||||
code: data.authCode, //临时登录凭证
|
// success: async (infoRes) => {
|
||||||
// rawData: JSON.stringify(infoRes),
|
let res = await APIuserlogin({
|
||||||
source: "alipay",
|
code: data.authCode, //临时登录凭证
|
||||||
});
|
// rawData: JSON.stringify(infoRes),
|
||||||
if (res) {
|
source: "alipay",
|
||||||
this.token = res.token;
|
});
|
||||||
this.miniAppOpenId = res.userInfo.miniAppOpenId;
|
if (res) {
|
||||||
this.userInfo = res.userInfo;
|
this.token = res.token;
|
||||||
uni.cache.set("token", res.token);
|
this.miniAppOpenId = res.userInfo.miniAppOpenId;
|
||||||
uni.cache.set("openId", res.userInfo.alipayOpenId);
|
this.userInfo = res.userInfo;
|
||||||
uni.cache.set("userInfo", res.userInfo);
|
uni.cache.set("token", res.token);
|
||||||
resolve(true);
|
uni.cache.set("openId", res.userInfo.alipayOpenId);
|
||||||
}
|
uni.cache.set("userInfo", res.userInfo);
|
||||||
},
|
resolve(true);
|
||||||
fail: () => {
|
}
|
||||||
reject(false);
|
},
|
||||||
},
|
fail: () => {
|
||||||
});
|
reject(false);
|
||||||
// #endif
|
},
|
||||||
});
|
});
|
||||||
},
|
// #endif
|
||||||
},
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const productStore = defineStore("product", {
|
export const productStore = defineStore("product", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
location: {
|
location: {
|
||||||
latitude: "",
|
latitude: "",
|
||||||
longitude: "",
|
longitude: "",
|
||||||
},
|
},
|
||||||
shopInfo: {
|
shopInfo: {
|
||||||
shopId: "",
|
shopId: "",
|
||||||
isOrderFence: 0,
|
isOrderFence: 0,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
getLocation() {
|
getLocation() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
console.log("获取经纬度");
|
console.log("获取经纬度");
|
||||||
uni.getLocation({
|
uni.getLocation({
|
||||||
type: "wgs84",
|
type: "wgs84",
|
||||||
altitude: true,
|
altitude: true,
|
||||||
isHighAccuracy: true,
|
isHighAccuracy: true,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log("获取经纬度成功", res);
|
console.log("获取经纬度成功", res);
|
||||||
|
|
||||||
this.location = res;
|
this.location = res;
|
||||||
this.APIgeocodelocation();
|
this.APIgeocodelocation();
|
||||||
resolve(res);
|
resolve(res);
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
console.error("获取经纬度失败", err);
|
console.error("获取经纬度失败", err);
|
||||||
reject(err);
|
reject(err);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async APIgeocodelocation() {
|
async APIgeocodelocation() {
|
||||||
let successres = await APIgeocodelocation({
|
let successres = await APIgeocodelocation({
|
||||||
lng: this.location.longitude,
|
lng: this.location.longitude,
|
||||||
lat: this.location.latitude,
|
lat: this.location.latitude,
|
||||||
});
|
});
|
||||||
if (successres) {
|
if (successres) {
|
||||||
let datastorage = {
|
let datastorage = {
|
||||||
country: successres.addressComponent.country, // "中国"
|
country: successres.addressComponent.country, // "中国"
|
||||||
province: successres.addressComponent.province, //province: "陕西省"
|
province: successres.addressComponent.province, //province: "陕西省"
|
||||||
address: successres.addressComponent.city, //district: "西安市"
|
address: successres.addressComponent.city, //district: "西安市"
|
||||||
district: successres.addressComponent.district, //district: "未央区"
|
district: successres.addressComponent.district, //district: "未央区"
|
||||||
lng: this.location.longitude,
|
lng: this.location.longitude,
|
||||||
lat: this.location.latitude,
|
lat: this.location.latitude,
|
||||||
};
|
};
|
||||||
uni.cache.set("getLocationstorage", datastorage);
|
uni.cache.set("getLocationstorage", datastorage);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getQueryString(url, name) {
|
getQueryString(url, name) {
|
||||||
//解码
|
//解码
|
||||||
var reg = new RegExp("(^|&|/?)" + name + "=([^&|/?]*)(&|/?|$)", "i");
|
var reg = new RegExp("(^|&|/?)" + name + "=([^&|/?]*)(&|/?|$)", "i");
|
||||||
var r = url.substr(1).match(reg);
|
var r = url.substr(1).match(reg);
|
||||||
if (r != null) {
|
if (r != null) {
|
||||||
return r[2];
|
return r[2];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 扫码请求
|
* 扫码请求
|
||||||
* @param {*} q
|
* @param {*} q
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async scanCodeactions(q) {
|
async scanCodeactions(q) {
|
||||||
console.log("扫码内容", q);
|
console.log("扫码内容", q);
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
if (q) {
|
if (q) {
|
||||||
console.log(q);
|
console.log(q);
|
||||||
let tableCode = "";
|
let tableCode = "";
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
tableCode = this.getQueryString(decodeURIComponent(q), "code");
|
tableCode = this.getQueryString(decodeURIComponent(q), "code");
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef MP-ALIPAY
|
// #ifdef MP-ALIPAY
|
||||||
tableCode = q;
|
tableCode = q;
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
tableCode = q.tableCode;
|
tableCode = q.tableCode;
|
||||||
// #endif
|
// #endif
|
||||||
console.log(tableCode);
|
console.log(tableCode);
|
||||||
// 储存卓玛
|
// 储存卓玛
|
||||||
uni.cache.set("tableCode", tableCode);
|
uni.cache.set("tableCode", tableCode);
|
||||||
if (tableCode) {
|
if (tableCode) {
|
||||||
console.log("台桌码", uni.cache.get("tableCode"));
|
console.log("台桌码", uni.cache.get("tableCode"));
|
||||||
let data = await this.actionsproductqueryShop(tableCode);
|
let data = await this.actionsproductqueryShop(tableCode);
|
||||||
|
|
||||||
console.log("data", data);
|
console.log("data", data);
|
||||||
// -4请求登录
|
// -4请求登录
|
||||||
if (data.code == "500") {
|
if (data.code == "500") {
|
||||||
if (await this.actionslogin()) {
|
if (await this.actionslogin()) {
|
||||||
// 成功 接着在调用
|
// 成功 接着在调用
|
||||||
await this.actionsproductqueryShop();
|
await this.actionsproductqueryShop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.shopInfo.isOrderFence == 0) {
|
if (this.shopInfo.isOrderFence == 0) {
|
||||||
this.jumpToOrderPage();
|
this.jumpToOrderPage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const canGetLocation = await this.openLocationAuth();
|
const canGetLocation = await this.openLocationAuth();
|
||||||
if (canGetLocation) {
|
if (canGetLocation) {
|
||||||
const canOrder = await this.computedDistance();
|
const canOrder = await this.computedDistance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// #ifdef APP || MP-WEIXIN || MP-ALIPAY
|
// #ifdef APP || MP-WEIXIN || MP-ALIPAY
|
||||||
uni.scanCode({
|
uni.scanCode({
|
||||||
success: async (res) => {
|
success: async (res) => {
|
||||||
let tableCode = this.getQueryString(
|
let tableCode = this.getQueryString(
|
||||||
decodeURIComponent(res.result),
|
decodeURIComponent(res.result),
|
||||||
"code"
|
"code"
|
||||||
);
|
);
|
||||||
// 储存卓玛
|
// 储存卓玛
|
||||||
uni.cache.set("tableCode", tableCode);
|
uni.cache.set("tableCode", tableCode);
|
||||||
if (tableCode) {
|
if (tableCode) {
|
||||||
let data = await this.actionsproductqueryShop();
|
let data = await this.actionsproductqueryShop();
|
||||||
if (!data) {
|
if (!data) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "店铺已过期或其他问题,请联系商家",
|
title: "店铺已过期或其他问题,请联系商家",
|
||||||
icon: "none",
|
icon: "none",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// -4请求登录
|
// -4请求登录
|
||||||
const store = Storelogin();
|
const store = Storelogin();
|
||||||
if (data.code == "-4") {
|
if (data.code == "-4") {
|
||||||
if (await store.actionslogin()) {
|
if (await store.actionslogin()) {
|
||||||
// 成功 接着在调用
|
// 成功 接着在调用
|
||||||
await this.actionsproductqueryShop();
|
await this.actionsproductqueryShop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.shopInfo.isOrderFence == 0) {
|
if (this.shopInfo.isOrderFence == 0) {
|
||||||
this.jumpToOrderPage();
|
this.jumpToOrderPage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const canGetLocation = await this.openLocationAuth();
|
const canGetLocation = await this
|
||||||
if (canGetLocation) {
|
.openLocationAuth();
|
||||||
const canOrder = await this.computedDistance();
|
if (canGetLocation) {
|
||||||
}
|
const canOrder = await this.computedDistance();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
fail: (res) => {
|
},
|
||||||
console.log(res);
|
fail: (res) => {
|
||||||
},
|
console.log(res);
|
||||||
});
|
},
|
||||||
// #endif
|
});
|
||||||
}
|
// #endif
|
||||||
});
|
}
|
||||||
},
|
});
|
||||||
async openLocationAuth() {
|
},
|
||||||
try {
|
async openLocationAuth() {
|
||||||
// 1. 检查当前位置授权状态
|
try {
|
||||||
return new Promise((resolve, reject) => {
|
// 1. 检查当前位置授权状态
|
||||||
uni.getSetting({
|
return new Promise((resolve, reject) => {
|
||||||
success: (settingRes) => {
|
uni.getSetting({
|
||||||
if (settingRes.authSetting["scope.userLocation"]) {
|
success: (settingRes) => {
|
||||||
// 2. 已授权:直接获取位置
|
if (settingRes.authSetting["scope.userLocation"]) {
|
||||||
resolve(true);
|
// 2. 已授权:直接获取位置
|
||||||
} else if (
|
resolve(true);
|
||||||
settingRes.authSetting["scope.userLocation"] === undefined
|
} else if (
|
||||||
) {
|
settingRes.authSetting["scope.userLocation"] ===
|
||||||
// 3. 未请求过授权:发起授权请求
|
undefined
|
||||||
uni
|
) {
|
||||||
.authorize({ scope: "scope.userLocation" })
|
// 3. 未请求过授权:发起授权请求
|
||||||
.then((authRes) => {
|
uni
|
||||||
if (authRes.errMsg === "authorize:ok") {
|
.authorize({
|
||||||
// 授权成功后获取位置
|
scope: "scope.userLocation"
|
||||||
resolve(true);
|
})
|
||||||
} else {
|
.then((authRes) => {
|
||||||
reject(false);
|
if (authRes.errMsg === "authorize:ok") {
|
||||||
}
|
// 授权成功后获取位置
|
||||||
});
|
resolve(true);
|
||||||
} else {
|
} else {
|
||||||
// 4. 已拒绝授权:提示用户去设置页开启
|
reject(false);
|
||||||
uni.showModal({
|
}
|
||||||
title: "开启定位",
|
});
|
||||||
content: "请允许“零点八零”使用您的位置,方便您进入店铺点餐",
|
} else {
|
||||||
confirmText: "开启定位",
|
// 4. 已拒绝授权:提示用户去设置页开启
|
||||||
cancelText: "取消",
|
uni.showModal({
|
||||||
success: (modalRes) => {
|
title: "开启定位",
|
||||||
if (modalRes.confirm) {
|
content: "请允许“零点八零”使用您的位置,方便您进入店铺点餐",
|
||||||
// 跳转微信小程序授权设置页
|
confirmText: "开启定位",
|
||||||
uni.openSetting({
|
cancelText: "取消",
|
||||||
success: async (openRes) => {
|
success: (modalRes) => {
|
||||||
// 用户在设置页开启授权后,再次获取位置
|
if (modalRes.confirm) {
|
||||||
if (openRes.authSetting["scope.userLocation"]) {
|
// 跳转微信小程序授权设置页
|
||||||
resolve(true);
|
uni.openSetting({
|
||||||
} else {
|
success: async (
|
||||||
reject(false);
|
openRes
|
||||||
}
|
) => {
|
||||||
},
|
// 用户在设置页开启授权后,再次获取位置
|
||||||
});
|
if (openRes
|
||||||
}
|
.authSetting[
|
||||||
},
|
"scope.userLocation"
|
||||||
});
|
]) {
|
||||||
}
|
resolve(
|
||||||
},
|
true
|
||||||
fail: (err) => {
|
);
|
||||||
reject(err);
|
} else {
|
||||||
},
|
reject(
|
||||||
});
|
false
|
||||||
});
|
);
|
||||||
} 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);
|
fail: (err) => {
|
||||||
console.log(
|
reject(err);
|
||||||
"用户经纬度",
|
},
|
||||||
this.location.latitude,
|
});
|
||||||
this.location.longitude
|
});
|
||||||
);
|
} 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(
|
const juli = getDistance(
|
||||||
this.location.latitude,
|
this.location.latitude,
|
||||||
this.location.longitude,
|
this.location.longitude,
|
||||||
this.shopInfo.lat,
|
this.shopInfo.lat,
|
||||||
this.shopInfo.lng
|
this.shopInfo.lng
|
||||||
);
|
);
|
||||||
const orderFenceDistance = (
|
const orderFenceDistance = (
|
||||||
(this.shopInfo.orderFenceDistance || 2000) / 2000
|
(this.shopInfo.orderFenceDistance || 2000) / 2000
|
||||||
).toFixed(2);
|
).toFixed(2);
|
||||||
|
|
||||||
console.log("距离", juli);
|
console.log("距离", juli);
|
||||||
|
|
||||||
if (this.shopInfo.isOrderFence && juli > orderFenceDistance) {
|
if (this.shopInfo.isOrderFence && juli > orderFenceDistance) {
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: "提示",
|
title: "提示",
|
||||||
confirmText: "重新定位",
|
confirmText: "重新定位",
|
||||||
content:
|
content: "抱歉,您当前距离店铺过远,为保障您的用餐体验,请您到店后或在门店附近再下单。若您已在店铺附近,可尝试重新定位",
|
||||||
"抱歉,您当前距离店铺过远,为保障您的用餐体验,请您到店后或在门店附近再下单。若您已在店铺附近,可尝试重新定位",
|
success: async (res) => {
|
||||||
success: async (res) => {
|
if (res.confirm) {
|
||||||
if (res.confirm) {
|
console.log("用户点击了确认");
|
||||||
console.log("用户点击了确认");
|
await this.getLocation();
|
||||||
await this.getLocation();
|
this.computedDistance();
|
||||||
this.computedDistance();
|
} else if (res.cancel) {
|
||||||
} else if (res.cancel) {
|
console.log("用户点击了取消");
|
||||||
console.log("用户点击了取消");
|
}
|
||||||
}
|
},
|
||||||
},
|
});
|
||||||
});
|
reject();
|
||||||
reject();
|
return;
|
||||||
return;
|
}
|
||||||
}
|
this.jumpToOrderPage();
|
||||||
this.jumpToOrderPage();
|
resolve(juli);
|
||||||
resolve(juli);
|
});
|
||||||
});
|
},
|
||||||
},
|
// 跳转点餐页面
|
||||||
// 跳转点餐页面
|
jumpToOrderPage() {
|
||||||
jumpToOrderPage() {
|
// 是否免除桌位费 0否1是
|
||||||
// 是否免除桌位费 0否1是
|
if (this.shopInfo.isTableFee == 0) {
|
||||||
if (this.shopInfo.isTableFee == 0) {
|
uni.reLaunch({
|
||||||
uni.reLaunch({
|
url: "/pages/product/choosetable",
|
||||||
url: "/pages/product/choosetable",
|
});
|
||||||
});
|
} else {
|
||||||
} else {
|
uni.reLaunch({
|
||||||
uni.reLaunch({
|
url: "/pages/product/index",
|
||||||
url: "/pages/product/index",
|
});
|
||||||
});
|
}
|
||||||
}
|
},
|
||||||
},
|
|
||||||
|
|
||||||
// /通过桌码获取当前店铺信息
|
// /通过桌码获取当前店铺信息
|
||||||
actionsproductqueryShop(tableCode) {
|
actionsproductqueryShop(tableCode) {
|
||||||
console.log("台桌码", tableCode);
|
console.log("台桌码", tableCode);
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
// try {
|
// try {
|
||||||
try {
|
try {
|
||||||
let res = await APIproductqueryShop({
|
let res = await APIproductqueryShop({
|
||||||
tableCode: tableCode ? tableCode : uni.cache.get("tableCode"),
|
tableCode: tableCode ? tableCode : uni.cache.get("tableCode"),
|
||||||
});
|
});
|
||||||
if (res) {
|
if (res) {
|
||||||
res.shopInfo.isVip = res.vip ? "1" : "0";
|
res.shopInfo.isVip = res.vip ? "1" : "0";
|
||||||
res.shopTable.shopExtendMap = res.shopExtendMap;
|
res.shopTable.shopExtendMap = res.shopExtendMap;
|
||||||
this.shopInfo = res.shopInfo;
|
this.shopInfo = res.shopInfo;
|
||||||
// 店铺信息
|
// 店铺信息
|
||||||
uni.cache.set("shopTable", res.shopTable);
|
uni.cache.set("shopTable", res.shopTable);
|
||||||
// 台桌信息
|
// 台桌信息
|
||||||
uni.cache.set("shopInfo", res.shopInfo);
|
uni.cache.set("shopInfo", res.shopInfo);
|
||||||
uni.cache.set("shopId", res.shopTable.shopId, 30);
|
// uni.cache.set("shopId", res.shopTable.shopId, 30);
|
||||||
|
uni.cache.set("shopId", res.shopTable.shopId);
|
||||||
|
|
||||||
resolve(res);
|
resolve(res);
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "通过桌码获取当前店铺信息失败",
|
title: "通过桌码获取当前店铺信息失败",
|
||||||
icon: "none",
|
icon: "none",
|
||||||
});
|
});
|
||||||
console.error("通过桌码获取当前店铺信息失败", res);
|
console.error("通过桌码获取当前店铺信息失败", res);
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
reject();
|
reject();
|
||||||
//TODO handle the exception
|
//TODO handle the exception
|
||||||
}
|
}
|
||||||
|
|
||||||
// } catch (e) {
|
// } catch (e) {
|
||||||
// reject(false)
|
// reject(false)
|
||||||
// }
|
// }
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 通过shopId 获取店铺会员信息
|
// 通过shopId 获取店铺会员信息
|
||||||
actionsproductqueryProduct() {
|
actionsproductqueryProduct() {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
let res = await APIshopUserInfo();
|
let res = await APIshopUserInfo();
|
||||||
uni.cache.set("shopUserInfo", res);
|
uni.cache.set("shopUserInfo", res);
|
||||||
uni.cache.set("orderVIP", res);
|
uni.cache.set("orderVIP", res);
|
||||||
uni.cache.set("ordershopUserInfo", res.shopInfo);
|
uni.cache.set("ordershopUserInfo", res.shopInfo);
|
||||||
resolve(res);
|
resolve(res);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject(false);
|
reject(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 用户信息获取
|
// 用户信息获取
|
||||||
actionsAPIuser() {
|
actionsAPIuser() {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
let res = null;
|
let res = null;
|
||||||
// 获取店铺用户会员信息
|
// 获取店铺用户会员信息
|
||||||
if (uni.cache.get("shopId")) {
|
if (uni.cache.get("shopId")) {
|
||||||
res = await this.actionsproductqueryProduct();
|
res = await this.actionsproductqueryProduct();
|
||||||
} else {
|
} else {
|
||||||
res = await APIuser();
|
res = await APIuser();
|
||||||
uni.cache.set("userInfo", res);
|
uni.cache.set("userInfo", res);
|
||||||
}
|
}
|
||||||
console.log("actionsAPIuser res", res);
|
console.log("actionsAPIuser res", res);
|
||||||
resolve(res);
|
resolve(res);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject(false);
|
reject(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user