const Parse = getApp().Parse
const company = getApp().globalData.company
Page({

  /**
   * 页面的初始数据
   */
  data: {
    steps: [
    ],
    active:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let {
      num,
      com,
      phone
    } = options
    this.setData({
      num,
      com
    })
    num && this.getExpress()
    com && this.getExpressCompany(com)
  },
  getExpress() {
    let {
      num,
      com,
      phone
    } = this.data
    let data = {
      company:company,
      num,
      com,
      phone
    }
    let url = `https://server.fmode.cn/api/apig/express/consult`
    wx.request({
      url: url,
      data: data,
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: (result) => {
        if(result?.data.code == 200){
          let steps = []
          let data = result.data.data.data
          console.log(data);
          data.forEach(item => {
            let obj = {
              text: item.context,
              desc: item.time,
              activeIcon: 'checked',
            }
            steps.push(obj)
          });
          this.setData({
            steps
          })
          let com = data = result.data.data.com
          this.getExpressCompany(com)
          return
        }
        console.log(result);
      },
      fail: () => {},
      complete: () => {}
    });
  },
  async getExpressCompany(com){
    let query = new Parse.Query('ExpressCompany')
    query.equalTo('code',com)
    let r = await query.first()
    if(r?.id){
      this.setData({
        companyText:r.get('name')
      })
    }
  },
  onCopy(){
    let { num } = this.data
    wx.setClipboardData({
      data: num,
      success: (result)=>{
        wx.showToast({
          title: '复制成功',
          icon: 'success',
          image: '',
          duration: 1500,
          mask: false,
        });
      },
      fail: ()=>{},
      complete: ()=>{}
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})