From 00c5987ccc56a4baec9da3a07c93c3235681cb01 Mon Sep 17 00:00:00 2001 From: gyq <875626088@qq.com> Date: Wed, 3 Dec 2025 15:26:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A2=84=E7=82=B9=E5=8D=95?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/components/pageLoading.vue | 108 + pages/index/index.vue | 25 +- pages/index/indexs.vue | 75 +- pages/order/confirm-order-back.vue | 2 +- pages/order/confirm-order.vue | 2674 ++++++------ pages/order/detail.vue | 2 +- pages/product/index.vue | 5263 +++++++++++------------- pages/subscribeto/index.vue | 2 +- pages/user/member/index.vue | 2 +- pages/user/member/memberdetails.vue | 1013 +++-- stores/user.js | 855 ++-- 11 files changed, 4814 insertions(+), 5207 deletions(-) create mode 100644 pages/index/components/pageLoading.vue diff --git a/pages/index/components/pageLoading.vue b/pages/index/components/pageLoading.vue new file mode 100644 index 0000000..4fc5a94 --- /dev/null +++ b/pages/index/components/pageLoading.vue @@ -0,0 +1,108 @@ + + + + + diff --git a/pages/index/index.vue b/pages/index/index.vue index 5cb6eec..b687705 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -127,6 +127,8 @@ + + @@ -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(); diff --git a/pages/index/indexs.vue b/pages/index/indexs.vue index 57e6e3d..44d1ea4 100644 --- a/pages/index/indexs.vue +++ b/pages/index/indexs.vue @@ -27,7 +27,6 @@ - @@ -38,6 +37,24 @@ + + + + 请选择 + + + + + + + 预点单 + + + 扫码点单 + + + + @@ -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; + } + } +} diff --git a/pages/order/confirm-order-back.vue b/pages/order/confirm-order-back.vue index 04219fc..50e940e 100644 --- a/pages/order/confirm-order-back.vue +++ b/pages/order/confirm-order-back.vue @@ -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); } // * 获取会员信息 diff --git a/pages/order/confirm-order.vue b/pages/order/confirm-order.vue index 679ade6..f0c6ece 100644 --- a/pages/order/confirm-order.vue +++ b/pages/order/confirm-order.vue @@ -1,292 +1,187 @@ \ No newline at end of file + diff --git a/pages/order/detail.vue b/pages/order/detail.vue index 6a65c6e..09fb782 100644 --- a/pages/order/detail.vue +++ b/pages/order/detail.vue @@ -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); } // * 获取会员信息 diff --git a/pages/product/index.vue b/pages/product/index.vue index 2770980..8e7ad92 100644 --- a/pages/product/index.vue +++ b/pages/product/index.vue @@ -1,999 +1,630 @@ diff --git a/pages/subscribeto/index.vue b/pages/subscribeto/index.vue index 83c4f8c..3fb03ff 100644 --- a/pages/subscribeto/index.vue +++ b/pages/subscribeto/index.vue @@ -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(); }) diff --git a/pages/user/member/index.vue b/pages/user/member/index.vue index 2601dba..f51fda3 100644 --- a/pages/user/member/index.vue +++ b/pages/user/member/index.vue @@ -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() diff --git a/pages/user/member/memberdetails.vue b/pages/user/member/memberdetails.vue index 2979de1..01cbb6c 100644 --- a/pages/user/member/memberdetails.vue +++ b/pages/user/member/memberdetails.vue @@ -2,650 +2,621 @@ - + - - {{shopUserInfo.shopInfo.shopName||''}}会员卡 + + {{ shopUserInfo.shopInfo.shopName || '' }}会员卡 - + VL1 - + - {{ shopUserInfo.shopInfo.isVip == 0 ? '尚未开通会员暂无法享受会员权益' : '欢迎加入本店会员~'}} - + {{ shopUserInfo.shopInfo.isVip == 0 ? '尚未开通会员暂无法享受会员权益' : '欢迎加入本店会员~' }} - {{shopUserInfo.amount || '0.00'}}储值 + {{ shopUserInfo.amount || '0.00' }} + 储值 - {{shopUserInfo.accountPoints || '0'}}积分 + {{ shopUserInfo.accountPoints || '0' }} + 积分 - {{shopUserInfo.couponNum || '0'}}优惠券 + {{ shopUserInfo.couponNum || '0' }} + 优惠券 - 0权益卡 + 0 + 权益卡 - - + 感谢你 2 天陪伴 - 您今天的幸运词:林波微步 + + 您今天的幸运词: + 林波微步 + - - + 专享2项权益 - + 会员专属活动 - + 福利商品 - - - - + \ No newline at end of file + + .therecontent { + margin-top: 32rpx; + position: relative; + padding: 22rpx 32rpx; + width: 100%; + background: #ffffff; + border-radius: 8rpx; + + input { + padding-left: 30rpx; + text-align: right; + font-size: 28rpx; + font-family: Source Han Sans CN-Medium, Source Han Sans CN; + font-weight: 500; + color: #666666; + } + } + + .therecontent::after { + position: absolute; + top: 50%; + left: 32rpx; + transform: translateY(-50%); + content: '¥'; + display: inline-block; + width: 28rpx; + height: 40rpx; + font-size: 28rpx; + font-family: Source Han Sans CN-Regular, Source Han Sans CN; + font-weight: 400; + color: #333333; + } + + .fourcontent { + .fourcontentlnage { + width: 33.33%; + + .fourcontentitem { + margin: 24rpx 10rpx; + padding: 16rpx 0; + text-align: center; + background: #ffffff; + border-radius: 8rpx; + border: 1rpx solid #333333; + font-size: 28rpx; + font-family: Roboto-Medium, Roboto; + font-weight: 500; + color: #333333; + } + + .fourcontentitems { + margin: 24rpx 10rpx; + padding: 16rpx 0; + text-align: center; + border-radius: 8rpx; + background: #f1cb66; + border-radius: 8rpx 8rpx 8rpx 8rpx; + border: 2rpx solid #f1cb66; + font-size: 28rpx; + font-family: Roboto-Medium, Roboto; + font-weight: 500; + color: #ffffff; + } + } + } + + .fivecontent { + position: relative; + bottom: 44rpx; + margin-top: 62rpx; + padding: 20rpx 0; + text-align: center; + width: 100%; + font-size: 36rpx; + font-family: PingFang SC-Bold, PingFang SC; + font-weight: bold; + color: #ffffff; + border-radius: 8rpx; + background: #f1cb66; + } + + // 会员详情 + .memberdetailsStyle { + margin-top: 32rpx; + border-radius: 24rpx 24rpx 24rpx 24rpx; + background-color: #fff; + padding: 32rpx; + height: 252rpx; + display: flex; + justify-content: space-between; + flex-direction: column; + + > text { + font-weight: bold; + font-size: 32rpx; + color: #333333; + } + + > view { + font-weight: 400; + font-size: 28rpx; + color: #333333; + display: flex; + justify-content: space-between; + align-items: center; + } + } +} + diff --git a/stores/user.js b/stores/user.js index 82e7c31..19bb25c 100644 --- a/stores/user.js +++ b/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); + } + }); + }, + }, +}); \ No newline at end of file