<template>
  <!-- 燃料运输派单 -->
  <div class="homeworkPath">
    <div class="top">
      <el-input
        placeholder="请输入内容"
        class="input"
        v-model="input"
        clearable
      >
      </el-input>
      <el-button type="primary" class="btn" @click="onclick">
        <i class="el-icon-search"></i>查询
      </el-button>
      <el-button type="primary" class="btn" @click="clickClose" v-if="activeName == 'option'">
        <i class="el-icon-close"></i>关闭
      </el-button>
    </div>
    <el-tabs v-model="activeName">
      <el-tab-pane label="未接收" name="option">
        <dilTable v-bind.sync="option" @selection-change="selectionChange"> </dilTable>
      </el-tab-pane>
      <el-tab-pane label="已接收" name="first">
        <dilTable v-bind.sync="option1"> </dilTable>
      </el-tab-pane>
      <el-tab-pane label="已拒绝" name="second">
        <dilTable v-bind.sync="option2"> </dilTable>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { getCookie } from "@/utils/util.js";
export default {
  name: "inplantTMS",
  data() {
    return {
      input: "",
      Time: "",
      activeName: "option",
      option: {
        // 表格请求数据的地址
        requestUrl:"",
        selectionType: "select",
      },
      option1: {
        // 表格请求数据的地址
        requestUrl:"",
      },
      option2: {
        // 表格请求数据的地址
        requestUrl:"",
      },
      list:[],
    };
  },
  watch:{
    activeName(val){
      if (getCookie("orgCode") == "chengyunshang") {
        if(val == "option"){
          this.option.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=148&fuelOrder=1&orderStatus=4&i="+new Date()+"&carrierSSOId=" + null;
        }else if(val == "first"){
          this.option1.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=148&fuelOrder=1&orderStatus=5&i="+new Date()+"&carrierSSOId=" + null;
        }else if(val == "second"){
          this.option1.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=241&fuelOrder=1&orderStatus=6&i="+new Date()+"&carrierSSOId=" + null;
        }
      }else{
        if(val == "option"){
          this.option.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=148&fuelOrder=1&orderStatus=4&i="+new Date()+"&carrierSSOId=" + null;
        }else if(val == "first"){
          this.option1.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=148&fuelOrder=1&orderStatus=5&i="+new Date()+"&carrierSSOId=" + null;
        }else if(val == "second"){
          this.option1.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=241&fuelOrder=1&orderStatus=6&i="+new Date()+"&carrierSSOId=" + null;
        }
      }
      
    }
  },
  created() {
    //判断是否是承运商
    if (getCookie("orgCode") == "chengyunshang") {
      this.option.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=148&fuelOrder=1&orderStatus=4&carrierSSOId=" + getCookie("userId");
      this.option1.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=148&fuelOrder=1&orderStatus=5&carrierSSOId=" + getCookie("userId");
      this.option2.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=241&fuelOrder=1&orderStatus=6&carrierSSOId=" + getCookie("userId");
    } else {
      this.option.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=148&fuelOrder=1&orderStatus=4&carrierSSOId=" + null;
      this.option1.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=148&fuelOrder=1&orderStatus=5&carrierSSOId=" + null;
      this.option2.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=241&fuelOrder=1&orderStatus=6&carrierSSOId=" + null;
    }
  },
  methods: {
    onclick() {
    if (getCookie("orgCode") == "chengyunshang") {
       if(this.activeName == "option"){
        this.option.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=148&fuelOrder=1&orderStatus=4&con=" + this.input +"&i="+new Date() + "&carrierSSOId=" + getCookie("userId");
      }else if (this.activeName == "first") {
        this.option1.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=241&fuelOrder=1&orderStatus=5&con=" + this.input +"&i="+new Date() + "&carrierSSOId=" + getCookie("userId");
      } else if (this.activeName == "second") {
        this.option2.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=241&fuelOrder=1&orderStatus=6&con=" + this.input +"&i="+new Date() + "&carrierSSOId=" + getCookie("userId");
      }
    }else{
      if(this.activeName == "option"){
        this.option.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=148&fuelOrder=1&orderStatus=4&con=" + this.input +"&i="+new Date() + "&carrierSSOId=" + null;
      }else if (this.activeName == "first") {
        this.option1.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=241&fuelOrder=1&orderStatus=5&con=" + this.input +"&i="+new Date() + "&carrierSSOId=" + null;
      } else if (this.activeName == "second") {
        this.option2.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=241&fuelOrder=1&orderStatus=6&con=" + this.input +"&i="+new Date() + "&carrierSSOId=" + null;
      }
    }
      
    },
    clickClose(){
      console.log(this.list)
      if(this.list.length == 0){
        this.$message.warning('请选择订单之后在关闭')
      }else{
        this.axios.post('/api/v1/oms/deleteOrders',{list:this.list}).then((res)=>{
          if(res.data.code == "200"){
            this.$message.success('关闭成功')
            this.option.requestUrl = "/api/v1/oms/getTransportDispatch?apiId=148&fuelOrder=1&orderStatus=4&con=" + this.input +"&i="+new Date();
          }
        })
      }

    },
    selectionChange(selection){
      this.list = [],
      selection.forEach(e => {
        this.list.push(e.orderId)
      });
    }
  },
};
</script>
<style lang='scss'>
.homeworkPath {
  .top {
    padding: 40px;
    .input {
      width: 250px;
      margin-right: 10px;
    }
  }
}
</style>