|
|
@@ -159,15 +159,10 @@
|
|
|
<block v-else>
|
|
|
<view v-if="isWithinTwoDays" class="no-supplier-tip">附近暂无批发店</view>
|
|
|
<block v-else>
|
|
|
- <view v-if="!shopInfo.lat || !shopInfo.long" class="location-empty-box">
|
|
|
+ <view class="location-empty-box">
|
|
|
<zui-svg-icon icon="general-location" :width="40" :height="40" color="#09C567"/>
|
|
|
<view class="location-empty-title">开启定位,查看附近批发店</view>
|
|
|
- <button class="location-empty-btn" @click="pageTo({url:'/admin/shop/add?id='+loginInfo.shopId+'&openLocation=1'})">开启</button>
|
|
|
- </view>
|
|
|
- <view v-else class="location-empty-box">
|
|
|
- <zui-svg-icon icon="general-location" :width="40" :height="40" color="#09C567"/>
|
|
|
- <view class="location-empty-title">寻找附近批发店</view>
|
|
|
- <button class="location-empty-btn" @click="searchGhs()">寻找</button>
|
|
|
+ <button class="location-empty-btn" @click="searchGhs()">开启</button>
|
|
|
</view>
|
|
|
</block>
|
|
|
</block>
|
|
|
@@ -231,6 +226,7 @@
|
|
|
import {currentShop, uploadShopAvatar} from "@/api/shop";
|
|
|
import { hasNotice } from "@/api/admin";
|
|
|
import { APIHOST } from "@/config";
|
|
|
+ import permision from "@/utils/wa-permission_1.1/permission.js";
|
|
|
export default {
|
|
|
name: "workbench",
|
|
|
mixins: [autoUpdateMixins],
|
|
|
@@ -547,17 +543,91 @@
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
- searchGhs(){
|
|
|
- searchNearbyGhs().then(res=>{
|
|
|
- if(res.code == 1){
|
|
|
- uni.setStorageSync('supplier_search_time', Date.now()) //设置缓存时间--记录当前查找附近批发店的时间
|
|
|
- //重新刷新列表
|
|
|
- this.getGHSList()
|
|
|
- this.$msg('查找成功')
|
|
|
- }else{
|
|
|
- this.$msg(res.msg)
|
|
|
+ async searchGhs(){
|
|
|
+ console.log('searchGhs start')
|
|
|
+
|
|
|
+ // #ifdef APP-PLUS
|
|
|
+ // App 端先显式申请权限,避免部分机型 getLocation 挂起无回调
|
|
|
+ if (plus.os.name === 'Android') {
|
|
|
+ const permissionRes = await permision.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION')
|
|
|
+ if (permissionRes !== 1) {
|
|
|
+ this.$msg('请开启定位权限后重试')
|
|
|
+ if (permissionRes === -1) {
|
|
|
+ permision.gotoAppPermissionSetting()
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
- })
|
|
|
+ }
|
|
|
+ if (!permision.checkSystemEnableLocation()) {
|
|
|
+ this.$msg('请先开启系统定位服务')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // #endif
|
|
|
+
|
|
|
+ let hasLocationCallback = false
|
|
|
+ const timeoutTimer = setTimeout(() => {
|
|
|
+ if (!hasLocationCallback) {
|
|
|
+ console.log('getLocation timeout')
|
|
|
+ this.$msg('定位超时,请确认系统定位已开启后重试')
|
|
|
+ }
|
|
|
+ }, 5000)
|
|
|
+
|
|
|
+ const handleLocationSuccess = (res, locationType) => {
|
|
|
+ hasLocationCallback = true
|
|
|
+ clearTimeout(timeoutTimer)
|
|
|
+ console.log('getLocation success', locationType, res)
|
|
|
+ searchNearbyGhs({
|
|
|
+ locationType: locationType,
|
|
|
+ lat: res.latitude,
|
|
|
+ long: res.longitude
|
|
|
+ }).then(ret=>{
|
|
|
+ if(ret.code == 1){
|
|
|
+ uni.setStorageSync('supplier_search_time', Date.now()) //设置缓存时间--记录当前查找附近批发店的时间
|
|
|
+ //重新刷新列表
|
|
|
+ this.getGHSList()
|
|
|
+ this.$msg('查找成功')
|
|
|
+ }else{
|
|
|
+ this.$msg(ret.msg)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ const requestLocation = (locationType) => {
|
|
|
+ uni.getLocation({
|
|
|
+ type: locationType,
|
|
|
+ success: (res) => {
|
|
|
+ handleLocationSuccess(res, locationType)
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.log('getLocation fail', locationType, err)
|
|
|
+ // 部分安卓机型不支持 gcj02,自动降级到 wgs84 再试一次
|
|
|
+ if (locationType === 'gcj02' && (
|
|
|
+ err.code == 18 ||
|
|
|
+ err.errCode == 18 ||
|
|
|
+ (err.errMsg && (
|
|
|
+ err.errMsg.indexOf('not support gcj02') > -1 ||
|
|
|
+ err.errMsg.indexOf('Not Support CoordsType') > -1
|
|
|
+ ))
|
|
|
+ )) {
|
|
|
+ requestLocation('wgs84')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ hasLocationCallback = true
|
|
|
+ clearTimeout(timeoutTimer)
|
|
|
+ uni.showToast({ title: '定位失败,请检查定位权限', icon: 'none' })
|
|
|
+ },
|
|
|
+ complete: () => {
|
|
|
+ console.log('getLocation complete', locationType)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ // iOS 机型在部分运行环境不支持 gcj02,直接使用 wgs84
|
|
|
+ // #ifdef APP-PLUS
|
|
|
+ if (plus.os.name === 'iOS') {
|
|
|
+ requestLocation('wgs84')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // #endif
|
|
|
+ requestLocation('gcj02')
|
|
|
}
|
|
|
}
|
|
|
};
|