// packageH/flightInformation/flightInformationDetail/flightInformationDetail.js
const app = getApp();
// import utils from '../../../utils/util';
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options){
      this.setData({
        id:options.id,
        form_id:options.form_id
      });
    }
    this.getData();
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },
  getData(e){
    let that = this;
    let urlStr = app.getNetAddresss('plugin.flight-collect.frontend.index.get-form-details');
    app._getNetWork({
      url: urlStr,
      data:{
        form_id:that.data.form_id,
        id:that.data.id
      },
      success: (resdata) => {
        let res = resdata.data;
        if (res.result == 1) {
          res.data.diy_from.status = 1; 
          res.data.form_data.flight_time = this.formatTimeTwo(res.data.form_data.flight_time,'Y/M/D');
          that.setData({
            dfData:res.data.diy_from,
            from:res.data.form_data,
          });
          wx.setNavigationBarTitle({
            title: '航班信息收集记录',
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 1000
          });
        }
      },
      fail: function (res) {
        console.log(res.msg);
      }
    });
  },
  formatNumber(n) {
    n = n.toString();
    return n[1] ? n : '0' + n;
  },
  formatTimeTwo(number, format) {
    var formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
    var returnArr = [];
    var date = new Date(number * 1000);
    returnArr.push(date.getFullYear());
    returnArr.push(this.formatNumber(date.getMonth() + 1));
    returnArr.push(this.formatNumber(date.getDate()));
    returnArr.push(this.formatNumber(date.getHours()));
    returnArr.push(this.formatNumber(date.getMinutes()));
    returnArr.push(this.formatNumber(date.getSeconds()));
    for (var i in returnArr) {
      format = format.replace(formateArr[i], returnArr[i]);
    }
    return format;
  }
});