{
    template:'${tmpl}',
    data:function(){
        return {
          location: {
            lat: 40.121643,
            lng: 116.662091
          },
          Arr: [],
          distance: 1,
          cityName: "",
          address: "",
          activeIndex: '1',
          key: "1",
          mkey: "",
          total: 0,
          size: 10,
          page: 1,
          activeName:1,
          a:false,
          b:false,
          showcondi:true,
          resultshow:true,
      }
    },
    mounted:function(){
      this.baiduMap()

    },
    created:function(){


    },
    methods:{
      baiduMap: function () {
        this.createMap();
        this.setMapEvent();
        this.addMapControl();
      },
      search: function () {
        this.createMap();
        this.setMapEvent();
        this.addMapControl();
        this.addMarker2();
        this.addMarker();
      },
      addresslbs: function () {

        if(this.address==""||this.distance==""){
          this.$message.warning("请输入目标地址和距离范围");
        }else{
          var params =
            {
              address: this.address,
              distance: this.distance,
              pageSize: this.size,
              currentPage: this.page
            };
          console.log(params);
          var that=this;
          this.$root.postReq("/web/lbsCtl/addressSearch",params).then(function(d){
            console.log("[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]");
            console.log(d.data);
            var Arr = d.data.list;
            if(Arr){
              that.Arr = Arr;
              that.location.lat = Arr[0].self_location[1];
              that.location.lng = Arr[0].self_location[0];
              that.search();
              that.mkey = "2";
              that.total = d.data.totalSize;
              console.log(that.total);
              that.a=true;
              that.b=false;
            }else{
              that.b=true;
              that.a=false;
              return false;
            }
            that.resultshow=false;
            that.showcondi=false;
          });
        }
      },
      lallbs: function () {
        if(this.location.lng==""||this.location.lat==""||this.distance==""){
          this.$message.warning("请输入目标经度、目标纬度和距离范围");
        }else{
          var params =
            {
              lat: this.location.lat,
              lng: this.location.lng,
              distance: this.distance,
              pageSize: this.size,
              currentPage: this.page
            };
          console.log("2334---------", params);
          var that=this;
          this.$root.postReq("/web/lbsCtl/lalSearch",params).then(function(d){
            console.log("[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]");
            console.log(d.data.list);
            var Arr = d.data.list;
            if(Arr){
              that.Arr = Arr;
              console.log("1", Arr);
              that.search();
              that.mkey = "2";
              that.total = d.data.totalSize;
              console.log(that.total);
              that.a=true;
              that.b=false;
            }else{
              that.b=true;
              that.a=false;
              return false;
            }
            that.showcondi=false;
            that.resultshow=false;
          });

        }
      },
      citylbs: function () {
        if(this.cityName==""){
          this.$message.warning("请输入城市名称");
        }else{
          var params =
            {
              cityName: this.cityName,
              pageSize: this.size,
              currentPage: this.page
            };
          console.log("2334---------", params);
          var that=this;
          this.$root.postReq("/web/lbsCtl/citySearch",params).then(function(d){
            console.log("[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]");
            console.log(d.data.list);
            var Arr = d.data.list;
            if(Arr){
              that.Arr = Arr;
              that.location.lat = Arr[0].self_location[1];
              that.location.lng = Arr[0].self_location[0];
              that.search();
              that.mkey = "3";
              that.total = d.data.totalSize;
              that.a=true;
              that.b=false;
            }else{
              this.b=true;
              this.a=false;
              return false;

            }
            that.showcondi=false;
            that.resultshow=true;
          });
        }
      },
      createMap: function () {
        console.log(111111111111111111111111);
        var map = new BMap.Map("dituContent",{enableMapClick:false});
        var location = this.location;
        console.log(location);
        var point = new BMap.Point(location.lng, location.lat);
        map.centerAndZoom(point, 16);
        window.map = map;
      },
      setMapEvent: function () {
        map.enableDragging();
        map.enableScrollWheelZoom();
        map.enableDoubleClickZoom();
        map.enableKeyboard();
      },

      addMapControl: function () {
        var ctrl_nav = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_LEFT, type: BMAP_NAVIGATION_CONTROL_LARGE});
        map.addControl(ctrl_nav);
        var ctrl_ove = new BMap.OverviewMapControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, isOpen: 1});
        map.addControl(ctrl_ove);
        var ctrl_sca = new BMap.ScaleControl({anchor: BMAP_ANCHOR_BOTTOM_LEFT});
        map.addControl(ctrl_sca);
      },
      addMarker() {
        let Arr = this.Arr;
        let point = new Array();
        let marker = new Array();
        let info = new Array();
        for (let i = 0; i < Arr.length; i++) {
          let infoA = Arr[i].company_location[0];
          let infoB = Arr[i].company_location[1];
          console.log(Arr[i].company_name+":"+infoA+","+infoB);
          point[i] = new window.BMap.Point(infoA, infoB);
          marker[i] = new window.BMap.Marker(point[i]);
          map.addOverlay(marker[i]);
          let opts={
            width:400,
            height:100
          };
          let content="<p style='font-size:12px;line-height:1.8em;'>" + "</br>" + Arr[i].company_name + "</br> 地址："+ Arr[i].company_address +  "</br> 成立时间：" + Arr[i].estiblish_time + "</p>";
          for(let j=0;j<Arr.length;j++){
            if(i!=j && Arr[i].company_location[0]==Arr[j].company_location[0] && Arr[i].company_location[1]==Arr[j].company_location[1]){
              let cont="<p style='font-size:12px;line-height:1.8em;'>" + "</br>" + Arr[j].company_name + "</br> 地址："+ Arr[j].company_address +  "</br> 成立时间：" + Arr[j].estiblish_time + "</p>";
              content+=cont;
            }
          }
          info[i] = new window.BMap.InfoWindow("<div style='overflow-y:auto;height:100px;width:400px'>"+content+"</div>",opts);
          console.log(info[i]);
          marker[i].addEventListener("mouseover", function () {
            this.openInfoWindow(info[i]);
          });
        }
      },
      addMarker2() {
        let point = "";
        let marker = "";
        let info = "";
        let infoA = this.location.lng;
        let infoB = this.location.lat;
        point = new window.BMap.Point(infoA, infoB);
        marker = new window.BMap.Marker(point);

        let Icon = new BMap.Icon("http://api.map.baidu.com/img/markers.png", new BMap.Size(23, 25), {
          offset: new BMap.Size(10, 25),
          imageOffset: new BMap.Size(0, 0 - 10 * 25)
        });
        marker.setIcon(Icon);
        map.addOverlay(marker);
      },

      handleSelect(key, keyPath) {
        console.log(key, keyPath);
        $("#maind"). scrollTop(0);
        if(key==="4"){
          this.resultshow=true;
          return;
        }
        if (key === "1") {
          this.key = "1";
          this.a=false;
          this.b=false;
          this.showcondi=true;

        } else if (key === "2") {
          this.key = "2";
          this.a=false;
          this.b=false;
          this.showcondi=true;
        }else{
          this.key="3";
          this.a=false;
          this.b=false;
          this.showcondi=true;
        }
     },
     handleChange(val) {
      console.log(val);
    },
    handleCurrentChange(val) {
      this.page = val;
      console.log(`当前 ${val} 页`);
      if (this.mkey === "1") {
        this.addresslbs();
      } else if (this.mkey === "3") {
        this.citylbs();
      } else {
        this.lallbs();
      }
    },
    handleSizeChange(val) {
      this.size = val;
      console.log(`每页 ${val} 条`);
      if (this.mkey === "1") {
        this.addresslbs();
      } else if (this.mkey === "3") {
        this.citylbs();
      } else {
        this.lallbs();
      }
    },

},
    vname:"gsb-h5lbs"
}
