Explorar o código

Merge branch 'feature_20240911_pc端无定位依然支持访问'

zhujindu hai 1 ano
pai
achega
5d6b98663f

+ 31 - 23
src/App.vue

@@ -1,36 +1,44 @@
 <template>
   <div id="app" class="bgcolor">
-    <router-view/>
+    <router-view />
   </div>
 </template>
 <script>
-import watermark from 'watermark-dom'
+import watermark from 'watermark-dom';
 
 export default {
-  name: "App",
-  mounted(){
-    setTimeout(()=>{
-      let username = localStorage.getItem("nickName");
-      if(username){
+  name: 'App',
+  created() {
+    // 当前设备:PC/mobile
+    let isDevice = window.navigator.userAgent.match(
+      /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
+    );
+    localStorage.setItem('isDevice', !isDevice ? 'PC' : 'mobile'); // !isDevice: true:PC false:mobile
+  },
+  mounted() {
+    setTimeout(() => {
+      let username = localStorage.getItem('nickName');
+      if (username) {
         let now = new Date();
         let year = now.getFullYear();
-        let month = now.getMonth()+1;
+        let month = now.getMonth() + 1;
         let day = now.getDate();
-        month = month<10?'0'+month:month;
-        day = day<10?'0'+day:day;
-        let date = year+'-'+month+'-'+day;
+        month = month < 10 ? '0' + month : month;
+        day = day < 10 ? '0' + day : day;
+        let date = year + '-' + month + '-' + day;
         watermark.load({
-          watermark_txt: username+'@立邦'+date,watermark_fontsize:'13px',
-          watermark_width:100,
-          watermark_rows:0,
-          watermark_cols:3,
-          watermark_height:50,
-          watermark_x_space:10,
-          watermark_y_space:60,
-          watermark_alpha:0.1,
-        })
+          watermark_txt: username + '@立邦' + date,
+          watermark_fontsize: '13px',
+          watermark_width: 100,
+          watermark_rows: 0,
+          watermark_cols: 3,
+          watermark_height: 50,
+          watermark_x_space: 10,
+          watermark_y_space: 60,
+          watermark_alpha: 0.1,
+        });
       }
-    },1000)
-  }
+    }, 1000);
+  },
 };
-</script>
+</script>

+ 81 - 86
src/utils/TXApiFun.js

@@ -1,84 +1,78 @@
-import Vue from 'vue'
-import { getTicket } from '@/api/index'
-import { toastLoading } from '@/utils/commonVant'
-import { CJ02BD, gcj02BD } from '@/utils/index'
-import { jsonp } from 'vue-jsonp'
+import Vue from 'vue';
+import { getTicket } from '@/api/index';
+import { toastLoading } from '@/utils/commonVant';
+import { CJ02BD, gcj02BD } from '@/utils/index';
+import { jsonp } from 'vue-jsonp';
 // 微信JSSDK实例
-const wx = Vue.prototype.wx
+const wx = Vue.prototype.wx;
 // 腾讯位置服务 key
-const TxMapKey = 'WLCBZ-HRM6L-YOMPV-ME62B-AQOG6-JUBW6'
+const TxMapKey = 'WLCBZ-HRM6L-YOMPV-ME62B-AQOG6-JUBW6';
+// 当前设备
+// const isDevice = localStorage.getItem('isDevice');
+// console.log(isDevice);
 
 /**
  * 获取当前定位 调用之前确保当前页面已经授权(getTicketFun)
  * */
-export function getPosition() {
+export function getPosition(isDevice) {
   return new Promise((resolve, reject) => {
-    toastLoading(0, '定位中...', true)
-    // 本地开发 test 环境时跳过获取定位功能 模拟定位
+    toastLoading(0, '定位中...', true);
+    // PC端没有定位权限依然可以访问
     if (process.env.NODE_ENV === 'test') {
+      // 本地开发 test 环境时跳过获取定位功能 模拟定位
       let resData = {
         latitude: 34.615684509277344,
         longitude: 112.4474105834961,
-      }
+      };
       // 定位坐标转换 腾讯转百度
-      let TXisBD = CJ02BD(resData.latitude, resData.longitude)
-      localStorage.setItem('lat', TXisBD.lat)
-      localStorage.setItem('lon', TXisBD.lon)
-      toastLoading().clear()
-      resolve({ TXisBD, resData })
+      let TXisBD = CJ02BD(resData.latitude, resData.longitude);
+      localStorage.setItem('lat', TXisBD.lat);
+      localStorage.setItem('lon', TXisBD.lon);
+      toastLoading().clear();
+      resolve({ TXisBD: TXisBD, resData: resData });
+    } else if (isDevice == 'PC') {
+      localStorage.setItem('lat', '');
+      localStorage.setItem('lon', '');
+      toastLoading().clear();
+      resolve({ TXisBD: { lat: '', lon: '' }, resData: { latitude: '', longitude: '' } });
     } else {
-      // let url = window.location.href;
-      // //  获取签名
-      // getTicket({ url: url }).then((response) => {
-      //   console.log(response);
-      //   toastLoading().clear();
-      //   if (response.code == 200) {
-      //     let qiyeData = response.data;
-      //     wx.config({
-      //       beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
-      //       debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
-      //       appId: qiyeData.appId, // 必填,企业微信的corpID
-      //       timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
-      //       nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
-      //       signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
-      //       jsApiList: ["ready", "getLocation"], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
-      //     });
       wx.ready(() => {
         wx.getLocation({
           type: 'gcj02',
           success: (resData) => {
-            toastLoading().clear()
-            console.log('处理前')
-            console.log(resData.latitude, resData.longitude)
+            console.log('success');
+            toastLoading().clear();
+            console.log('处理前');
+            console.log(resData.latitude, resData.longitude);
             // 定位坐标转换 腾讯转百度
-            let TXisBD = CJ02BD(resData.latitude, resData.longitude)
-            console.log('处理后')
-            console.log(TXisBD)
-            localStorage.setItem('lat', TXisBD.lat)
-            localStorage.setItem('lon', TXisBD.lon)
-            resolve({ TXisBD, resData })
+            let TXisBD = CJ02BD(resData.latitude, resData.longitude);
+            console.log('处理后');
+            console.log(TXisBD);
+            localStorage.setItem('lat', TXisBD.lat);
+            localStorage.setItem('lon', TXisBD.lon);
+            resolve({ TXisBD: TXisBD, resData: resData });
           },
           fail: () => {
-            toastLoading().clear()
-            reject('GPS未开启')
+            console.log('fail');
+            toastLoading().clear();
+            reject('GPS未开启');
           },
           complete: () => {
-            toastLoading().clear()
+            console.log('complete');
+            toastLoading().clear();
           },
-        })
-      })
+        });
+      });
       wx.error((err) => {
-        toastLoading().clear()
-        console.log(err)
-        reject('定位失败,请开启企微定位权限')
-      })
-      // } else {
-      //   toastLoading().clear();
-      //   reject("获取签名失败");
-      // }
-      // });
+        console.log('wx.error');
+        toastLoading().clear();
+        console.log(err);
+        localStorage.setItem('lat', '');
+        localStorage.setItem('lon', '');
+        reject('定位失败,请开启企微定位权限');
+      });
     }
