<template>
  <!-- 辅料运输派单 -->
  <div class="homeworkPath">
    <div class="top">
      <el-input
        placeholder="请输入内容"
        class="input"
        v-model="input"
        clearable
      >
      </el-input>
      <span class="text">下发时间：</span>
      <el-date-picker
        v-model="startTime"
        type="datetime"
        placeholder="选择日期"
      >
      </el-date-picker>
      <span class="text">至</span>
      <el-date-picker v-model="endTime" type="datetime" placeholder="选择日期">
      </el-date-picker>
      <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";
import { sjTime } from "@/utils/sharedJsFile";
export default {
  name: "inplantTMS",
  data() {
    return {
      startTime: null,
      endTime: null,
      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&orderType=5&orderStatus=4&i=" +
            new Date() +
            "&carrierSSOId=" +
            getCookie("userId");
        } else if (val == "first") {
          this.option1.requestUrl =
            "/api/v1/oms/getTransportDispatch?apiId=148&orderType=5&orderStatus=5&i=" +
            new Date() +
            "&carrierSSOId=" +
            getCookie("userId");
        } else if (val == "second") {
          this.option1.requestUrl =
            "/api/v1/oms/getTransportDispatch?apiId=241&orderType=5&orderStatus=6&i=" +
            new Date() +
            "&carrierSSOId=" +
            getCookie("userId");
        }
      } else {
        if (val == "option") {
          this.option.requestUrl =
            "/api/v1/oms/getTransportDispatch?apiId=148&orderType=5&orderStatus=4&i=" +
            new Date() +
            "&carrierSSOId=" +
            null;
        } else if (val == "first") {
          this.option1.requestUrl =
            "/api/v1/oms/getTransportDispatch?apiId=148&orderType=5&orderStatus=5&i=" +
            new Date() +
            "&carrierSSOId=" +
            null;
        } else if (val == "second") {
          this.option1.requestUrl =
            "/api/v1/oms/getTransportDispatch?apiId=241&orderType=5&orderStatus=6&i=" +
            new Date() +
            "&carrierSSOId=" +
            null;
        }
      }
    },
  },
  created() {
    //判断是否是承运商
    if (getCookie("orgCode") == "chengyunshang") {
      this.option.requestUrl =
        "/api/v1/oms/getTransportDispatch?apiId=148&orderType=5&orderStatus=4&carrierSSOId=" +
        getCookie("userId");
      this.option1.requestUrl =
        "/api/v1/oms/getTransportDispatch?apiId=148&orderType=5&orderStatus=5&carrierSSOId=" +
        getCookie("userId");
      this.option2.requestUrl =
        "/api/v1/oms/getTransportDispatch?apiId=241&orderType=5&orderStatus=6&carrierSSOId=" +
        getCookie("userId");
    } else {
      this.option.requestUrl =
        "/api/v1/oms/getTransportDispatch?apiId=148&orderType=5&orderStatus=4&carrierSSOId=" +
        null;
      this.option1.requestUrl =
        "/api/v1/oms/getTransportDispatch?apiId=148&orderType=5&orderStatus=5&carrierSSOId=" +
        null;
      this.option2.requestUrl =
        "/api/v1/oms/getTransportDispatch?apiId=241&orderType=5&orderStatus=6&carrierSSOId=" +
        null;
    }
  },
  methods: {
    getRequestUrl() {
      //判断是否是承运商
      if (getCookie("orgCode") == "chengyunshang") {
        this.option.requestUrl =
          "/api/v1/oms/getTransportDispatch?apiId=148&orderType=5&orderStatus=4&carrierSSOId=" +
          getCookie("userId") +
          "&i=" +
          new Date();
        this.option1.requestUrl =
          "/api/v1/oms/getTransportDispatch?apiId=148&orderType=5&orderStatus=5&carrierSSOId=" +
          getCookie("userId") +
          "&i=" +
          new Date();
        this.option2.requestUrl =
          "/api/v1/oms/getTransportDispatch?apiId=241&orderType=5&orderStatus=6&carrierSSOId=" +
          getCookie("userId") +
          "&i=" +
          new Date();
      } else {
        this.option.requestUrl =
          "/api/v1/oms/getTransportDispatch?apiId=148&orderType=5&orderStatus=4&carrierSSOId=" +
          null +
          "&i=" +
          new Date();
        this.option1.requestUrl =
          "/api/v1/oms/getTransportDispatch?apiId=148&orderType=5&orderStatus=5&carrierSSOId=" +
          null +
          "&i=" +
          new Date();
        this.option2.requestUrl =
          "/api/v1/oms/getTransportDispatch?apiId=241&orderType=5&orderStatus=6&carrierSSOId=" +
          null +
          "&i=" +
          new Date();
      }
    },
    onclick() {
      if (getCookie("orgCode") == "chengyunshang") {
        if (this.activeName == "option") {
          this.option.requestUrl =
            "/api/v1/oms/getTransportDispatch?apiId=148&orderType=5&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&orderType=5&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&orderType=5&orderStatus=6&con=" +
            this.input +
            "&i=" +
            new Date() +
            "&carrierSSOId=" +
            getCookie("userId");
        }
      } else {
        let startTime = null;
        let endTime = null;
        if (this.startTime) {
          startTime = sjTime(this.startTime);
        }
        if (this.endTime) {
          endTime = sjTime(this.endTime);
        }
        if (startTime && endTime) {
          if (startTime < endTime) {
            if (this.activeName == "option") {
              this.option.requestUrl =
                "/api/v1/oms/getTransportDispatch?apiId=148&orderType=5&orderStatus=4&con=" +
                this.input +
                "&i=" +
                new Date() +
                "&carrierSSOId=" +
                null +
                "&startTime=" +
                startTime +
                "&endTime=" +
                endTime;
            } else if (this.activeName == "first") {
              this.option1.requestUrl =
                "/api/v1/oms/getTransportDispatch?apiId=241&orderType=5&orderStatus=5&con=" +
                this.input +
                "&i=" +
                new Date() +
                "&carrierSSOId=" +
                null +
                "&startTime=" +
                startTime +
                "&endTime=" +
                endTime;
            } else if (this.activeName == "second") {
              this.option2.requestUrl =
                "/api/v1/oms/getTransportDispatch?apiId=241&orderType=5&orderStatus=6&con=" +
                this.input +
                "&i=" +
                new Date() +
                "&carrierSSOId=" +
                null +
                "&startTime=" +
                startTime +
                "&endTime=" +
                endTime;
            }
          }
        } else {
          if (this.activeName == "option") {
            this.option.requestUrl =
              "/api/v1/oms/getTransportDispatch?apiId=148&orderType=5&orderStatus=4&con=" +
              this.input +
              "&i=" +
              new Date() +
              "&carrierSSOId=" +
              null;
          } else if (this.activeName == "first") {
            this.option1.requestUrl =
              "/api/v1/oms/getTransportDispatch?apiId=241&orderType=5&orderStatus=5&con=" +
              this.input +
              "&i=" +
              new Date() +
              "&carrierSSOId=" +
              null;
          } else if (this.activeName == "second") {
            this.option2.requestUrl =
              "/api/v1/oms/getTransportDispatch?apiId=241&orderType=5&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.getRequestUrl();
            }
          });
      }
    },
    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>