diff --git a/src/App.vue b/src/App.vue index f90c767..5340c70 100644 --- a/src/App.vue +++ b/src/App.vue @@ -6,7 +6,7 @@ export default { latitude: 39.5426, longitude: 116.23292, }, - appId: "wxed3e2914d6aa4d52", + appId: "wx9995c9f495efa82e", hasLocationAuth: true, }, onLaunch: function () { diff --git a/src/manifest.json b/src/manifest.json index f20915f..5fb2f35 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -57,7 +57,7 @@ /* 快应用特有相关 */ }, "mp-weixin": { - /* 微信小程序特有相关 */ "appid": "wxed3e2914d6aa4d52", + /* 微信小程序特有相关 */ "appid": "wx9995c9f495efa82e", "setting": { "urlCheck": false }, diff --git a/src/subPackages/site/details/index.vue b/src/subPackages/site/details/index.vue index 5cfa68d..8acb72a 100644 --- a/src/subPackages/site/details/index.vue +++ b/src/subPackages/site/details/index.vue @@ -201,39 +201,16 @@ export default { }, }, methods: { - hasLocationAuthHandle(callback = () => {}) { - const appInstance = getApp(); - let { hasLocationAuth } = appInstance.globalData; - if (!hasLocationAuth) { - uni.showModal({ - title: "未打开小程序定位", - content: "需获取您的地理位置才可以继续加油", - confirmText: "开启定位", - success: (res) => { - if (res.confirm) { - uni.openSetting({ - success: (res) => { - if (res.authSetting["scope.userLocation"]) { - callback(); - } - }, - }); - } - }, - }); - return false; - } - return true; - }, serviceIllustrate() { this.$refs.popupIllustrate.open("bottom"); }, - createCOrder() { + async createCOrder() { let isHas = this.hasLocationAuthHandle(() => { this.getById(this.siteInfo); }); if (!isHas) return; - if (!this.beyondDistance()) return; + let isBeyond = await this.beyondDistance(); + if (!isBeyond) return; if (!this.checkParams()) return; serve .createCOrder({ @@ -251,17 +228,24 @@ export default { this.wxPay(res.data); }); }, - beyondDistance() { - let { juli, siteName } = this.siteInfo; - if (juli > 10000) { + // 定位权限是否开启检测 + hasLocationAuthHandle(callback = () => {}) { + const appInstance = getApp(); + let { hasLocationAuth } = appInstance.globalData; + if (!hasLocationAuth) { uni.showModal({ - title: siteName, - content: "您与加油站距离较远,请到达加油站与加油员确认金额后付款", - confirmText: "导航到站", - cancelText: "我知道了", + title: "未打开小程序定位", + content: "需获取您的地理位置才可以继续加油", + confirmText: "开启定位", success: (res) => { if (res.confirm) { - this.openMap(); + uni.openSetting({ + success: (res) => { + if (res.authSetting["scope.userLocation"]) { + callback(); + } + }, + }); } }, }); @@ -269,6 +253,36 @@ export default { } return true; }, + // 距离检测 + async beyondDistance() { + let { juli, siteName, siteId, id } = this.siteInfo; + if (juli > 10000) { + let firstRes = await this.$utils.obtainLocationHandle(); + let { latitude, longitude } = firstRes; + let secondRes = await serve.getById({ + id: siteId || id, + latitude, + longitude, + }); + if (secondRes.code !== 20000) return false; + if (secondRes.data.juli > 10000) { + uni.showModal({ + title: siteName, + content: "您与加油站距离较远,请到达加油站与加油员确认金额后付款", + confirmText: "导航到站", + cancelText: "我知道了", + success: (res) => { + if (res.confirm) { + this.openMap(); + } + }, + }); + return false; + } + return true; + } + return true; + }, checkParams() { if (!this.params.oilsBar) { uni.showToast({ @@ -385,7 +399,7 @@ export default { marketPrice: item.marketPrice, sitePriceId: item.priceId, }); - // item.oilsBars数据结构为['','',''] 此处不适用 转化下为[{},{},{}] + // item.oilsBars数据结构为['','',''] 此处不适用 转化为[{},{},{}] spear[item.oilProductCode] = item.oilsBars.reduce((prev, item) => { prev.push({ label: item,