-  })
+  });
 }
 
 /**
@@ -89,13 +83,13 @@ export function getPosition() {
 export function getTicketFun(jsApiList = ['getLocation']) {
   return new Promise((resolve, reject) => {
     // 当前页面
-    let url = window.location.href
+    let url = window.location.href;
     //  获取签名
     getTicket({ url: url }).then((response) => {
-      console.log(response)
-      toastLoading().clear()
+      console.log(response);
+      toastLoading().clear();
       if (response.code == 200) {
-        let qiyeData = response.data
+        let qiyeData = response.data;
         wx.config({
           beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
           debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
@@ -104,14 +98,15 @@ export function getTicketFun(jsApiList = ['getLocation']) {
           nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
           signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
           jsApiList: ['ready', ...jsApiList], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
-        })
-        resolve('获取签名成功')
+        });
+        console.log('获取签名成功');
+        resolve('获取签名成功');
       } else {
-        console.log('获取签名失败')
-        reject('获取签名失败')
+        console.log('获取签名失败');
+        reject('获取签名失败');
       }
-    })
-  })
+    });
+  });
 }
 /**
  * 地点搜索 获取500米范围poi点
@@ -123,19 +118,19 @@ export function getTicketFun(jsApiList = ['getLocation']) {
 export function getMapPoi(location, radius = 500, auto_extend = 0) {
   return new Promise((resolve, reject) => {
     let api =
-      'https://apis.map.qq.com/ws/place/v1/search?page_size=10&page_index=1&orderby=_distance&output=jsonp'
-    let boundary = `&boundary=nearby(${location.latitude},${location.longitude},${radius},${auto_extend})`
-    let key = `&key=${TxMapKey}`
+      'https://apis.map.qq.com/ws/place/v1/search?page_size=10&page_index=1&orderby=_distance&output=jsonp';
+    let boundary = `&boundary=nearby(${location.latitude},${location.longitude},${radius},${auto_extend})`;
+    let key = `&key=${TxMapKey}`;
     jsonp(api + boundary + key)
       .then((res) => {
-        console.log(res)
-        resolve(res)
+        console.log(res);
+        resolve(res);
       })
       .catch((err) => {
-        console.log(err)
-        reject(err)
-      })
-  })
+        console.log(err);
+        reject(err);
+      });
+  });
 }
 
 /**
@@ -146,21 +141,21 @@ export function getMapPoi(location, radius = 500, auto_extend = 0) {
  */
 export function getkeywordPoi(location, keywordValue) {
   return new Promise((resolve, reject) => {
-    let keyword = keywordValue ? '&keyword=' + encodeURI(keywordValue) : ''
+    let keyword = keywordValue ? '&keyword=' + encodeURI(keywordValue) : '';
     // 关键词搜索
     let api =
-      'https://apis.map.qq.com/ws/place/v1/suggestion?output=jsonp&page_size=10&region_fix=1'
-    let key = `&key=${TxMapKey}`
-    let locationPos = `&location=${location.latitude},${location.longitude}`
+      'https://apis.map.qq.com/ws/place/v1/suggestion?output=jsonp&page_size=10&region_fix=1';
+    let key = `&key=${TxMapKey}`;
+    let locationPos = `&location=${location.latitude},${location.longitude}`;
     jsonp(api + locationPos + keyword + key)
       .then((res) => {
-        console.log(keyword)
-        console.log(res)
-        resolve(res)
+        console.log(keyword);
+        console.log(res);
+        resolve(res);
       })
       .catch((err) => {
-        console.log(err)
-        reject(err)
-      })
-  })
+        console.log(err);
+        reject(err);
+      });
+  });
 }

+ 146 - 143
src/views/deviceOutside/index.vue

@@ -938,99 +938,120 @@ export default {
     // 范围
     rangeStoreFn() {
       localStorage.setItem('tabVal', this.tabVal);
-      let loading1 = this.$toast.loading({
-        duration: 0,
-        message: '加载中...',
-        forbidClick: true,
-      });
-      let url = window.location.href;
-      let wx = this.wx;
-      var that = this;
-      // that.$router.push({path: "/rangeStore", query: {
-      //     lon:"112.45359397440227",
-      //     lat:"34.62171814576471",
-      //     tabVal:that.tabVal
-      //   }
-      // })
-      let qiyeData;
-      const instance = axios.create();
-      instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
-      instance
-        .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
-          params: {
-            url: url,
-          },
+      getPosition()
+        .then((res) => {
+          let { TXisBD } = res;
+          this.lat = TXisBD.lat;
+          this.lon = TXisBD.lon;
+          let name = this.tabVal != 1 ? '销售部' : '我的';
+          this.buryingPoint({
+            systemModel: '计划外',
+            buryingPointType: 3,
+            buryingPointValue: name,
+            buryingPointName: '计划外',
+            buryingPointPosition: '进入地图',
+          });
+          this.$router.push({
+            path: '/rangeStore',
+            query: {
+              lat: '',
+              lon: '',
+              tabVal: this.tabVal,
+            },
+          });
         })
-        .then((response) => {
-          if (response.status == 200) {
-            this.cont = 5;
-            var flat = true;
-            var times = setInterval(() => {
-              this.cont--;
-              if (this.cont == '0') {
-                if (flat) {
-                  loading1.clear();
-                  clearInterval(times);
-                  that.$dialog.alert({
-                    message: '定位失败,请开启企微定位权限',
-                  });
-                } else {
-                  clearInterval(times);
-                }
-              }
-            }, 1000);
-            qiyeData = response.data.data;
-            wx.config({
-              beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
-              debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
-              appId: qiyeData.appId, // 必填,企业微信的corpID
-              timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
-              nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
-              signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
-              jsApiList: ['ready', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
-            });
-            wx.ready(function () {
-              wx.getLocation({
-                type: 'gcj02',
-                success: function (res) {
-                  flat = false;
-                  loading1.clear();
-                  var name = '我的';
-                  if (that.tabVal != 1) {
-                    name = '销售部';
-                  }
-                  that.buryingPoint({
-                    systemModel: '计划外',
-                    buryingPointType: 3,
-                    buryingPointValue: name,
-                    buryingPointName: '计划外',
-                    buryingPointPosition: '进入地图',
-                  });
-                  that.$router.push({
-                    path: '/rangeStore',
-                    query: {
-                      lat: '',
-                      lon: '',
-                      tabVal: that.tabVal,
-                    },
-                  });
-                },
-                fail: function () {
-                  loading1.clear();
-                  that.$dialog.alert({
-                    message: 'GPS未开启',
-                  });
-                },
-              });
-            });
-            wx.error(function (res) {
-              loading1.clear();
-              that.$dialog.alert({
-                message: '定位失败,请开启企微定位权限',
-              });
-            });
-          }
+        .catch((error) => {
+          this.$dialog.alert({
+            message: error,
+          });
         });
+      // let loading1 = this.$toast.loading({
+      //   duration: 0,
+      //   message: '加载中...',
+      //   forbidClick: true,
+      // });
+      // let url = window.location.href;
+      // let wx = this.wx;
+      // var that = this;
+      // let qiyeData;
+      // const instance = axios.create();
+      // instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
+      // instance
+      //   .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
+      //     params: {
+      //       url: url,
+      //     },
+      //   })
+      //   .then((response) => {
+      //     if (response.status == 200) {
+      //       this.cont = 5;
+      //       var flat = true;
+      //       var times = setInterval(() => {
+      //         this.cont--;
+      //         if (this.cont == '0') {
+      //           if (flat) {
+      //             loading1.clear();
+      //             clearInterval(times);
+      //             that.$dialog.alert({
+      //               message: '定位失败,请开启企微定位权限',
+      //             });
+      //           } else {
+      //             clearInterval(times);
+      //           }
+      //         }
+      //       }, 1000);
+      //       qiyeData = response.data.data;
+      //       wx.config({
+      //         beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
+      //         debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
+      //         appId: qiyeData.appId, // 必填,企业微信的corpID
+      //         timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
+      //         nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
+      //         signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
+      //         jsApiList: ['ready', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
+      //       });
+      //       wx.ready(function () {
+      //         wx.getLocation({
+      //           type: 'gcj02',
+      //           success: function (res) {
+      //             flat = false;
+      //             loading1.clear();
+      //             var name = '我的';
+      //             if (that.tabVal != 1) {
+      //               name = '销售部';
+      //             }
+      //             that.buryingPoint({
+      //               systemModel: '计划外',
+      //               buryingPointType: 3,
+      //               buryingPointValue: name,
+      //               buryingPointName: '计划外',
+      //               buryingPointPosition: '进入地图',
+      //             });
+      //             that.$router.push({
+      //               path: '/rangeStore',
+      //               query: {
+      //                 lat: '',
+      //                 lon: '',
+      //                 tabVal: that.tabVal,
+      //               },
+      //             });
+      //           },
+      //           fail: function () {
+      //             loading1.clear();
+      //             that.$dialog.alert({
+      //               message: 'GPS未开启',
+      //             });
+      //           },
+      //         });
+      //       });
+      //       wx.error(function (res) {
+      //         loading1.clear();
+      //         that.$dialog.alert({
+      //           message: '定位失败,请开启企微定位权限',
+      //         });
+      //       });
+      //     }
+      //   });
     },
     //取消搜索
     cancelSearch() {
@@ -1114,22 +1135,27 @@ export default {
       });
     },
     positionFn(val) {
-      getPosition().then((res) => {
-        let { TXisBD } = res;
-        this.lat = TXisBD.lat;
-        this.lon = TXisBD.lon;
-        localStorage.setItem('lat', TXisBD.lat);
-        localStorage.setItem('lon', TXisBD.lon);
-        if (val == 1) {
-          if (this.tabVal == 1) {
-            this.getUserOutPlaListFun();
+      const isDevice = localStorage.getItem('isDevice');
+      getPosition(isDevice)
+        .then((res) => {
+          let { TXisBD } = res;
+          this.lat = TXisBD.lat;
+          this.lon = TXisBD.lon;
+          if (val == 1) {
+            if (this.tabVal == 1) {
+              this.getUserOutPlaListFun();
+            } else {
+              this.getUserOrgStoreList();
+            }
           } else {
-            this.getUserOrgStoreList();
+            this.getUserOutPlaListFun();
           }
-        } else {
-          this.getUserOutPlaListFun();
-        }
-      });
+        })
+        .catch((error) => {
+          this.$dialog.alert({
+            message: error,
+          });
+        });
       // // 本地开发 test 环境时 时跳过获取定位功能
       // if (process.env.NODE_ENV === 'test') {
       //   this.lat = 34.62188103091605;
@@ -1460,44 +1486,21 @@ export default {
                   },
                 });
               } else {
-                getPosition().then((res) => {
-                  let { TXisBD, resData } = res;
-                  this.lat = TXisBD.lat;
-                  this.lon = TXisBD.lon;
-                  localStorage.setItem('lat', this.lat);
-                  localStorage.setItem('lon', this.lon);
-                  // var location = this.CJ02BD(res.latitude, res.longitude);
-                  this.checkStoreAddressByStoreCodeFun(val, TXisBD, resData);
-                });
-                // // 本地开发 test 环境时 跳过获取定位功能
-                // if (process.env.NODE_ENV === 'test') {
-                //   let res = {
-                //     latitude: 34.615684509277344,
-                //     longitude: 112.4474105834961,
-                //   };
-                //   this.lat = res.latitude;
-                //   this.lon = res.longitude;
-                //   localStorage.setItem('lat', this.lat);
-                //   localStorage.setItem('lon', this.lon);
-                //   var location = this.CJ02BD(res.latitude, res.longitude);
-                //   this.checkStoreAddressByStoreCodeFun(val, location, res);
-                // } else {
-                //   let loading1 = this.$toast.loading({
-                //     duration: 0,
-                //     message: '加载中...',
-                //     forbidClick: true,
-                //   });
-                //   this.getLocationFun()
-                //     .then((resData) => {
-                //       loading1.clear();
-                //       let { location, res } = resData;
-                //       this.checkStoreAddressByStoreCodeFun(val, location, res);
-                //     })
-                //     .catch((err) => {
-                //       console.log(err);
-                //       loading1.clear();
-                //     });
-                // }
+                getPosition()
+                  .then((res) => {
+                    let { TXisBD, resData } = res;
+                    this.lat = TXisBD.lat;
+                    this.lon = TXisBD.lon;
+                    localStorage.setItem('lat', this.lat);
+                    localStorage.setItem('lon', this.lon);
+                    // var location = this.CJ02BD(res.latitude, res.longitude);
+                    this.checkStoreAddressByStoreCodeFun(val, TXisBD, resData);
+                  })
+                  .catch((error) => {
+                    this.$dialog.alert({
+                      message: error,
+                    });
+                  });
               }
             }
           }

