//运输预约展现
<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" align="center" label="操作" width="120">
            <template slot-scope="scope">
              <el-button @click="sendClick(1,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">
           <el-table-column fixed="right" align="center" label="操作" width="120">
            <template slot-scope="scope">
              <el-button @click="CloseClick(scope.row.orderId)"  type="text" size="small">
               关闭
              </el-button>
            </template>
          </el-table-column>
        </dilTable>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
export default {
  name: "inplantTMS",
  data() {
    return {

      input: "",
      Time: "",
      activeName: "first",
      option1: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/ams/getSporadicOrdersList?apiId=384&issueStatus=0&orderType=12",
        // 控制显示多选列
        selectionType: "select",
        maplist:[]
      },
       option2: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/ams/getSporadicOrdersList?apiId=384&issueStatus=1&orderType=14",
      },
      selection:[],
    };
  },
  methods: {
    //获取选中的订单
    selectionChange(selection){
      this.selection = [];
      this.maplist = selection
      
    },
    onclick() {
      if(this.activeName == "first"){
        this.option1.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=384&issueStatus=0&orderType=14&con=" + this.input;
      }else{
        this.option2.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=384&issueStatus=1&orderType=14&con=" + this.input;
      }
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
     // 下发
    sendClick() {
      this.$confirm("是否下发", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
         this.axios
            .post(
              "/api/v1/ams/issueSporadicOrders",this.maplist
            )
            .then(() => {
              this.option1.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=384&issueStatus=0&orderType=12"
            })
            .then(() => {
             this.$message({
            type: "success",
            message: "下发成功!",
          });
          // console.log(this.arr[0].text_prop);
   
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消下发!",
          });
        });
    },
    // 删除
    deleteClick(row) {
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
         this.axios
            .post(
               "/api/v1/ams/deleteSporadicOrders",row
            )
        .then((res) => {
          if(res.data.code == '200'){
            this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.option1.requestUrl = "/api/v1/ams/getSporadicOrdersList?apiId=384&issueStatus=0&orderType=12"
          }  
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除!",
          });
        });
    },
    //新增
    insertClick() {
      this.$router.push("/steelReturn/addTransportAppoint");
    },
    //修改
    updateClick(orderId) {
      this.$router.push("/importedIngredients/transportReserveFuEdit/" + orderId);
    },

  },
};
</script>
<style lang='scss' scoped>
   .homeworkPath {
   .top {
    padding: 1.25rem 1.875rem;
  }
}
</style>