<template>
  <!-- 运输预约 -->
  <div class="homeworkPath">
    <div class="top">
      <el-input class="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" align="center" label="操作" width="120">
            <template slot-scope="scope">
              <el-button @click="sendClick(scope.row.planId)"  type="text" size="small">
                下发
              </el-button>
              <el-button @click="updateClick(scope.row.planId)" type="text" size="small">
                修改
              </el-button>
              <el-button @click="deleteClick(scope.row.planId)" 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: "",
      Time: "",
      activeName: "first",
      option1: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/ams/getAllPurPlan?apiId=79&status=0"
      },
      option2: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/ams/getAllPurPlan?apiId=79&status=1",
      }
    };
  },
  methods: {
    onclick() {
      if(this.activeName == "first"){
        this.option1.requestUrl="/api/v1/ams/getAllPurPlan?apiId=79&status=0&con=" + this.input;
      }else{
        this.option2.requestUrl="/api/v1/ams/getAllPurPlan?apiId=79&status=1&con=" + this.input;
      }
    },
    // 删除
    deleteClick(planId) {
      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/ams/deletePurPlan/" + planId
            )
            .then(() => {
              this.$router.go(0);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除!",
          });
        });
    },
    // 下发
    sendClick(planId) {
      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/ams/sendPurPlan/" + planId
            )
            .then(() => {
              this.option1.requestUrl = "/api/v1/ams/getAllPurPlan?apiId=79&status=0&q=1"
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消下发!",
          });
        });
    },
    
    //新增
    insertClick() {
      // console.log(111);
      this.$router.push("/transportReserveAdd");
    },
    //修改
    updateClick(planId) {
      this.$router.push("/transportReserveEdit/" + planId);
    },

  },
};
</script>
<style lang='scss'>
.homeworkPath {
  .top {
    padding: 1.25rem 0.375rem;
    .el-input {
      width: 20%;
      margin-right: 1.25rem;
    }
  }
}
</style>