+ 389 - 258
src/views/deviceOutside/topStore.vue

@@ -607,6 +607,7 @@ import { getOrderUrlByStoreId, topjoinInPlan, topStore } from '@/api/inventory';
 import { parseTime } from '@/utils';
 import { checkStoreAddressByStoreCode } from '@/api/visitstore';
 import sbpmdh from '@/assets/sbpmdh.png';
+import { getPosition, getTicketFun } from '@/utils/TXApiFun';
 export default {
   name: 'outsidelist',
   components: { mapmarker },
@@ -1177,93 +1178,119 @@ export default {
     },
     // 范围
     rangeStoreFn() {
-      let loading1 = this.$toast.loading({
-        duration: 0,
-        message: '加载中...',
-        forbidClick: true,
-      });
-      let url = window.location.href;
-      let wx = this.wx;
-      var that = this;
-      let qiyeData;
-      const instance = axios.create();
-      instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
-      instance
-        .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
-          params: {
-            url: url,
-          },
+      getPosition()
+        .then((res) => {
+          let { TXisBD } = res;
+          this.lat = TXisBD.lat;
+          this.lon = TXisBD.lon;
+          this.buryingPoint({
+            systemModel: '高销额门店推荐',
+            buryingPointType: 3,
+            buryingPointValue: '进入地图',
+            buryingPointName: '高销额门店推荐',
+            buryingPointPosition: '进入地图',
+          });
+          this.$router.push({
+            path: '/rangeStore',
+            query: {
+              lat: '',
+              lon: '',
+              tabVal: 6,
+            },
+          });
         })
-        .then((response) => {
-          if (response.status == 200) {
-            this.cont = 3;
-            var flat = true;
-            var times = setInterval(() => {
-              this.cont--;
-              if (this.cont == '0') {
-                if (flat) {
-                  loading1.clear();
-                  clearInterval(times);
-                  that.$dialog
-                    .alert({
-                      message: '定位失败,请开启企微定位权限',
-                    })
-                    .then(() => {});
-                } else {
-                  clearInterval(times);
-                }
-              }
-            }, 1000);
-            qiyeData = response.data.data;
-            wx.config({
-              beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
-              debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
-              appId: qiyeData.appId, // 必填,企业微信的corpID
-              timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
-              nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
-              signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
-              jsApiList: ['ready', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
-            });
-            wx.ready(function () {
-              wx.getLocation({
-                type: 'gcj02',
-                success: function (res) {
-                  flat = false;
-                  loading1.clear();
-                  that.buryingPoint({
-                    systemModel: '高销额门店推荐',
-                    buryingPointType: 3,
-                    buryingPointValue: '进入地图',
-                    buryingPointName: '高销额门店推荐',
-                    buryingPointPosition: '进入地图',
-                  });
-                  that.$router.push({
-                    path: '/rangeStore',
-                    query: {
-                      lat: '',
-                      lon: '',
-                      tabVal: 6,
-                    },
-                  });
-                },
-                fail: function () {
-                  loading1.clear();
-                  that.$dialog.alert({
-                    message: 'GPS未开启',
-                  });
-                },
-              });
-            });
-            wx.error(function (res) {
-              loading1.clear();
-              that.$dialog
-                .alert({
-                  message: '定位失败,请开启企微定位权限',
-                })
-                .then(() => {});
-            });
-          }
+        .catch((error) => {
+          this.$dialog.alert({
+            message: error,
+          });
         });
+      // let loading1 = this.$toast.loading({
+      //   duration: 0,
+      //   message: '加载中...',
+      //   forbidClick: true,
+      // });
+      // let url = window.location.href;
+      // let wx = this.wx;
+      // var that = this;
+      // let qiyeData;
+      // const instance = axios.create();
+      // instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
+      // instance
+      //   .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
+      //     params: {
+      //       url: url,
+      //     },
+      //   })
+      //   .then((response) => {
+      //     if (response.status == 200) {
+      //       this.cont = 3;
+      //       var flat = true;
+      //       var times = setInterval(() => {
+      //         this.cont--;
+      //         if (this.cont == '0') {
+      //           if (flat) {
+      //             loading1.clear();
+      //             clearInterval(times);
+      //             that.$dialog
+      //               .alert({
+      //                 message: '定位失败,请开启企微定位权限',
+      //               })
+      //               .then(() => {});
+      //           } else {
+      //             clearInterval(times);
+      //           }
+      //         }
+      //       }, 1000);
+      //       qiyeData = response.data.data;
+      //       wx.config({
+      //         beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
+      //         debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
+      //         appId: qiyeData.appId, // 必填,企业微信的corpID
+      //         timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
+      //         nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
+      //         signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
+      //         jsApiList: ['ready', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
+      //       });
+      //       wx.ready(function () {
+      //         wx.getLocation({
+      //           type: 'gcj02',
+      //           success: function (res) {
+      //             flat = false;
+      //             loading1.clear();
+      //             that.buryingPoint({
+      //               systemModel: '高销额门店推荐',
+      //               buryingPointType: 3,
+      //               buryingPointValue: '进入地图',
+      //               buryingPointName: '高销额门店推荐',
+      //               buryingPointPosition: '进入地图',
+      //             });
+      //             that.$router.push({
+      //               path: '/rangeStore',
+      //               query: {
+      //                 lat: '',
+      //                 lon: '',
+      //                 tabVal: 6,
+      //               },
+      //             });
+      //           },
+      //           fail: function () {
+      //             loading1.clear();
+      //             that.$dialog.alert({
+      //               message: 'GPS未开启',
+      //             });
+      //           },
+      //         });
+      //       });
+      //       wx.error(function (res) {
+      //         loading1.clear();
+      //         that.$dialog
+      //           .alert({
+      //             message: '定位失败,请开启企微定位权限',
+      //           })
+      //           .then(() => {});
+      //       });
+      //     }
+      //   });
     },
     //取消搜索
     cancelSearch() {
@@ -1435,173 +1462,188 @@ export default {
                   },
                 });
               } else {
-                let loading1 = this.$toast.loading({
-                  duration: 0,
-                  message: '加载中...',
-                  forbidClick: true,
-                });
-                let url = window.location.href;
-                let wx = this.wx;
-                let qiyeData;
-                const instance = axios.create();
-                instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
-                instance
-                  .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
-                    params: {
-                      url: url,
-                    },
+                getPosition()
+                  .then((res) => {
+                    let { TXisBD, resData } = res;
+                    this.lat = TXisBD.lat;
+                    this.lon = TXisBD.lon;
+                    localStorage.setItem('lat', this.lat);
+                    localStorage.setItem('lon', this.lon);
+                    // var location = this.CJ02BD(res.latitude, res.longitude);
+                    this.checkStoreAddressByStoreCodeFun(val, TXisBD, resData);
                   })
-                  .then((response) => {
-                    if (response.status == 200) {
-                      this.cont = 5;
-                      var flat = true;
-                      var times = setInterval(() => {
-                        this.cont--;
-                        if (this.cont == '0') {
-                          if (flat) {
-                            loading1.clear();
-                            clearInterval(times);
-                            that.$dialog
-                              .alert({
-                                message: '定位失败,请开启企微定位权限',
-                              })
-                              .then(() => {});
-                          } else {
-                            clearInterval(times);
-                          }
-                        }
-                      }, 1000);
-                      qiyeData = response.data.data;
-                      wx.config({
-                        beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
-                        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
-                        appId: qiyeData.appId, // 必填,企业微信的corpID
-                        timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
-                        nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
-                        signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
-                        jsApiList: ['ready', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
-                      });
-                      wx.ready(() => {
-                        wx.getLocation({
-                          type: 'gcj02',
-                          success: (res) => {
-                            flat = false;
-                            // loading1.clear();
-                            var location = that.CJ02BD(res.latitude, res.longitude);
-                            checkStoreAddressByStoreCode({
-                              storeCode: val.storeCode,
-                              lon: location.lon,
-                              lat: location.lat,
-                            }).then((response) => {
-                              loading1.clear();
-                              if (val.lat == '' || val.lat == null) {
-                                this.lat = location.lat;
-                                this.lon = location.lon;
-                              } else {
-                                this.lat = val.lat;
-                                this.lon = val.lon;
-                              }
-                              let PointSum = this.twoPointSum(
-                                this.lat,
-                                this.lon,
-                                location.lat,
-                                location.lon
-                              ).toFixed(2);
-                              let PointSumval = this.twoPointSum(
-                                location.lat,
-                                location.lon,
-                                location.lat,
-                                location.lon
-                              ).toFixed(2);
-                              // GZ:工装店铺 直接进入拜访
-                              if (localStorage.getItem('postType') == 'GZ') {
-                                localStorage.setItem('startTime', new Date());
-                                localStorage.setItem('ORGName', val.deptName);
-                                localStorage.setItem('chainNameR', val.storeName);
-                                this.toSuishenbangOutstoreVisit(res, val, location, PointSumval);
-                                return;
-                              }
-                              // 门店编码校验门店地址不通过
-                              if (response.code != 200) {
-                                // updateAddress : ,1:同城AB+金牌,去修改地址;2:非金牌店铺,非同城店铺偏差过大不允许拜访,可以重置定位;0非金牌店铺,非同城店铺 位置信息不存在 可以继续拜访
-                                if (response.data.updateAddress == 0) {
-                                  // 非金牌店铺,非同城店铺 位置信息不存在 可以继续拜访
-                                  this.$dialog
-                                    .confirm({
-                                      confirmButtonText: '确定拜访',
-                                      cancelButtonText: '取消拜访',
-                                      title: '系统提示',
-                                      message:
-                                        '该客户没有经纬度,此次拜访会保存定位点作为客户经纬度,下次拜访时判断是否偏差过大。',
-                                      closeOnClickOverlay: true,
-                                    })
-                                    .then(() => {
-                                      this.toSuishenbangOutstoreVisit(
-                                        res,
-                                        val,
-                                        location,
-                                        PointSumval
-                                      );
-                                    });
-                                } else if (response.data.updateAddress == 1) {
-                                  // 同城AB+金牌,去修改地址
-                                  // addressUpdateTimesOver: true=已经达到最大次数,不让修改; false=没有达到可以修改
-                                  if (!response.data.addressUpdateTimesOver) {
-                                    this.$dialog
-                                      .confirm({
-                                        title: '系统提示',
-                                        message: response.msg + '请立即修改后再拜访',
-                                        messageAlign: 'left',
-                                        confirmButtonText: '立即修改',
-                                        cancelButtonText: '取消',
-                                      })
-                                      .then(() => {
-                                        this.$router.push({
-                                          path: '/storeDetail',
-                                          query: {
-                                            id: val.storeId,
-                                            type: 'address',
-                                            storeAddressId: val.storeAddressId,
-                                          },
-                                        });
-                                      });
-                                  } else {
-                                    this.$dialog.confirm({
-                                      title: '系统提示',
-                                      message: '已经达到最大修改次数',
-                                      messageAlign: 'left',
-                                      confirmButtonText: '确定',
-                                    });
-                                  }
-                                } else if (response.data.updateAddress == 2) {
-                                  // 1.非金牌店铺,非同城店铺 位置偏差过大 重置经纬度
-                                  this.resetCoord(res, val, location, PointSumval);
-                                  return;
-                                }
-                              } else {
-                                // 门店编码校验门店地址通过 进入拜访
-                                this.toSuishenbangOutstoreVisit(res, val, location, PointSumval);
-                              }
-                            });
-                          },
-                          fail: function () {
-                            loading1.clear();
-                            that.$dialog.alert({
-                              message: 'GPS未开启',
-                            });
-                          },
-                        });
-                      });
-                      wx.error(function (error) {
-                        loading1.clear();
-                        that.$dialog
-                          .alert({
-                            message: '定位失败,请开启企微定位权限',
-                          })
-                          .then(() => {});
-                      });
-                    }
+                  .catch((error) => {
+                    this.$dialog.alert({
+                      message: error,
+                    });
                   });
+                // let loading1 = this.$toast.loading({
+                //   duration: 0,
+                //   message: '加载中...',
+                //   forbidClick: true,
+                // });
+                // let url = window.location.href;
+                // let wx = this.wx;
+                // let qiyeData;
+                // const instance = axios.create();
+                // instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
+                // instance
+                //   .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
+                //     params: {
+                //       url: url,
+                //     },
+                //   })
+                //   .then((response) => {
+                //     if (response.status == 200) {
+                //       this.cont = 5;
+                //       var flat = true;
+                //       var times = setInterval(() => {
+                //         this.cont--;
+                //         if (this.cont == '0') {
+                //           if (flat) {
+                //             loading1.clear();
+                //             clearInterval(times);
+                //             that.$dialog
+                //               .alert({
+                //                 message: '定位失败,请开启企微定位权限',
+                //               })
+                //               .then(() => {});
+                //           } else {
+                //             clearInterval(times);
+                //           }
+                //         }
+                //       }, 1000);
+                //       qiyeData = response.data.data;
+                //       wx.config({
+                //         beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
+                //         debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
+                //         appId: qiyeData.appId, // 必填,企业微信的corpID
+                //         timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
+                //         nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
+                //         signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
+                //         jsApiList: ['ready', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
+                //       });
+                //       wx.ready(() => {
+                //         wx.getLocation({
+                //           type: 'gcj02',
+                //           success: (res) => {
+                //             flat = false;
+                //             // loading1.clear();
+                //             var location = that.CJ02BD(res.latitude, res.longitude);
+                //             checkStoreAddressByStoreCode({
+                //               storeCode: val.storeCode,
+                //               lon: location.lon,
+                //               lat: location.lat,
+                //             }).then((response) => {
+                //               loading1.clear();
+                //               if (val.lat == '' || val.lat == null) {
+                //                 this.lat = location.lat;
+                //                 this.lon = location.lon;
+                //               } else {
+                //                 this.lat = val.lat;
+                //                 this.lon = val.lon;
+                //               }
+                //               let PointSum = this.twoPointSum(
+                //                 this.lat,
+                //                 this.lon,
+                //                 location.lat,
+                //                 location.lon
+                //               ).toFixed(2);
+                //               let PointSumval = this.twoPointSum(
+                //                 location.lat,
+                //                 location.lon,
+                //                 location.lat,
+                //                 location.lon
+                //               ).toFixed(2);
+                //               // GZ:工装店铺 直接进入拜访
+                //               if (localStorage.getItem('postType') == 'GZ') {
+                //                 localStorage.setItem('startTime', new Date());
+                //                 localStorage.setItem('ORGName', val.deptName);
+                //                 localStorage.setItem('chainNameR', val.storeName);
+                //                 this.toSuishenbangOutstoreVisit(res, val, location, PointSumval);
+                //                 return;
+                //               }
+                //               // 门店编码校验门店地址不通过
+                //               if (response.code != 200) {
+                //                 // updateAddress : ,1:同城AB+金牌,去修改地址;2:非金牌店铺,非同城店铺偏差过大不允许拜访,可以重置定位;0非金牌店铺,非同城店铺 位置信息不存在 可以继续拜访
+                //                 if (response.data.updateAddress == 0) {
+                //                   // 非金牌店铺,非同城店铺 位置信息不存在 可以继续拜访
+                //                   this.$dialog
+                //                     .confirm({
+                //                       confirmButtonText: '确定拜访',
+                //                       cancelButtonText: '取消拜访',
+                //                       title: '系统提示',
+                //                       message:
+                //                         '该客户没有经纬度,此次拜访会保存定位点作为客户经纬度,下次拜访时判断是否偏差过大。',
+                //                       closeOnClickOverlay: true,
+                //                     })
+                //                     .then(() => {
+                //                       this.toSuishenbangOutstoreVisit(
+                //                         res,
+                //                         val,
+                //                         location,
+                //                         PointSumval
+                //                       );
+                //                     });
+                //                 } else if (response.data.updateAddress == 1) {
+                //                   // 同城AB+金牌,去修改地址
+                //                   // addressUpdateTimesOver: true=已经达到最大次数,不让修改; false=没有达到可以修改
+                //                   if (!response.data.addressUpdateTimesOver) {
+                //                     this.$dialog
+                //                       .confirm({
+                //                         title: '系统提示',
+                //                         message: response.msg + '请立即修改后再拜访',
+                //                         messageAlign: 'left',
+                //                         confirmButtonText: '立即修改',
+                //                         cancelButtonText: '取消',
+                //                       })
+                //                       .then(() => {
+                //                         this.$router.push({
+                //                           path: '/storeDetail',
+                //                           query: {
+                //                             id: val.storeId,
+                //                             type: 'address',
+                //                             storeAddressId: val.storeAddressId,
+                //                           },
+                //                         });
+                //                       });
+                //                   } else {
+                //                     this.$dialog.confirm({
+                //                       title: '系统提示',
+                //                       message: '已经达到最大修改次数',
+                //                       messageAlign: 'left',
+                //                       confirmButtonText: '确定',
+                //                     });
+                //                   }
+                //                 } else if (response.data.updateAddress == 2) {
+                //                   // 1.非金牌店铺,非同城店铺 位置偏差过大 重置经纬度
+                //                   this.resetCoord(res, val, location, PointSumval);
+                //                   return;
+                //                 }
+                //               } else {
+                //                 // 门店编码校验门店地址通过 进入拜访
+                //                 this.toSuishenbangOutstoreVisit(res, val, location, PointSumval);
+                //               }
+                //             });
+                //           },
+                //           fail: function () {
+                //             loading1.clear();
+                //             that.$dialog.alert({
+                //               message: 'GPS未开启',
+                //             });
+                //           },
+                //         });
+                //       });
+                //       wx.error(function (error) {
+                //         loading1.clear();
+                //         that.$dialog
+                //           .alert({
+                //             message: '定位失败,请开启企微定位权限',
+                //           })
+                //           .then(() => {});
+                //       });
+                //     }
+                //   });
               }
             }
           }
@@ -1613,6 +1655,93 @@ export default {
         }
       });
     },
