<template>
  <!-- 请车作业页面 -->
  <div class="homeworkPath">
    <div class="top">
      <el-input placeholder="请输入内容" v-model="inputText" 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>
    </div>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <!-- 未下发 -->
      <el-tab-pane label="未下发" name="first">
        <dilTable v-bind.sync="option1" ref="table">
          <el-table-column fixed="right" label="操作" width="120">
            <template slot-scope="scope">
              <el-button
                @click="updateClick(scope.row.resultId)"
                type="text"
                size="small"
              >
                修改
              </el-button>
              <el-button
                @click="deleteClick(scope.row.resultId)"
                type="text"
                size="small"
              >
                删除
              </el-button>
              <el-button
                @click="sendClick(scope.row.resultId)"
                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>
export default {
  name: "inplantTMS",
  data() {
    return {
      inputText: "",
      activeName: "first",
      option1: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/tms/getAllWagonPlease?apiId=253&status=0&resultType=4",
      },
      option2: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/tms/getAllWagonPlease?apiId=253&status=1&resultType=4",
      },
    };
  },
  methods: {
    onclick() {
      if(this.activeName == 'first'){
        this.option1.requestUrl = "/api/v1/tms/getAllWagonPlease?apiId=253&status=0&resultType=4&con=" + this.inputText;
      }else{
        this.option1.requestUrl = "/api/v1/tms/getAllWagonPlease?apiId=253&status=1&resultType=4&con=" + this.inputText;  
      }
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    // 删除
    deleteClick(resultId) {
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.$axios
            .post("/api/v1/tms/deleteApproveWagonPlease/" + resultId)
            .then((res) => {
              if (res.data.code == "200") {
                this.$message({
                  type: "success",
                  message: "删除成功!",
                });
                this.$router.go(0);
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除!",
          });
        });
    },
    // 下发
    sendClick(resultId) {
      this.$confirm("是否下发", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          // console.log(this.arr[0].text_prop);
          this.$axios
            .post("/api/v1/tms/sendWagonPlease/" + resultId)
            .then((res) => {
              if (res.data.code == "200") {
                this.$message({
                  type: "success",
                  message: "下发成功!",
                });
                this.$router.go(0);
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消下发!",
          });
        });
    },
    //新增
    insertClick() {
      this.$router.push("/addWagonPlease");
    },
    //修改
    updateClick(resultId) {
      this.$router.push("/editWagonPlease/" + resultId);
    },
  },
};
</script>
<style lang='scss'>
.homeworkPath {
  .top {
    padding: 1.25rem 1.875rem;
  }
}
</style>