//运输预约展现
<template>
  <!-- 零星物资运输预约 -->
  <div class="homeworkPath">
    <div class="top">
      <el-input placeholder="请输入内容" 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" @click="insertClick">
        <i class="el-icon-plus"></i>新增
      </el-button>
      <el-button
        type="primary"
        @click="sendClick()"
        v-if="this.activeName == 'first'"
      >
        <i class="el-icon-bottom"></i>下发
      </el-button>
    </div>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <!-- 未下发 -->
      <el-tab-pane label="未下发" name="first">
        <dilTable
          v-bind.sync="option1"
          ref="table"
          @selection-change="selectionChange"
        >
          <el-table-column
            fixed="right"
            label="操作"
            width="120"
          >
            <template slot-scope="scope">
              <el-button @click="deleteClick(scope)" 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">
          <el-table-column
            fixed="right"
            label="操作"
            width="100"
          >
            <template slot-scope="scope">
              <el-button @click="stopSpoOrder(scope)" type="text" size="small">
                停止
              </el-button>
            </template>
          </el-table-column>
        </dilTable>
      </el-tab-pane>
       <!-- 已接单 -->
      <el-tab-pane label="已接单" name="third">
        <dilTable v-bind.sync="option3">
        </dilTable>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { getCookie } from "@/utils/util.js";
export default {
  name: "inplantTMS",
  data() {
    return {
      input: null,
      Time: "",
      activeName: "first",
      option1: {
        // 表格请求数据的地址
        requestUrl:
          "",
        // 控制显示多选列
        selectionType: "select",
      },
      option2: {
        // 表格请求数据的地址
        requestUrl:
          "",
      },
      option3: {
        // 表格请求数据的地址
        requestUrl:
          "",
      },
      selection: [],
      maplist:[]
    };
  },
  created(){
      if(getCookie("orgCode") == "dagangadmin" || getCookie("orgCode") == "zidonghuabu"){
            this.option1.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=428&issueStatus=0&orderType=15&dispatchStatus=0",
            this.option2.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=428&issueStatus=1&orderType=15&sporadicStatus=1",
            this.option3.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&type1=1"       
      }else{
            this.option1.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=428&issueStatus=0&orderType=15&dispatchStatus=0&userId=" + getCookie("orgCode"),
            this.option2.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=428&issueStatus=1&orderType=15&sporadicStatus=1&userId=" + getCookie("orgCode"),
            this.option3.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&type1=1&userId=" + getCookie("orgCode")
      }
  },
  methods: {
    getRequestUrl(){
      if(getCookie("orgCode") == "dagangadmin" || getCookie("orgCode") == "zidonghuabu"){
            this.option1.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=428&issueStatus=0&orderType=15&dispatchStatus=0&test=" + new Date(),
            this.option2.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=428&issueStatus=1&orderType=15&sporadicStatus=1&test=" + new Date(),
            this.option3.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&type1=1&test=" + new Date()
      }else{
            this.option1.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=428&issueStatus=0&orderType=15&dispatchStatus=0&userId=" + getCookie("orgCode") + "&test=" + new Date(),
            this.option2.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=428&issueStatus=1&orderType=15&sporadicStatus=1&userId=" + getCookie("orgCode") + "&test=" + new Date(),
            this.option3.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&type1=1&userId=" + getCookie("orgCode") + "&test=" + new Date()
     }
    },
    stopSpoOrder(scope){
      this.$confirm("是否停止", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.axios
            .post("/api/v1/ams/closeSporadicOrder" ,{
              sporadicOrderId : scope.row.sporadicOrderId
            })
            .then((res) => {
              if (res.data.code == 200) {
                this.$message({
                  type: "success",
                  message: "成功停止!",
                });
              this.getRequestUrl()
              } else {
                this.$message({
                  message: "停止失败",
                  type: "warning",
                });
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "停止操作已取消!",
          });
        });
    },
    //获取选中的订单
    selectionChange(selection) {
      this.maplist = selection;
    },
    onclick() {
      if(this.input != null){
        if(getCookie("orgCode") == "dagangadmin" || getCookie("orgCode") == "zidonghuabu")
        {
          if(this.activeName == "first"){
            this.option1.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=428&issueStatus=0&orderType=15&dispatchStatus=0&con=" + this.input
          }else if(this.activeName == "second"){
            this.option2.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=428&issueStatus=1&orderType=15&sporadicStatus=1&con=" + this.input
          }else{
            this.option3.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=11&con=" + this.input
          }                
        }else
        {
          if(this.activeName == "first"){
            this.option1.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=428&issueStatus=0&orderType=15&dispatchStatus=0&userId=" + getCookie("orgCode") + "&con=" + this.input
          }else if(this.activeName == "second"){
            this.option2.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=428&issueStatus=1&orderType=15&sporadicStatus=1&userId=" + getCookie("orgCode") + "&con=" + this.input
          }else{
            this.option3.requestUrl = "/api/v1/oms/getOthersOrderMesToSend?apiId=386&type=3&orderStatus=11&userId=" + getCookie("orgCode") + "&con=" + this.input
          }       
        }
        }else{
        this.$message.warning("未输入查询条件")
        }
    },
    handleClick(tab, event) {
      this.getRequestUrl()
    },
    // 下发
    sendClick() {
      if(this.maplist.length == 0){
        this.$message.warning('未选择零星订单')
        return
      }
      this.axios
        .post("/api/v1/ams/issueSporadicOrders", this.maplist)
        .then((res) => {
          if (res.data.code == "200") {
            this.getRequestUrl()
            // this.$router.go(0)
            this.$message({
              type: "success",
              message: "下发成功!",
            });
            this.maplist = []
          }
        });
    },
    // 删除
    deleteClick(scope) {
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.axios
          .post(
          "/api/v1/ams/deleteSporadicOrders?sporadicOrderId=" +
            scope.row.sporadicOrderId
            )
            .then((res) => {
              if (res.data.code == 200) {
                this.$message({
                  type: "success",
                  message: "成功删除!",
                });
              this.getRequestUrl()
              } else {
                this.$message({
                  message: "删除失败",
                  type: "warning",
                });
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "删除操作已取消!",
          });
        });
    },
    //新增
    insertClick() {
      this.$router.push("addMornThanTransportAppoint");
    },
  },
};
</script>
<style lang='scss' scoped>
.homeworkPath {
  .top {
    padding: 40px;
    .el-input {
      width: 250px;
      margin-right: 20px;
    }
  }
}
</style>