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

  /**
   * 页面的初始数据
   */
  data: {
    workelist:[],
    status:"",
    inputValue:"",
    pageindex: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.workDesc();
      this.setData({
        status:app.globalData.status
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({pageindex:this.data.pageindex+=1})
    this.workDesc()
  },


  //网点列表
  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,
      page: that.data.pageindex
      }, "get").then(function (res) {
        if (res.code != 200) {
            wx.showLoading({
                title: '网点加载失败'+res.status,
              })
            that.setData({pageindex: that.data.pageindex -= 1})
        } else {
          if (that.data.pageindex == 1) {
            that.setData({workelist: []})
          }
          if (res.message.data.data.length > 0) {
            that.setData({workelist: that.data.workelist.concat(res.message.data.data)})
          } else {
            that.setData({pageindex: that.data.pageindex -= 1})
          }
        }

        wx.hideLoading();

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

},
bindKeyInput: function (e) {
  this.setData({
    inputValue: e.detail.value
  })
},
setworke(e){
  console.log(e);
  const network_id=e.currentTarget.dataset.id
  var that=this;
  app.api.useApi(app.globalData.baseAppUrl+"api/user/"+network_id+"/setNetwork",{
  },"post").then(function(res){
    if (res.code == 200) {
      wx.showLoading({
        title: res.message.msg,
      })
      wx.setStorageSync('nid', network_id);
      setTimeout(function () {
        wx.switchTab({
          url: '/pages/tabber/home/index',
        })
        
        }, 1000)

 
     
     
    }
  }).catch(function(err){
    console.log(222);
  })
},
location(e){
  wx.openLocation({
    latitude: Number(e.currentTarget.dataset.lat),
    longitude:Number(e.currentTarget.dataset.lng)
  });
}

})