//新增运输派单
//新增运输订单
<template>
  <div class="addSaleOrderSend">
    <page-title>新增运输订单派车</page-title>
    <!-- 零星订单表的数据 -->
    <div class="saleOrder">
      <dilTable
        v-bind.sync="option"
        @radio-change="currentRadioChange"
      ></dilTable>
    </div>
    <!-- 表单选择车辆-->
    <div class="from">
      <div class="vehicle">
        <span class="text">车辆</span>
        <el-button type="primary" @click="onClick(2)">浏览</el-button>
        <span class="span"></span>
      </div>
    </div>
    <!-- 派车表格 -->
    <div class="selectionTable from">
      <el-table
        :data="selectionList"
        border
        style="width: 100%"
        highlight-current-row
      >
        <el-table-column type="index" label="序号" width="50">
        </el-table-column>
        <el-table-column
          v-for="(item, i) in tableTop"
          :key="i"
          :prop="item.prop"
          :label="item.label"
          :width="item.width"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <!-- 操作列 -->
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button
              @click="deleteRow(scope.$index)"
              type="text"
              icon="el-icon-close"
              size="big"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 车辆模态框 -->
    <el-drawer 
      :visible.sync="truckDrawer" 
      :with-header="false"
      :destroy-on-close="false"
      direction="rtl"
      size="40%"
      :show-close="false"
      :wrapperClosable="false"
      modal
      close-on-press-escape
    
    >
      <el-input
        placeholder="请输入内容"
        v-model="truckText"
        style="margin-top: 10px; margin-left: 20px; width: 250px"
        clearable
      >
      </el-input>
      <el-button
        type="primary"
        class="btn"
        @click="selectTruckClick"
        style="margin-left: 5px"
      >
        <i class="el-icon-search"></i>查询
      </el-button>
      <el-button
        type="primary"
        class="btn"
        @click="AddTruckClick"
        style="margin-left: 5px"
      >
        <i class="el-icon-check"></i>确定
      </el-button>
      <div class="tablecls">
        <!-- 查询所有的车辆 -->
        <dilTable
          v-bind.sync="truck"
          @selection-change="currentRadioChange1"
        ></dilTable>
      </div>
    </el-drawer>
    <div class="button_box">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="makeSure" :disabled = "disabled" >确定</el-button>
    </div>
  </div>
