const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    transportName:null,
    transport:null,
    driverName:null,
    plateNum:null,
    //运输类型id  10 汽车 20船 30火车 40飞机 50其他
    transportType:[
      {name:'汽车',type:'10'},
      {name:'船运',type:'20'},
      {name:'火车',type:'30'},
      {name:'飞机',type:'40'},
      {name:'其他',type:'50'},
    ],
  },
  setTransportName(e){
    this.setData({
      transportName:e.detail.value
    })
  },
  setDriverName(e){
    this.setData({
      driverName:e.detail.value
    })
  },
  setPlateNum(e){
    this.setData({
      plateNum:e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const {transportName,transport,driverName,plateNum,code,uid} = options;
    this.setData({
      transportName,driverName,plateNum,code,uid
    })
    this.setOptonsType(transport)
  },
  setOptonsType(transport){
    var transportType = this.data.transportType;
    for(var i=0;i<transportType.length;i++){
      if(transport == transportType[i].name){
        this.setData({
          transport:i
        })
        break;
      }
    }
  },
  setTransportType(e){
    var value = e.detail.value;
    this.setData({
      transport:value+''
    })
  },
  addLabel(){
    const {transportName,transport,driverName,plateNum,code,uid} = this.data;
    this.updteVvmTransportOrder({transportName,transport,driverName,plateNum,code,uid})
  },
  updteVvmTransportOrder(form){
    var that = this;
    app.requestP({
      url: '/transport/updteVvmTransportOrder',
      method: 'post',
      contentType: 'application/json',
      data: form
    }).then(res=>{
      app.showToptip(that, 'success', res.data.msg);
      wx.navigateBack({
        delta: 1,
      })
    }).catch(err=>{
      app.showToptip(that, 'error', err.data.msg)
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})