// pages/index/info.js
const app = getApp()
var QRCode = require('../../utils/weapp-qrcode.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: {},
    fileList:[], //司机回签图片

    appointmentTypeArray: [{
      dictValue: "",
      dictLabel: "全部状态"
    }],
    appointmentTypeIndex: 0,

    appointmentClassifyArray: [
      { label:'充电预约',value:'1' },
      { label:'管桩预约',value:'2' },
      { label:'其他预约',value:'3' },
    ], //预约类型
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    //订单类型
    let treeData = app.globalData.treeArr
    for (const element of treeData) {
      let arrStr;
      switch (element.dictValue) {
        case 'appointment_type':
          arrStr = "appointmentTypeArray";
          break;
      }
      this.setData({
        [arrStr]: element.children
      })
    }
    //获取详情
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    let getInfo = prevPage.data.resData[options.index]
    //司机回签图片
    let fileList = []
    if(getInfo.unloadImg){
      let unloadImgArr = getInfo.unloadImg.split(',')
      unloadImgArr.forEach(element => {
        fileList.push({
          url     : app.host.BASEIMG_URL+element,
          imgUrl  : element,
          isImage : true
        })
      });
    }
    this.setData({
      info      : getInfo,
      fileList  : fileList
    })
    // 预约类型
    if(getInfo.appointmentType == '5'){
      // 管桩预约
      this.getPipeplanData(getInfo.orderId)
    }

    if(getInfo.status!='1'||getInfo.status!='2'||getInfo.status!='10'||getInfo.status!='11'||getInfo.status!='12'||getInfo.status!='13'||getInfo.status!='14'||getInfo.status!='15'){
      this.makeCode(JSON.stringify({
        "id": getInfo.id,
        "licenseNumber":getInfo.licenseNumber
      }))
    }

  },

  // 二维码
  makeCode(data) {
    var qrcode;
    qrcode = new QRCode('canvas', {
      text: data,
      width: 220,
      height: 220,
      colorDark: "#000000",
      colorLight: "#ffffff",
      correctLevel: QRCode.CorrectLevel.H,
    });
    qrcode.makeCode(data);
  },

  // 管桩计划详情
  getPipeplanData: function (id) {
    app.request.GET({
      url: app.API.bizpipeplanDetail,
      params: {'id' : id},
      page: this,
      successFun: true
    }).then(res => {
      let getInfo = res.data.data;
      this.setData({
        planNumber      : getInfo.planNumber,
        planName        : getInfo.planName,
        planCount       : getInfo.planCount,
        planAlreadyCount: getInfo.planAlreadyCount,
        beginTime       : getInfo.beginTime,
        endTime         : getInfo.endTime,
      })
    })
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})