</template>
<script>
import PageTitle from "@/components/Page/Title";
import { getCookie } from "@/utils/util.js";
import { sjTime,isNumber } from "@/utils/sharedJsFile";
export default {
  components: { PageTitle },
  data() {
    return {
      disabled:false,
      //零星订单ID
      sporadicOrderId:null,
      //运输订单ID
      orderId:null,
      //线路名称
      lineName:null,
      //已经选择车辆物资信息
      selectionList:[],
      //销售订单物资信息
      option: {
        // 表格请求数据的地址
        requestUrl:"",
        // 控制显示当选列
        selectionType: "radio",
        isPagination: false,
      },
      //当前选中的物资id
      materialId: null,
      //当前选中的物资名称
      materialName: null,   
      //是否打开选择车辆的模态框
      truckDrawer:false,
      //车辆的表格
      truck: {
        requestUrl: "",
        selectionType: "select",
      },
      tableTop: [
        {
          prop: "capacityNumber",
          label: "车牌号",
        }
      ],
      truckText:null,
      //当前多选选中的车辆
      selectTruck:[],
    };
  },
  created() {
    if (getCookie("orgCode") == "chengyunshang") {
      this.truck.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" +
        getCookie("userId");
        this.option.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=439&issueStatus=1&orderType=12&dispatchStatus=0&carrierSsoId=" + getCookie("userId");
    } else if(getCookie("orgCode") == "dagangadmin" || getCookie("orgCode") == "zidonghuabu" || getCookie("orgCode") == "wuliuchuyunzhongxin"){
      this.truck.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" + null;
        this.option.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=439&issueStatus=1&orderType=12&dispatchStatus=0&sporadicStatus=0";
    }else if(getCookie("orgCode") == "biemeierchejian") {
      this.truck.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" + null + "&con=" + "铁专线精煤"; 
      this.option.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=439&issueStatus=1&orderType=12&dispatchStatus=0&sporadicStatus=0&userId=" + getCookie("orgCode");
    }
    else{
        this.truck.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" + null;
        this.option.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=439&issueStatus=1&orderType=12&dispatchStatus=0&sporadicStatus=0&userId=" + getCookie("orgCode");
    }
  },
  methods: {
    //点击确定按钮的事件
    makeSure(){
       console.log(this.selectionList)
        this.disabled = true
        console.log(this.orderId)
        if(this.orderId == null){
          this.$message.error("未勾选零星订单")
          this.disabled = false
          return 
        }else if(this.selectionList.length == 0){
          this.$message.error("未选择车辆")
          this.disabled = false
          return
        }
        this.axios.post('/api/v1/ams/addSporadicOrderTimes',{
          orderId:this.orderId,
          sporadicOrderId:this.sporadicOrderId,
          mapList:this.selectionList,
        }).then((res)=>{
          if(res.data.code == '200'){
            this.$message.success('派车成功')
            this.disabled = false
            this.cancel();
          }
        })
    },
    //点击取消按钮的事件
    cancel(){
      this.$router.push('/sporadicTransportOrder')
    },
    //点击删除按钮删除当前点击的对象
    deleteRow(index){
      this.selectionList.splice(index,1)
    },
    //车辆模态框的确定事件
    AddTruckClick(){
      this.selectTruck.forEach(e => {
        this.selectionList.push({
          capacityId:e.capacityId,
          capacityNumber:e.capacityNumber,
        })
      });
      this.truckDrawer = false;
    },
    //车辆模态框框计算
    selectTruckClick(){
      if(this.truckText != null){
        if (getCookie("orgCode") == "chengyunshang") {
        this.truck.requestUrl =
          "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" +
          getCookie("userId") + "&index="+this.truckText;
      }else if(getCookie("orgCode") == "biemeierchejian") {
      this.truck.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" + null + "&con=" + "铁专线精煤" + "&index="+this.truckText;; 
      
    } 
      else {
        this.truck.requestUrl =
          "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" + null + "&index="+this.truckText;
      }
        this.truckText = null
      }else{
         if (getCookie("orgCode") == "chengyunshang") {
        this.truck.requestUrl =
          "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" +
          getCookie("userId") + "&i=" + new Date()
      }else if(getCookie("orgCode") == "biemeierchejian") {
      this.truck.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" + null + "&con=" + "铁专线精煤" + + "&i=" + new Date(); 
    } 
      else {
        this.truck.requestUrl =
          "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" + null + "&i=" + new Date()
      }
      }
    
    },
    //车辆表格
    currentRadioChange1(select){
      this.selectTruck = [];
      this.selectTruck = select;
    },
    //主界面表格单选
    currentRadioChange(row) {
      console.log(row)
      this.sporadicOrderId = row.sporadicOrderId
      this.orderId = row.orderId
    },
    onClick() {
      if(getCookie("orgCode") == "chengyunshang") {
      this.truck.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" +
        getCookie("userId") + "&t=" + new Date();
    }else if(getCookie("orgCode") == "biemeierchejian") {
      this.truck.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" + null + "&con=" + "铁专线精煤" + "&t=" + new Date();
    }
     else {
      this.truck.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=429&carrierSsoId=" + null  + "&t=" + new Date();
    } 
      this.truckDrawer = true
    },
  },
};
</script>
<style lang='scss'>
.addSaleOrderSend {
  .el-drawer__body {
   overflow: auto;
  }
  .el-drawer__container ::-webkit-scrollbar{
    display: none;
  }
  .from {
    margin-top: 20px;
    .line {
      display: flex;
      justify-content: center;
      align-items: center;
      .el-input {
        width: 250px;
        margin-left: 10px;
        margin-right: 10px;
      }
    }
    .vehicle {
      display: flex;
      justify-content: center;
      align-items: center;
      margin-top: 20px;
      .el-button {
        width: 250px;
        margin-left: 10px;
        margin-right: 10px;
      }
      .span {
        width: 70px;
      }
    }
  }
  .tablecls{
    margin-top: 20px;
  }
  .button_box{
    display: flex;
    justify-content: center;
    margin: 20px;
    .el-button{
      width: 100px;
      margin-left: 20px;
    }
  }
}
</style>