// pages/home/map/map.js
const  app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        location:{},
        mapworkelist:[],
        inputValue:"",
        workelist:[],
        hasMarkers:true
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this
          that.setData({
            location:{
              'latitude':wx.getStorageSync('latitude'),
            'longitude':wx.getStorageSync('longitude')
          }
          })
          that.workDesc();
    },

    onHide(){
        wx.stopLocationUpdate({
            success: (res) => {
                console.log(res);
            },
          })
    },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        wx.stopLocationUpdate({
            success: (res) => {
                console.log(res);
            },
          })
    },

  //网点列表
  workDesc:function(e){
    var that=this;
    var keyword=that.data.inputValue;
    console.log(keyword);
    var latitude=wx.getStorageSync('latitude');
    var longitude=wx.getStorageSync('longitude');
  
    app.api.useApi(app.globalData.baseAppUrl + "api", {
      lat: latitude,
      lng: longitude,
      keyword: keyword,
      }, "get").then(function (res) {
        if (res.code != 200) {
            wx.showLoading({
                title: '网点加载失败'+res.status,
              })
        } else {
         var data=res.message.data.data
         that.setData({
            workelist:res.message.data.data
         })
         var maplist=[];
         for (var i = 0; i < data.length; ++i) {
          maplist[i]={
           
            'id':data[i]['id'],
            'latitude':data[i]['lat'],
            'longitude':data[i]['lng'],
            'iconPath': '/image/address/location.png',
            'width':100,
            'height':100
          }
           
        }
        that.setData({
          mapworkelist:maplist,
          hasMarkers:true
        })


        console.log(that.data.mapworkelist)
        }

        wx.hideLoading();

      }).catch(function (err) {
        console.log(222);
      })

},
bindKeyInput: function (e) {
  this.setData({
    inputValue: e.detail.value
  })
},
})