//采购化工材料运输预约
<template>
  <div >
    <div style="margin:10px">
      <el-select v-model="condition1" placeholder="请选择筛选条件"  style="width:150px" clearable>
          <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
          </el-option>
      </el-select>
      <el-input
          placeholder="请输入内容"
          v-model="input1"
          style="width:200px"
          clearable
      >
      </el-input>
      <el-select v-model="condition2" placeholder="请选择筛选条件" style="width:150px" clearable>
          <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
          </el-option>
      </el-select>
      <el-input
          placeholder="请输入内容"
          v-model="input2"
          style="width:200px"
          clearable
      >
      </el-input>
      <span class="text" v-if="activeName == 'second'">下发时间：</span>
      <el-date-picker
        v-if="activeName == 'second'"
        v-model="startTime"
        type="datetime"
        placeholder="选择日期"
      >
      </el-date-picker>
      <span class="text" v-if="activeName == 'second'">至</span>
      <el-date-picker
        v-if="activeName == 'second'"
        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="insertClick">
        <i class="el-icon-plus"></i>新增
      </el-button>
      <el-button
        type="primary"
        class="btn"
        @click="issue"
        v-if="activeName == 'first'"
      >
        <i class="el-icon-download"></i>下发
      </el-button>
    </div>
    <el-tabs v-model="activeName">
      <!-- 未下发 -->
      <el-tab-pane label="未下发" name="first">
        <dilTable
          v-bind.sync="option1"
          ref="table"
          @selection-change="selectionChange"
        >
          <el-table-column
            fixed="right"
            align="center"
            label="操作"
            width="120"
          >
            <template slot-scope="scope">
              <el-button
                @click="sendClick(scope.row.orderId)"
                type="text"
                size="small"
              >
                下发
              </el-button>
              <el-button
                @click="updateClick(scope.row.orderId)"
                type="text"
                size="small"
              >
                修改
              </el-button>
              <el-button
                @click="
                  deleteClick(scope.row.orderId, scope.row.capacityNumber)
                "
                type="text"
                size="small"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </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 {
      condition1:null,
      condition2:null,
      input1:null,
      input2:null,
      options:[
          {
          label:"车牌号",
          value:"capacityNumber"
          },
          {
          label:"物资名称",
          value:"materialName"
          },
          {
          label:"发货单位",
          value:"supplierName"
          },
          {
          label:"采购订单",
          value:"purchaseOrderNo"
          }
          
      ],
      input: "",
      Time: "",
      startTime: null,
      endTime: null,
      activeName: "first",
      option1: {
        // 表格请求数据的地址
        requestUrl: "",
        selectionType: "select",
        mapList: [],
      },
      option2: {
        // 表格请求数据的地址
        requestUrl: "",
      },
    };
  },

  activeName(val) {
    if (val == "first") {
      if (getCookie("orgCode") == "chengyunshang") {
        this.option1.requestUrl =
          "/api/v1/oms/getAllTruckOrder?apiId=141&orderStatus=3&fuelOrder=2&carrierSSOId=" +
          getCookie("userId") +
          "&i=" +
          new Date();
      } else {
        this.option1.requestUrl =
          "/api/v1/oms/getAllTruckOrder?apiId=141&orderStatus=3&fuelOrder=2&carrierSSOId=" +
          null +
          "&i=" +
          new Date();
      }
    } else {
      if (getCookie("orgCode") == "chengyunshang") {
        this.option2.requestUrl =
          "/api/v1/oms/getAllTruckOrder?apiId=243&orderStatus=111&fuelOrder=2&carrierSSOId=" +
          getCookie("userId") +
          "&i=" +
          new Date();
      } else {
        this.option2.requestUrl =
          "/api/v1/oms/getAllTruckOrder?apiId=243&orderStatus=111&fuelOrder=2&carrierSSOId=" +
          null +
          "&i=" +
          new Date();
      }
    }
  },

  created() {
    //判断是否是承运商
    if (getCookie("orgCode") == "chengyunshang") {
      this.option1.requestUrl =
        "/api/v1/oms/getAllTruckOrder?apiId=141&orderStatus=3&fuelOrder=2&carrierSSOId=" +
        getCookie("userId");
      this.option2.requestUrl =
        "/api/v1/oms/getAllTruckOrder?apiId=243&orderStatus=111&fuelOrder=2&carrierSSOId=" +
        getCookie("userId");
    } else {
      this.option1.requestUrl =
        "/api/v1/oms/getAllTruckOrder?apiId=141&orderStatus=3&fuelOrder=2&carrierSSOId=" +
        null;
      this.option2.requestUrl =
        "/api/v1/oms/getAllTruckOrder?apiId=243&orderStatus=111&fuelOrder=2&carrierSSOId=" +
        null;
    }
  },
  methods: {
    getRequestUrl() {
      //判断是否是承运商
      if (getCookie("orgCode") == "chengyunshang") {
        this.option1.requestUrl =
          "/api/v1/oms/getAllTruckOrder?apiId=141&orderStatus=3&fuelOrder=2&carrierSSOId=" +
          getCookie("userId") +
          "&i=" +
          new Date();
        this.option2.requestUrl =
          "/api/v1/oms/getAllTruckOrder?apiId=243&orderStatus=111&fuelOrder=2&carrierSSOId=" +
          getCookie("userId") +
          "&i=" +
          new Date();
      } else {
        this.option1.requestUrl =
          "/api/v1/oms/getAllTruckOrder?apiId=141&orderStatus=3&fuelOrder=2&carrierSSOId=" +
          null +
          "&i=" +
          new Date();
        this.option2.requestUrl =
          "/api/v1/oms/getAllTruckOrder?apiId=243&orderStatus=111&fuelOrder=2&carrierSSOId=" +
          null +
          "&i=" +
          new Date();
      }
    },
    onclick() {
       let requestQuery={}
      if(this.condition1 == this.condition2){
            requestQuery[this.condition1]=[this.input1,this.input2]
        }else{
            requestQuery[this.condition1]=[this.input1+'']
            requestQuery[this.condition2]=[this.input2+'']
        }
      if (this.activeName == "first") {
        //判断是否是承运商
        if (getCookie("orgCode") == "chengyunshang") {
          this.option1.requestUrl =
            "/api/v1/oms/getAllTruckOrder?apiId=141&orderStatus=3&fuelOrder=2&carrierSSOId=" +
            getCookie("userId")
        } else {
          this.option1.requestUrl =
            "/api/v1/oms/getAllTruckOrder?apiId=141&orderStatus=3&fuelOrder=2&carrierSSOId=" +
            null
        }
        this.option1.requestQuery=requestQuery;
      } 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 (getCookie("orgCode") == "chengyunshang") {
              this.option2.requestUrl =
                "/api/v1/oms/getAllTruckOrder?apiId=243&orderStatus=111&fuelOrder=2&carrierSSOId=" +
                getCookie("userId") +
                "&startTime=" +
                startTime +
                "&endTime=" +
                endTime +
                "&i=" +
                new Date();
            } else {
              this.option2.requestUrl =
                "/api/v1/oms/getAllTruckOrder?apiId=243&orderStatus=111&fuelOrder=2&carrierSSOId=" +
                null +
                "&startTime=" +
                startTime +
                "&endTime=" +
                endTime +
                "&i=" +
                new Date();
            }
          } 
          this.option2.requestQuery=requestQuery;
        }else{
            console.log("我进来了");
            //判断是否是承运商
            if (getCookie("orgCode") == "chengyunshang") {
              this.option2.requestUrl =
                "/api/v1/oms/getAllTruckOrder?apiId=243&orderStatus=111&fuelOrder=2&carrierSSOId=" +
                getCookie("userId") +
                "&i=" +
                new Date();
            } else {
              this.option2.requestUrl =
                "/api/v1/oms/getAllTruckOrder?apiId=243&orderStatus=111&fuelOrder=2&carrierSSOId=" +
                null +
                "&i=" +
                new Date();
            }
            this.option2.requestQuery=requestQuery;
        }
      }
      this.$forceUpdate();
    },

    selectionChange(selection) {
      this.mapList = selection;
    },
    issue() {
      let mapvalue = {
        mapList: this.mapList,
      };
      this.axios.post("/api/v1/oms/dispatchOrder", mapvalue).then(() => {
        this.$message({
          type: "success",
          message: "下发成功!",
        });
        this.getRequestUrl();
      });
    },
    // 下发
    sendClick(orderId) {
      let mapvalue = {
        mapList: [{ orderId: orderId }],
      };
      this.$confirm("是否下发", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.axios.post("/api/v1/oms/dispatchOrder", mapvalue).then(() => {
            this.$message({
              type: "success",
              message: "下发成功!",
            });
            this.getRequestUrl();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消下发!",
          });
        });
    },
    // 删除
    deleteClick(orderId, capacityNumber) {
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.axios
            .post("/api/v1/oms/deleteOrder", {
              orderId: orderId,
              capacityNumber: capacityNumber,
            })
            .then(() => {
              this.getRequestUrl();
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除!",
          });
        });
    },
    //新增
    insertClick() {
      this.$router.push("/transportationReservationAdd");
    },
    //修改
    updateClick(orderId) {
      this.$router.push("/transportationReservationEDIT/" + orderId);
    },
  },
};
</script>
<style lang='scss' scoped>
.homeworkPath {
  .top {
    padding: 40px;
    .input {
      width: 250px;
      margin-right: 20px;
    }
    .btn {
      margin-right: 10px;
    }
  }
}
</style>