App({
  post: function (url, data, headerParams) {
    wx.showNavigationBarLoading()

    var promise = new Promise((resolve, reject) => {
      let that = this;
      let postData = data;
      let baseUrl = 'https://einp.net/api';
      let header = {
        'content-type': 'application/x-www-form-urlencoded'
      }
      header = Object.assign(header, headerParams)
      wx.request({
        url: baseUrl + url,
        data: postData,
        method: 'POST',
        header: header,
        success: function (res) {
          resolve(res)
          setTimeout(function () {
            wx.hideLoading()
          }, 600)
          wx.hideNavigationBarLoading()
        },
        error: function (e) {
          reject('');
          wx.hideLoading()
          wx.hideNavigationBarLoading()
          wx.showModal({
            title: '',
            content: res.data.msg,
            showCancel: false
          })
        }
      })
    });
    wx.hideLoading()
    return promise;
  },

  nowDate(later) {
    let date = new Date();
    date.setDate(date.getDate() + later);
    let month = date.getMonth() + 1;
    let day = date.getDate();
    return date.getFullYear() + '/' + (month > 9 ? month : ('0' + month)) + '/' + (day > 9 ? day : ('0' + day));
  },

  globalData: {
    userInfo: null
  }
})