// pages/weighingRecord/info.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    floorstatus: false,
    autoplay: true,
    indicatorDots: false,
    interval: 5000,
    duration: 1000,
    bannerIMg: [], //顶部轮播图数组 '/images/carImg.jpeg'
    setCurrent: 1, //顶部轮播图的index,用于显示当前播放的是第几张图片

    stockTypeArr: [], //出入库类型
    storehouseTypeArr: [], //库房确认状态
    tareTypeArr: [], //皮重类型
    weightOperateTypeArr: [], //称重状态

    tareCaptureArr: [], //过皮抓拍照片
    grossCaptureArr: [], //过毛抓拍照片

    appointmentStatusArray:[],//预约状态

    type: '',
    info: {
      plateColor: '黄色'
    }
  },
  onClickLeft: function () {
    wx.navigateBack()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     //字典数据
     let treeData = app.globalData.treeArr
     for (const element of treeData) {
       let arrStr;
       switch (element.dictValue) {
         case 'appointment_status':
           arrStr = "appointmentStatusArray";
           break;
       }
       this.setData({
         [arrStr]: element.children
       })
     }
    this.setData({
      id: options.id
    })
    //获取详情
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    let getInfo = prevPage.data.resData[options.index]
    ///司机回签
    let unloadImgArray = []
    if(getInfo.unloadImg){
      let unloadImg = getInfo.unloadImg.split(',')
      unloadImg.forEach(element => {
        unloadImgArray.push({
          url:app.host.BASEIMG_URL+element
        })
      });
    }

    let bannerIMg = []
    let grossCaptureArr = [] //过毛图片
    let tareCaptureArr = [] //过皮图片
    if (getInfo.grossPlateName) {
      grossCaptureArr.push({
        name: '过毛车牌',
        url: getInfo.grossPlateName
      })
    }
    if (getInfo.grossLicenseName) {
      grossCaptureArr.push({
        name: '过毛车辆',
        url: getInfo.grossLicenseName
      })
    }
    if (getInfo.grossCaptureHead) {
      grossCaptureArr.push({
        name: '过毛车辆',
        url: getInfo.grossCaptureHead
      })
    }
    if (getInfo.grossCaptureTail) {
      grossCaptureArr.push({
        name: '过毛车辆',
        url: getInfo.grossCaptureTail
      })
    }
    if (getInfo.grossCaptureWare) {
      grossCaptureArr.push({
        name: '过毛车辆',
        url: getInfo.grossCaptureWare
      })
    }
    if (getInfo.grossCaptureBody) {
      grossCaptureArr.push({
        name: '过毛车辆',
        url: getInfo.grossCaptureBody
      })
    }
    if (getInfo.grossCapturePoundRoom) {
      grossCaptureArr.push({
        name: '过毛车牌',
        url: getInfo.grossCapturePoundRoom
      })
    }

    //过皮图片
    if (getInfo.tarePlateName) {
      tareCaptureArr.push({
        name: '过皮车辆',
        url: getInfo.tarePlateName
      })
    }
    if (getInfo.tareLicenseName) {
      tareCaptureArr.push({
        name: '过皮车辆',
        url: getInfo.tareLicenseName
      })
    }
    if (getInfo.tareCaptureHead) {
      tareCaptureArr.push({
        name: '过皮车辆',
        url: getInfo.tareCaptureHead
      })
    }
    if (getInfo.tareCaptureTail) {
      tareCaptureArr.push({
        name: '过皮车辆',
        url: getInfo.tareCaptureTail
      })
    }
    if (getInfo.tareCaptureWare) {
      tareCaptureArr.push({
        name: '过皮车辆',
        url: getInfo.tareCaptureWare
      })
    }
    if (getInfo.tareCaptureBody) {
      tareCaptureArr.push({
        name: '过皮车牌',
        url: getInfo.tareCaptureBody
      })
    }
    if (getInfo.tareCapturePoundRoom) {
      tareCaptureArr.push({
        name: '过皮车牌',
        url: getInfo.tareCapturePoundRoom
      })
    }
    bannerIMg = [...grossCaptureArr, ...tareCaptureArr]
    this.setData({
      info: getInfo,
      unloadImgArray:unloadImgArray,//签收图片
      bannerIMg, //过毛过皮所有图片
      grossCaptureArr,
      tareCaptureArr
    })
    //this.getInfo(options.id)
  },

  /**
   * 获取当前轮播的的序号用于显示
   * @param {*} event 
   */
  getCurrent: function (event) {
    this.setData({
      setCurrent: event.detail.current + 1
    })
  },

  //查询详情
  getInfo: function (id, url) {
    //详情
    app.request.requestGetApi(url, { 'id': id }, this, function (res, _that) {
      let getInfo = res.data.data;
      let setImgArr = []
      if (getInfo.grossCaptureBody) {
        setImgArr.push({
          name: '过毛车牌',
          url: getInfo.grossCaptureBody
        })
      }
      if (getInfo.grossCaptureHead) {
        setImgArr.push({
          name: '过毛车辆',
          url: getInfo.grossCaptureHead
        })
      }
      if (getInfo.grossCapturePoundRoom) {
        setImgArr.push({
          name: '过皮车牌',
          url: getInfo.grossCapturePoundRoom
        })
      }
      if (getInfo.grossCaptureTail) {
        setImgArr.push({
          name: '过皮车辆',
          url: getInfo.grossCaptureTail
        })
      }
      if (getInfo.grossCaptureWare) {
        setImgArr.push({
          name: '过皮车辆',
          url: getInfo.grossCaptureWare
        })
      }
      if (getInfo.grossLicenseName) {
        setImgArr.push({
          name: '过皮车辆',
          url: getInfo.grossLicenseName
        })
      }
      if (getInfo.grossPlateName) {
        setImgArr.push({
          name: '过皮车辆',
          url: getInfo.grossPlateName
        })
      }
      //
      if (getInfo.tareCaptureBody) {
        setImgArr.push({
          name: '过毛车牌',
          url: getInfo.tareCaptureBody
        })
      }
      if (getInfo.tareCaptureHead) {
        setImgArr.push({
          name: '过毛车辆',
          url: getInfo.tareCaptureHead
        })
      }
      if (getInfo.tareCapturePoundRoom) {
        setImgArr.push({
          name: '过皮车牌',
          url: getInfo.tareCapturePoundRoom
        })
      }
      if (getInfo.tareCaptureTail) {
        setImgArr.push({
          name: '过皮车辆',
          url: getInfo.tareCaptureTail
        })
      }
      if (getInfo.tareCaptureWare) {
        setImgArr.push({
          name: '过皮车辆',
          url: getInfo.tareCaptureWare
        })
      }
      if (getInfo.tareLicenseName) {
        setImgArr.push({
          name: '过皮车辆',
          url: getInfo.tareLicenseName
        })
      }
      if (getInfo.tarePlateName) {
        setImgArr.push({
          name: '过皮车辆',
          url: getInfo.tarePlateName
        })
      }
      _that.setData({
        info: getInfo,
        bannerIMg: setImgArr,
        // tareCaptureArr: tareCaptureArr,
        // grossCaptureArr:grossCaptureArr
      })

      //派车方式字典
      app.request.requestGetApi(app.API.api.getDispatchType, {}, _that, function (result, _this) {
        let resData = result.data.data;
        _this.setData({
          dispatchTypeArray:resData,
          dispatchTypeTxt:app.util.getDicName(resData, getInfo.dispatchType, 'code', 'value')
        })
      })
      //派车状态字典
      app.request.requestGetApi(app.API.api.getDispatchStatus, {}, _that, function (result, _this) {
        let resData = result.data.data;
        _this.setData({
          dispatchStatusArray:resData,
          dispatchStatusTxt:app.util.getDicName(resData, getInfo.dispatchStatus, 'code', 'value')
        })
      })


      //派车详情
      app.request.requestGetApi(app.API.api.dispatchVehicleDetail, { 'id': getInfo.dispatchVehicleId }, _that, function (result, that) {
        let getDispatchInfo = result.data.data
        that.setData({
          dispatchInfo: getDispatchInfo,
          dispatchTypeTxt:app.util.getDicName(that.data.dispatchTypeArray, getDispatchInfo.dispatchType, 'code', 'value'),
          dispatchStatusTxt:app.util.getDicName(that.data.dispatchStatusArray, getDispatchInfo.dispatchStatus, 'code', 'value')
        })
        console.log('getDispatchInfo:::',getDispatchInfo)
        //进出方式
        app.request.requestGetApi(app.API.api.getExitMethod, {}, that, function (getresult, setThat) {
          setThat.setData({
            exitMethodTxt:app.util.getDicName(getresult.data.data, getDispatchInfo.exitMethod, 'code', 'value')
          })
        })

      })



    })
  },

  // 获取滚动条当前位置
  onPageScroll: function (e) {
    if (e.scrollTop > 180) {
      this.setData({
        'floorstatus': true
      });
    } else {
      this.setData({
        'floorstatus': false
      });
    }
    // app.util.checkOnPageScroll(e, this, 'floorstatus')
  },

})