var amapFile = require('../../utils/amap-wx.js');
var app = getApp();

Page({
  data: {
    city:"天津",
    weather:"晴",
    temperature:"10",
    windpower:"18级",
    winddirection:"南",
    humidity:"5",
  },
  onLoad: function(options){
    var that = this;
    var myAmapFun = new amapFile.AMapWX({key:'78a99442f6e5cad3bfb832e33bdcf629'});
    myAmapFun.getWeather({
      success: function(res){
        //成功回调
        console.log("调取天气接口成功", res)
        // 一定要在接口里进行赋值，否则接口数据还未返回，页面就已经将数据取走进行显示
        that.setData({
          city: res.city.data,
          weather: res.weather.data,
          temperature: res.temperature.data,
          windpower: res.windpower.data,
          winddirection: res.winddirection.data,
          humidity: res.humidity.data
        })
      },
      fail: function(info){
        //失败回调
        console.log(info)
      }
    })
  }
})