点击判断地址是否在已设置的电子围栏内

532 阅读1分钟

点击判断地址是否在已设置的电子围栏内

setSiteMessage(e) { //用户选择地址信息
    const index = e.currentTarget.dataset.index
    const pages = getCurrentPages(),
      prevPage = pages[pages.length - 2];
    const data = {
      latitude: this.data.listData[index].latitude,
      longitude: this.data.listData[index].longitude,
      id: this.data.listData[index].id,
      defaultVal: this.data.listData[index].defaultVal, //页面跳转类型,可忽略
      communityId: this.data.communityId, //小区id,可忽略
    }
      if (!data.latitude){ //选择的地址没有经纬度则跳转至编辑地址页
        app.commonTip('地址id和经纬度为必填项'); //提示
        var timerTem = setTimeout(function () { //定时器
          wx.navigateTo({
            url: `/pages/address/add-site?id=${data.id}&status=${data.defaultVal}`
          })
        }, 800)
        this.setData({
          timer: timerTem
        })
      }else{
        address.isRange(data).then(res => { //调用判断电子围栏的接口
          if (res.success == true) {
            if (res.d.isInMapFence == true) { //true:在电子围栏内 false:不在电子围栏内
              if (prevPage.route != 'pages/myInfo/index') { //判断页面跳转,可忽略
                if (!this.data.type) console.error('选择的地址类型不存在');
                const info = this.data.listData[index], //上一个页面
                  typeName = this.data.type;
                if (typeName == 'pickup') {
                  const pickupAddress = {
                    name: info.name,
                    phone: info.phone,
                    address: info.address,
                    id: info.id
                  }
                  prevPage.setData({
                    receiveName: info.name,
                    receivePhone: info.phone,
                    receiveProvinceName: info.provinceName,
                    receiveCityName: info.cityName,
                    receiveDistrictName: info.districtName,
                    receiveAddress: info.address,
                    pickupAddress: pickupAddress,
                    addressTag: ''
                  })
                } else {
                  prevPage.setData({
                    [`${typeName}Address`]: info,
                  })
                }
                wx.setStorageSync('counte', 0)
                wx.navigateBack({
                  delta: 1
                })
              }
            } else {
              app.commonTip(res.d.msg);
              return false;
            }
          } else {
            app.commonTip(res.d.msg);
            return false;
          }
        })
    }
  },