+    checkStoreAddressByStoreCodeFun(val, location, res) {
+      checkStoreAddressByStoreCode({
+        storeCode: val.storeCode,
+        lon: location.lon,
+        lat: location.lat,
+      }).then((response) => {
+        // loading1.clear();
+        if (val.lat == '' || val.lat == null) {
+          this.lat = location.lat;
+          this.lon = location.lon;
+        } else {
+          this.lat = val.lat;
+          this.lon = val.lon;
+        }
+        // let PointSum = this.twoPointSum(this.lat, this.lon, location.lat, location.lon).toFixed(2);
+        let PointSumval = this.twoPointSum(
+          location.lat,
+          location.lon,
+          location.lat,
+          location.lon
+        ).toFixed(2);
+        // GZ:工装店铺 直接进入拜访
+        if (localStorage.getItem('postType') == 'GZ') {
+          localStorage.setItem('startTime', new Date());
+          localStorage.setItem('ORGName', val.deptName);
+          localStorage.setItem('chainNameR', val.storeName);
+          this.toSuishenbangOutstoreVisit(res, val, location, PointSumval);
+          return;
+        }
+        // 门店校验 地址不通过
+        if (response.code != 200) {
+          // updateAddress : ,1:同城AB+金牌,去修改地址;2:非金牌店铺,非同城店铺偏差过大不允许拜访,可以重置定位;0非金牌店铺,非同城店铺 位置信息不存在 可以继续拜访
+          if (response.data.updateAddress == 0) {
+            // 非金牌店铺,非同城店铺 位置信息不存在 可以继续拜访
+            this.$dialog
+              .confirm({
+                confirmButtonText: '确定拜访',
+                cancelButtonText: '取消拜访',
+                title: '系统提示',
+                message:
+                  '该客户没有经纬度,此次拜访会保存定位点作为客户经纬度,下次拜访时判断是否偏差过大。',
+                closeOnClickOverlay: true,
+              })
+              .then(() => {
+                this.toSuishenbangOutstoreVisit(res, val, location, PointSumval);
+              });
+          } else if (response.data.updateAddress == 1) {
+            // 同城AB+金牌,去修改地址
+            // addressUpdateTimesOver: true=已经达到最大次数,不让修改; false=没有达到可以修改
+            if (!response.data.addressUpdateTimesOver) {
+              this.$dialog
+                .confirm({
+                  title: '系统提示',
+                  message: response.msg + '请立即修改后再拜访',
+                  messageAlign: 'left',
+                  confirmButtonText: '立即修改',
+                  cancelButtonText: '取消',
+                })
+                .then(() => {
+                  this.$router.push({
+                    path: '/storeDetail',
+                    query: {
+                      id: val.storeId,
+                      type: 'address',
+                      storeAddressId: val.storeAddressId,
+                    },
+                  });
+                });
+            } else {
+              this.$dialog.confirm({
+                title: '系统提示',
+                message: '已经达到最大修改次数',
+                messageAlign: 'left',
+                confirmButtonText: '确定',
+              });
+            }
+          } else if (response.data.updateAddress == 2) {
+            // 1.非金牌店铺,非同城店铺 位置偏差过大 重置经纬度
+            this.resetCoord(res, val, location, PointSumval);
+            return;
+          }
+        } else {
+          // 门店编码校验门店地址通过 进入拜访
+          this.toSuishenbangOutstoreVisit(res, val, location, PointSumval);
+        }
+      });
+    },
     // 重置经纬度
     resetCoord(res, val, location, PointSumval) {
       this.$dialog
@@ -1681,7 +1810,6 @@ export default {
           PointSum: PointSumval,
           marklat: res.latitude,
           marklon: res.longitude,
-          linkType: 6,
         },
       });
     },
