Explorar o código

pc端无定位依然支持访问,计划内没有定位优化

zhujindu hai 1 ano
pai
achega
4b3386ff39
Modificáronse 1 ficheiros con 263 adicións e 161 borrados
  1. 263 161
      src/views/deviceWithin/index.vue

+ 263 - 161
src/views/deviceWithin/index.vue

@@ -770,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();
+                //     }
+                //   });
               }
             }
           }
@@ -944,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