<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>
    </div>
    <el-tabs v-model="activeName">
      <!-- 未下发 -->
      <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 {
      input: "",
      activeName: "first",
      option1: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/tms/getAllWagonPlease?apiId=57&status=0&resultType=3",
      },
      option2: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/tms/getAllWagonPlease?apiId=57&status=1&resultType=3",
      },
    };
  },
  methods: {
    onclick() {
      if(this.activeName == "first"){
        this.option1.requestUrl = "/api/v1/tms/getAllWagonPlease?apiId=57&status=0&resultType=3&con=" +this.input;
      }else{
        this.option2.requestUrl = "/api/v1/tms/getAllWagonPlease?apiId=57&status=1&resultType=3&con=" +this.input;
      }
    },
    // 删除
    deleteClick(resultId) {
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          // console.log(this.arr[0].text_prop);
          this.$axios
            .post("/api/v1/tms/deleteApproveWagonPlease/" + resultId)
            .then(() => {
              this.$router.go(0);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除!",
          });
        });
    },
    // 下发
    sendClick(resultId) {
      this.$confirm("是否下发", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "下发成功!",
          });
          // console.log(this.arr[0].text_prop);
          this.$axios
            .post("/api/v1/tms/sendWagonPlease/" + resultId)
            .then(() => {
              this.$router.go(0);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消下发!",
          });
        });
    },

    //新增
    insertClick() {
      this.$router.push("/domesticMine/wagonPleaseAdd");
    },
    //修改
    updateClick(resultId) {
      this.$router.push("/domesticMine/wagonPleaseEdit/" + resultId);
    },
  },
};
</script>
<style lang='scss' scoped>
.homeworkPath {
  .top {
    padding: 1.25rem 1.875rem;
  }
}
</style>