@@ -2399,13 +2527,16 @@ export default {
       this.onLoad();
     },
     onLoad() {
-      var postType = localStorage.getItem('postType');
-      if (postType == 'GZ') {
-        this.typeShow = false;
-      } else {
-        this.typeShow = true;
-      }
-      this.getUserOutPlaList();
+      // 授权
+      getTicketFun().then(() => {
+        var postType = localStorage.getItem('postType');
+        if (postType == 'GZ') {
+          this.typeShow = false;
+        } else {
+          this.typeShow = true;
+        }
+        this.getUserOutPlaList();
+      });
     },
     onLoadlong() {
       this.list = [];

+ 368 - 257
src/views/deviceWithin/index.vue

@@ -654,34 +654,40 @@ export default {
       }
       this.storeType = localStorage.getItem('storeType');
       this.endShow = false;
-      let loading1 = this.$toast.loading({
-        duration: 0,
-        message: '加载中...',
-        forbidClick: true,
-      });
+      this.toastLoading(0, '加载中...', true);
       localStorage.removeItem('visitId');
-      getPosition().then((res) => {
-        let { TXisBD } = res;
-        getUserInPlanList({
-          storeName: this.storeName.trim(),
-          genDate: this.genDate,
-          lat: TXisBD.lat,
-          lon: TXisBD.lon,
-        }).then((res) => {
-          loading1.clear();
-          if (res.code == 200) {
-            this.list = res.data;
-            this.list.forEach((item) => {
-              if (item.stateString.indexOf('拜访中') != -1) {
-                this.endShow = true;
-                this.visitEndId = item.visitId;
-                return;
-              }
-            });
-          } else {
-            this.$toast.fail(res.msg);
-          }
+      const isDevice = localStorage.getItem('isDevice');
+      getPosition(isDevice)
+        .then((res) => {
+          let { TXisBD } = res;
+          this.getUserInPlanListFun(TXisBD);
+        })
+        .catch((error) => {
+          this.$dialog.alert({
+            message: error,
+          });
         });
+    },
+    getUserInPlanListFun(TXisBD) {
+      getUserInPlanList({
+        storeName: this.storeName.trim(),
+        genDate: this.genDate,
+        lat: TXisBD.lat,
+        lon: TXisBD.lon,
+      }).then((res) => {
+        this.toastLoading().clear();
+        if (res.code == 200) {
+          this.list = res.data;
+          this.list.forEach((item) => {
+            if (item.stateString.indexOf('拜访中') != -1) {
+              this.endShow = true;
+              this.visitEndId = item.visitId;
+              return;
+            }
+          });
+        } else {
+          this.$toast.fail(res.msg);
+        }
       });
     },
     storeVisit(val) {
@@ -764,169 +770,184 @@ export default {
                 localStorage.setItem('ORGName', val.deptName);
                 localStorage.setItem('chainNameR', val.storeName);
               } else {
-                let loading1 = this.$toast.loading({
-                  duration: 0,
-                  message: '加载中...',
-                  forbidClick: true,
-                });
-                let url = window.location.href;
-                let wx = this.wx;
-                let qiyeData;
-                const instance = axios.create();
-                instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
-                instance
-                  .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
-                    params: {
-                      url: url,
-                    },
+                getPosition()
+                  .then((res) => {
+                    let { TXisBD, resData } = res;
+                    this.lat = TXisBD.lat;
+                    this.lon = TXisBD.lon;
+                    localStorage.setItem('lat', this.lat);
+                    localStorage.setItem('lon', this.lon);
+                    // var location = this.CJ02BD(res.latitude, res.longitude);
+                    this.checkStoreAddressByStoreCodeFun(val, TXisBD, resData);
                   })
-                  .then((response) => {
-                    if (response.status == 200) {
-                      this.cont = 3;
-                      var flat = true;
-                      var times = setInterval(() => {
-                        this.cont--;
-                        if (this.cont == '0') {
-                          if (flat) {
-                            loading1.clear();
-                            clearInterval(times);
-                            that.$dialog
-                              .alert({
-                                message: '定位失败,请开启企微定位权限',
-                              })
-                              .then(() => {});
-                          } else {
-                            clearInterval(times);
-                          }
-                        }
-                      }, 1000);
-                      qiyeData = response.data.data;
-                      wx.config({
-                        beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
-                        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
-                        appId: qiyeData.appId, // 必填,企业微信的corpID
-                        timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
-                        nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
-                        signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
-                        jsApiList: ['ready', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
-                      });
-                      wx.ready(() => {
-                        wx.getLocation({
-                          type: 'gcj02',
-                          success: (res) => {
-                            flat = false;
-                            var location = this.CJ02BD(res.latitude, res.longitude);
-                            this.location = location;
-                            checkStoreAddressByStoreCode({
-                              storeCode: val.storeCode,
-                              lon: location.lon,
-                              lat: location.lat,
-                            }).then((response) => {
-                              loading1.clear();
-                              if (val.lat == '' || val.lat == null) {
-                                that.lat = location.lat;
-                                that.lon = location.lon;
-                              } else {
-                                that.lat = val.lat;
-                                that.lon = val.lon;
-                              }
-                              let PointSum = that
-                                .twoPointSum(that.lat, that.lon, location.lat, location.lon)
-                                .toFixed(2);
-                              let PointSumval = that
-                                .twoPointSum(location.lat, location.lon, location.lat, location.lon)
-                                .toFixed(2);
-                              // GZ:工装店铺 直接进入拜访
-                              if (localStorage.getItem('postType') == 'GZ') {
-                                localStorage.setItem('startTime', new Date());
-                                localStorage.setItem('ORGName', val.deptName);
-                                localStorage.setItem('chainNameR', val.storeName);
-                                this.toSuishenbangOutstoreVisit(res, val, location, PointSumval);
-                                return;
-                              }
-                              // 门店编码校验门店地址不通过
-                              if (response.code != 200) {
-                                // updateAddress : ,1:同城AB+金牌,去修改地址;2:非金牌店铺,非同城店铺偏差过大不允许拜访,可以重置定位;0非金牌店铺,非同城店铺 位置信息不存在 可以继续拜访
-                                if (response.data.updateAddress == 0) {
-                                  // 非金牌店铺,非同城店铺 位置信息不存在 可以继续拜访
-                                  this.$dialog
-                                    .confirm({
-                                      confirmButtonText: '确定拜访',
-                                      cancelButtonText: '取消拜访',
-                                      title: '系统提示',
-                                      message:
-                                        '该客户没有经纬度,此次拜访会保存定位点作为客户经纬度,下次拜访时判断是否偏差过大。',
-                                      closeOnClickOverlay: true,
-                                    })
-                                    .then(() => {
-                                      this.toSuishenbangOutstoreVisit(
-                                        res,
-                                        val,
-                                        location,
-                                        PointSumval
-                                      );
-                                    });
-                                } else if (response.data.updateAddress == 1) {
-                                  // 同城AB+金牌,去修改地址
-                                  // addressUpdateTimesOver: true=已经达到最大次数,不让修改; false=没有达到可以修改
-                                  if (!response.data.addressUpdateTimesOver) {
-                                    this.$dialog
-                                      .confirm({
-                                        title: '系统提示',
-                                        message: response.msg + '请立即修改后再拜访',
-                                        messageAlign: 'left',
-                                        confirmButtonText: '立即修改',
-                                        cancelButtonText: '取消',
-                                      })
-                                      .then(() => {
-                                        this.$router.push({
-                                          path: '/storeDetail',
-                                          query: {
-                                            id: val.storeId,
-                                            type: 'address',
-                                            storeAddressId: val.storeAddressId,
-                                          },
-                                        });
-                                      });
-                                  } else {
-                                    this.$dialog.confirm({
-                                      title: '系统提示',
-                                      message: '已经达到最大修改次数',
-                                      messageAlign: 'left',
-                                      confirmButtonText: '确定',
-                                    });
-                                  }
-                                } else if (response.data.updateAddress == 2) {
-                                  // 1.非金牌店铺,非同城店铺 位置偏差过大 重置经纬度
-                                  this.resetCoord(res, val, location, PointSumval);
-                                  return;
-                                }
-                              } else {
-                                // 门店编码校验门店地址通过 进入拜访
-                                this.toSuishenbangOutstoreVisit(res, val, location, PointSumval);
-                              }
-                            });
-                          },
-                          fail: function () {
-                            loading1.clear();
-                            that.$dialog.alert({
-                              message: 'GPS未开启',
-                            });
-                          },
-                        });
-                      });
-                      wx.error(function (res) {
-                        loading1.clear();
-                        that.$dialog
-                          .alert({
-                            message: '定位失败,请开启企微定位权限',
-                          })
-                          .then(() => {});
-                      });
-                    } else {
-                      loading1.clear();
-                    }
+                  .catch((error) => {
+                    this.$dialog.alert({
+                      message: error,
+                    });
                   });
+                // let loading1 = this.$toast.loading({
+                //   duration: 0,
+                //   message: '加载中...',
+                //   forbidClick: true,
+                // });
+                // let url = window.location.href;
+                // let wx = this.wx;
+                // let qiyeData;
+                // const instance = axios.create();
+                // instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
+                // instance
+                //   .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
+                //     params: {
+                //       url: url,
+                //     },
+                //   })
+                //   .then((response) => {
+                //     if (response.status == 200) {
+                //       this.cont = 3;
+                //       var flat = true;
+                //       var times = setInterval(() => {
+                //         this.cont--;
+                //         if (this.cont == '0') {
+                //           if (flat) {
+                //             loading1.clear();
+                //             clearInterval(times);
+                //             that.$dialog
+                //               .alert({
+                //                 message: '定位失败,请开启企微定位权限',
+                //               })
+                //               .then(() => {});
+                //           } else {
+                //             clearInterval(times);
+                //           }
+                //         }
+                //       }, 1000);
+                //       qiyeData = response.data.data;
+                //       wx.config({
+                //         beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
+                //         debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
+                //         appId: qiyeData.appId, // 必填,企业微信的corpID
+                //         timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
+                //         nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
+                //         signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
+                //         jsApiList: ['ready', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
+                //       });
+                //       wx.ready(() => {
+                //         wx.getLocation({
+                //           type: 'gcj02',
+                //           success: (res) => {
+                //             flat = false;
+                //             var location = this.CJ02BD(res.latitude, res.longitude);
+                //             this.location = location;
+                //             checkStoreAddressByStoreCode({
+                //               storeCode: val.storeCode,
+                //               lon: location.lon,
+                //               lat: location.lat,
+                //             }).then((response) => {
+                //               loading1.clear();
+                //               if (val.lat == '' || val.lat == null) {
+                //                 that.lat = location.lat;
+                //                 that.lon = location.lon;
+                //               } else {
+                //                 that.lat = val.lat;
+                //                 that.lon = val.lon;
+                //               }
+                //               let PointSum = that
+                //                 .twoPointSum(that.lat, that.lon, location.lat, location.lon)
+                //                 .toFixed(2);
+                //               let PointSumval = that
+                //                 .twoPointSum(location.lat, location.lon, location.lat, location.lon)
+                //                 .toFixed(2);
+                //               // GZ:工装店铺 直接进入拜访
+                //               if (localStorage.getItem('postType') == 'GZ') {
+                //                 localStorage.setItem('startTime', new Date());
+                //                 localStorage.setItem('ORGName', val.deptName);
+                //                 localStorage.setItem('chainNameR', val.storeName);
+                //                 this.toSuishenbangOutstoreVisit(res, val, location, PointSumval);
+                //                 return;
+                //               }
+                //               // 门店编码校验门店地址不通过
+                //               if (response.code != 200) {
+                //                 // updateAddress : ,1:同城AB+金牌,去修改地址;2:非金牌店铺,非同城店铺偏差过大不允许拜访,可以重置定位;0非金牌店铺,非同城店铺 位置信息不存在 可以继续拜访
+                //                 if (response.data.updateAddress == 0) {
+                //                   // 非金牌店铺,非同城店铺 位置信息不存在 可以继续拜访
+                //                   this.$dialog
+                //                     .confirm({
+                //                       confirmButtonText: '确定拜访',
+                //                       cancelButtonText: '取消拜访',
+                //                       title: '系统提示',
+                //                       message:
+                //                         '该客户没有经纬度,此次拜访会保存定位点作为客户经纬度,下次拜访时判断是否偏差过大。',
+                //                       closeOnClickOverlay: true,
+                //                     })
+                //                     .then(() => {
+                //                       this.toSuishenbangOutstoreVisit(
+                //                         res,
+                //                         val,
+                //                         location,
+                //                         PointSumval
+                //                       );
+                //                     });
+                //                 } else if (response.data.updateAddress == 1) {
+                //                   // 同城AB+金牌,去修改地址
+                //                   // addressUpdateTimesOver: true=已经达到最大次数,不让修改; false=没有达到可以修改
+                //                   if (!response.data.addressUpdateTimesOver) {
+                //                     this.$dialog
+                //                       .confirm({
+                //                         title: '系统提示',
+                //                         message: response.msg + '请立即修改后再拜访',
+                //                         messageAlign: 'left',
+                //                         confirmButtonText: '立即修改',
+                //                         cancelButtonText: '取消',
+                //                       })
+                //                       .then(() => {
+                //                         this.$router.push({
+                //                           path: '/storeDetail',
+                //                           query: {
+                //                             id: val.storeId,
+                //                             type: 'address',
+                //                             storeAddressId: val.storeAddressId,
+                //                           },
+                //                         });
+                //                       });
+                //                   } else {
+                //                     this.$dialog.confirm({
+                //                       title: '系统提示',
+                //                       message: '已经达到最大修改次数',
+                //                       messageAlign: 'left',
+                //                       confirmButtonText: '确定',
+                //                     });
+                //                   }
+                //                 } else if (response.data.updateAddress == 2) {
+                //                   // 1.非金牌店铺,非同城店铺 位置偏差过大 重置经纬度
+                //                   this.resetCoord(res, val, location, PointSumval);
+                //                   return;
+                //                 }
+                //               } else {
+                //                 // 门店编码校验门店地址通过 进入拜访
+                //                 this.toSuishenbangOutstoreVisit(res, val, location, PointSumval);
+                //               }
+                //             });
+                //           },
+                //           fail: function () {
+                //             loading1.clear();
+                //             that.$dialog.alert({
+                //               message: 'GPS未开启',
+                //             });
+                //           },
+                //         });
+                //       });
+                //       wx.error(function (res) {
+                //         loading1.clear();
+                //         that.$dialog
+                //           .alert({
+                //             message: '定位失败,请开启企微定位权限',
+                //           })
+                //           .then(() => {});
+                //       });
+                //     } else {
+                //       loading1.clear();
+                //     }
+                //   });
               }
             }
           }
@@ -938,6 +959,93 @@ export default {
         }
       });
     },
+    checkStoreAddressByStoreCodeFun(val, location, res) {
+      checkStoreAddressByStoreCode({
+        storeCode: val.storeCode,
+        lon: location.lon,
+        lat: location.lat,
+      }).then((response) => {
+        // loading1.clear();
+        if (val.lat == '' || val.lat == null) {
+          this.lat = location.lat;
+          this.lon = location.lon;
+        } else {
+          this.lat = val.lat;
+          this.lon = val.lon;
+        }
+        // let PointSum = this.twoPointSum(this.lat, this.lon, location.lat, location.lon).toFixed(2);
+        let PointSumval = this.twoPointSum(
+          location.lat,
+          location.lon,
+          location.lat,
+          location.lon
+        ).toFixed(2);
+        // GZ:工装店铺 直接进入拜访
+        if (localStorage.getItem('postType') == 'GZ') {
+          localStorage.setItem('startTime', new Date());
+          localStorage.setItem('ORGName', val.deptName);
+          localStorage.setItem('chainNameR', val.storeName);
+          this.toSuishenbangOutstoreVisit(res, val, location, PointSumval);
+          return;
+        }
+        // 门店校验 地址不通过
+        if (response.code != 200) {
+          // updateAddress : ,1:同城AB+金牌,去修改地址;2:非金牌店铺,非同城店铺偏差过大不允许拜访,可以重置定位;0非金牌店铺,非同城店铺 位置信息不存在 可以继续拜访
+          if (response.data.updateAddress == 0) {
+            // 非金牌店铺,非同城店铺 位置信息不存在 可以继续拜访
+            this.$dialog
+              .confirm({
+                confirmButtonText: '确定拜访',
+                cancelButtonText: '取消拜访',
+                title: '系统提示',
+                message:
+                  '该客户没有经纬度,此次拜访会保存定位点作为客户经纬度,下次拜访时判断是否偏差过大。',
+                closeOnClickOverlay: true,
+              })
+              .then(() => {
+                this.toSuishenbangOutstoreVisit(res, val, location, PointSumval);
+              });
+          } else if (response.data.updateAddress == 1) {
+            // 同城AB+金牌,去修改地址
+            // addressUpdateTimesOver: true=已经达到最大次数,不让修改; false=没有达到可以修改
+            if (!response.data.addressUpdateTimesOver) {
+              this.$dialog
+                .confirm({
+                  title: '系统提示',
+                  message: response.msg + '请立即修改后再拜访',
+                  messageAlign: 'left',
+                  confirmButtonText: '立即修改',
+                  cancelButtonText: '取消',
+                })
+                .then(() => {
+                  this.$router.push({
+                    path: '/storeDetail',
+                    query: {
+                      id: val.storeId,
+                      type: 'address',
+                      storeAddressId: val.storeAddressId,
+                    },
+                  });
+                });
+            } else {
+              this.$dialog.confirm({
+                title: '系统提示',
+                message: '已经达到最大修改次数',
+                messageAlign: 'left',
+                confirmButtonText: '确定',
+              });
+            }
+          } else if (response.data.updateAddress == 2) {
+            // 1.非金牌店铺,非同城店铺 位置偏差过大 重置经纬度
+            this.resetCoord(res, val, location, PointSumval);
+            return;
+          }
+        } else {
+          // 门店编码校验门店地址通过 进入拜访
+          this.toSuishenbangOutstoreVisit(res, val, location, PointSumval);
+        }
+      });
+    },
     // 重置经纬度
     resetCoord(res, val, location, PointSumval) {
       this.$dialog
@@ -1503,77 +1611,80 @@ export default {
       });
     },
     goFn() {
-      let loading1 = this.$toast.loading({
-        duration: 0,
-        message: '加载中...',
-        forbidClick: true,
+      this.$router.push({
+        path: '/topStore',
       });
-      let url = window.location.href;
-      let wx = this.wx;
-      var that = this;
-      let qiyeData;
-      const instance = axios.create();
-      instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
-      instance
-        .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
-          params: {
-            url: url,
-          },
-        })
-        .then((response) => {
-          if (response.status == 200) {
-            this.cont = 5;
-            var flat = true;
-            var times = setInterval(() => {
-              this.cont--;
-              if (this.cont == '0') {
-                if (flat) {
-                  loading1.clear();
-                  clearInterval(times);
-                  that.$dialog.alert({
-                    message: '定位失败,请开启企微定位权限',
-                  });
-                } else {
-                  clearInterval(times);
-                }
-              }
-            }, 1000);
-            qiyeData = response.data.data;
-            wx.config({
-              beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
-              debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
-              appId: qiyeData.appId, // 必填,企业微信的corpID
-              timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
-              nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
-              signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
-              jsApiList: ['ready', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
-            });
-            wx.ready(function () {
-              wx.getLocation({
-                type: 'gcj02',
-                success: function (res) {
-                  flat = false;
-                  loading1.clear();
-                  that.$router.push({
-                    path: '/topStore',
-                  });
-                },
-                fail: function () {
-                  loading1.clear();
-                  that.$dialog.alert({
-                    message: 'GPS未开启',
-                  });
-                },
-              });
-            });
-            wx.error(function (res) {
-              loading1.clear();
-              that.$dialog.alert({
-                message: '定位失败,请开启企微定位权限',
-              });
-            });
-          }
-        });
+      // let loading1 = this.$toast.loading({
+      //   duration: 0,
+      //   message: '加载中...',
+      //   forbidClick: true,
+      // });
+      // let url = window.location.href;
+      // let wx = this.wx;
+      // var that = this;
+      // let qiyeData;
+      // const instance = axios.create();
+      // instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
+      // instance
+      //   .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
+      //     params: {
+      //       url: url,
+      //     },
+      //   })
+      //   .then((response) => {
+      //     if (response.status == 200) {
+      //       this.cont = 5;
+      //       var flat = true;
+      //       var times = setInterval(() => {
+      //         this.cont--;
+      //         if (this.cont == '0') {
+      //           if (flat) {
+      //             loading1.clear();
+      //             clearInterval(times);
+      //             that.$dialog.alert({
+      //               message: '定位失败,请开启企微定位权限',
+      //             });
+      //           } else {
+      //             clearInterval(times);
+      //           }
+      //         }
+      //       }, 1000);
+      //       qiyeData = response.data.data;
+      //       wx.config({
+      //         beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
+      //         debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
+      //         appId: qiyeData.appId, // 必填,企业微信的corpID
+      //         timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
+      //         nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
+      //         signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
+      //         jsApiList: ['ready', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
+      //       });
+      //       wx.ready(function () {
+      //         wx.getLocation({
+      //           type: 'gcj02',
+      //           success: function (res) {
+      //             flat = false;
+      //             loading1.clear();
+      //             that.$router.push({
+      //               path: '/topStore',
+      //             });
+      //           },
+      //           fail: function () {
+      //             loading1.clear();
+      //             that.$dialog.alert({
+      //               message: 'GPS未开启',
+      //             });
+      //           },
+      //         });
+      //       });
+      //       wx.error(function (res) {
+      //         loading1.clear();
+      //         that.$dialog.alert({
+      //           message: '定位失败,请开启企微定位权限',
+      //         });
+      //       });
+      //     }
+      //   });
     },
     formLink() {
       this.$router.push('/storeVisit/questions');

+ 38 - 25
src/views/home/login.vue

@@ -1,35 +1,42 @@
 <template>
   <div class="logins">
-    <br><br><br><br><br><br><br><br><br><br><br>
-    <div class="avsd" >门点拜访登录</div>
-    <br><br>
-    <br><br>
-    <van-field v-model="name" label="账号" placeholder="请输入账号"/>
-    <br><br><br><br>
-    <van-button type="info" size="small" plain class="Btn100" @click="login" style="margin:0 auto;">登录</van-button>
+    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
+    <div class="avsd">门点拜访登录</div>
+    <br /><br />
+    <br /><br />
+    <van-field v-model="name" label="账号" placeholder="请输入账号" />
+    <br /><br /><br /><br />
+    <van-button type="info" size="small" plain class="Btn100" @click="login" style="margin: 0 auto"
+      >登录</van-button
+    >
   </div>
 </template>
 <script>
 export default {
-  name: "login",
+  name: 'login',
   data() {
     return {
-      name: ""
-    }
+      name: '',
+    };
   },
   methods: {
     login() {
       localStorage.clear();
-      if (this.name.trim() != "") {
-        localStorage.setItem('loginName', this.name)
-        localStorage.removeItem('loginType')
-        this.$router.push("/")
+      if (this.name.trim() != '') {
+        // 当前设备:PC/mobile
+        let isDevice = window.navigator.userAgent.match(
+          /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
+        );
+        localStorage.setItem('isDevice', !isDevice ? 'PC' : 'mobile');
+        localStorage.setItem('loginName', this.name);
+        localStorage.removeItem('loginType');
+        this.$router.push('/');
       } else {
-        this.$toast("账号不能为空")
+        this.$toast('账号不能为空');
       }
-    }
-  }
-}
+    },
+  },
+};
 </script>
 
 <style scoped>
@@ -47,17 +54,23 @@ export default {
   height: 44px;
   font-size: 16px;
 }
-.avsd{
+.avsd {
   margin: 0 auto;
   width: 112px;
   font-size: 18px;
-  color:#0057ba;
+  color: #0057ba;
   animation: jump 3s ease infinite;
 }
-@keyframes jump{
-  0%{ transform:translateY(0) scale(1,1);}
+@keyframes jump {
+  0% {
+    transform: translateY(0) scale(1, 1);
+  }
   /* 中间状态图片位移并且拉伸 */
-  50%{transform:translateY(-20px) scale(0.97,1.03);}
-  100%{transform:translateY(0) scale(1,1);}
+  50% {
+    transform: translateY(-20px) scale(0.97, 1.03);
+  }
+  100% {
+    transform: translateY(0) scale(1, 1);
+  }
 }
-</style>
+</style>