// pages/day/day.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    winHeight: 0,
    newcity:[],
    city:'',
    lat:'',
    lng:''
  },
  cityTap(e) {
    console.log('fasdfsdfsdfds');
    console.log(e);
    const cityName = e.detail.cityname.name;
    console.log(cityName)
    if (cityName==undefined){
      this.setData({
        city: e.detail.cityname
      })
    }else{
      this.setData({
        city: e.detail.cityname.name
      })
    }
   

   console.log(this.data.city)

    this.getjingwei();


    setTimeout(function(){
    wx.switchTab({
      url: '/pages/index/index',
    })
    },1500)
    
   
    // wx.navigateBack();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const win = wx.getSystemInfoSync();
    console.log(win);
    this.setData({
      winHeight: win.windowHeight
    });

    // this.gethotcity()
  },

  //根据城市获取经纬度
  getjingwei() {
    let that = this;
    var url = 'index/category/get_lng_lat';
    var params = {
      city: that.data.city,

    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        lat:res.data.lat,
        lng:res.data.lng
      })

     

      console.log(this.data.city);
      console.log(this.data.lat);
      console.log(this.data.lng)
      wx.setStorageSync('city', this.data.city)
      wx.setStorageSync('lat', this.data.lat)
      wx.setStorageSync('lng', this.data.lng)

    }).catch((err) => {

    })
  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})