// pages/queueCar/adjustOrder.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showModal: false,
    defaultText: '请选择',
    isSubmitting: false,

    beginTime:'',
    endTime:'',

    orderArray: [], //订单
    orderIndex: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     //获取详情
     var pages = getCurrentPages();
     var prevPage = pages[pages.length - 2];
     let getInfo = prevPage.data.resData[options.index]
    this.setData({
      id:options.id,
      orderId: options.orderId,
      info: getInfo,
      beginTime:getInfo.beginTime,
      endTime:getInfo.endTime,
    })
    this.getSelectData()
  },

  //获取订单下拉列表
  getSelectData: function () {
    //获取订单下拉列表
    app.request.GET({
      url: app.API.bizorderPage,
      params: {},
      page: this,
      successFun: true
    }).then(res => {
      this.setData({
        orderArray:res.data.data,
        orderIndex: app.util.getDicIndex(res.data.data, this.data.orderId, 'id'),
      })
    })

  },

  //下拉选择
  bindPickerChange: function (e) { //下拉菜单
    let { pickername } = e.target.dataset
    let getIndex = pickername + 'Index'
    app.util.getPickerIndex(this, getIndex, e);
    switch (pickername) {
      case 'order': //收货单位一级
      app.request.GET({
        url: app.API.queryByOrderId,
        params: {
          id:this.data.orderArray[this.data.orderIndex].id
        },
        page: this,
        successFun: true
      }).then(res => {
        let {confStartTime,confEndTime} = res.data.data
        this.setData({
          beginTime:confStartTime,
          endTime:confEndTime,
        })
      })
        break;
    }
  },

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

  },

  //表单提交
  formSubmit: function ({detail: { value }}) {
    let formData = value;
    var warn = ""; //弹框时提示的内容
    if (typeof formData.orderId == 'undefined' || formData.orderId == '') {
      warn = "请选择订单！";
    }
    if (warn != '') {
      app.util.checkForm(warn);
    } else {
      app.request.POST({
        url: app.API.lineUpAdjust,
        params: value,
        page: this,
        isLoadingTxt: '调度中...',
        isSubmitting: true,
        successFun: true
      }).then(res => {
        wx.showToast({
          title: '调度成功',
          icon: 'success',
          duration: 2000,
          mask:true,
          complete: function () {
            setTimeout(() => {
              wx.navigateBack()
            }, 1500) //延迟时间  
          }
        })
      })

    }
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})