<!-- 监督检查任务管理 -->
<script>
import {
  delSuperviseWayItemData,
  getSuperviseWayTaskListData,
} from "@/api/dike";
export default {
  name: "InspectionItems",
  data() {
    return {
      searchTaskName: "",
      searchManageName: "",
      paramsData: {
        name: "",
        type: null,
        dikeName: "",
        selectLevel: "",
        selectType: "",
      },
      tableData: [], // 检查列表
      pageData: {
        pageNum: 1, // 当前页
        pageSize: 10, // 请求数量
        pageSizes: [10, 20, 50, 100],
        total: 0, // 总数量
      },
    };
  },
  methods: {
    handleCurrentPageChange(page) {
      this.pageData.pageNum = page;
      this.getTableData();
    },
    handlePageSizeChange(pageSize) {
      this.pageData.pageSize = pageSize;
      this.getTableData();
    },
    // 跳转任务新增页面
    handleGoDetails() {
      this.$router.push({
        path: "supervisionTasksDetails",
        query: {
          type: "add",
        },
      });
    },
    // 跳转任务编辑页面
    handleEdit(row) {
      this.$router.push({
        path: "supervisionTasksDetails",
        query: {
          type: "edit",
          id: row.id,
        },
      });
    },
    // 获取列表数据
    getTableData() {
      getSuperviseWayTaskListData({
        data: {
          timeView: {
            timeField: "create_time",
          },
          name: this.searchTaskName || null,
          engineeringManagementUnit: this.searchManageName || null,
        },
        params: {
          orderBy: "create_time",
          sort: "desc",
        },
        pageSize: this.pageData.pageSize,
        pageNum: this.pageData.pageNum,
      }).then((res) => {
        if (res) {
          this.tableData = res.records;
          this.pageData.total = res.total;
        }
      });
    },
    // 重置搜索
    resetSearch() {
      this.searchTaskName = null;
      this.searchManageName = null;
      this.getTableData();
    },
    // 删除
    handleDel(row) {
      this.$confirm("是否删除该条数据？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          delSuperviseWayItemData(row.id).then((res) => {
            if (res) {
              this.$message.success("删除成功");
              this.getTableData();
            }
          });
        })
        .catch(() => {});
    },
  },
  created() {
    this.getDicts("embankment_type").then((response) => {
      this.dikeTypeList = response.data;
    });
  },
  mounted() {
    // 获取列表数据
    this.getTableData();
  },
};
</script>

<template>
  <div class="body slider-right">
    <div class="top-title">基础信息管理</div>
    <div class="table-box">
      <span>任务名称：</span>
      <el-input
        class="search-input ml-10"
        v-model="searchTaskName"
        placeholder="请输入名称"
      />
      <span class="ml-10">管理单位：</span>
      <el-input
        class="search-input ml-10"
        v-model="searchManageName"
        placeholder="请输入"
      />
      <el-button class="search-btn" type="success" @click="getTableData()"
        >搜索</el-button
      >
      <el-button class="search-btn" @click="resetSearch">重置</el-button>
      <el-button
        class="search-btn"
        style="margin-right: 16px; margin-bottom: 8px; float: right"
        type="success"
        @click="handleGoDetails()"
        >添加</el-button
      >
      <el-table class="table mt-16" height="640" :data="tableData" border>
        <el-table-column type="index" align="center" label="序号" width="60" />
        <el-table-column prop="name" align="center" label="检查任务" />
        <el-table-column prop="createTime" align="center" label="创建时间">
        </el-table-column>
        <el-table-column prop="updateTime" align="center" label="更新时间" />
        <el-table-column
          prop="engineeringManagementUnit"
          align="center"
          label="管理单位"
        />
        <el-table-column prop="operate" align="center" label="操作">
          <template slot-scope="scope">
            <el-button v-hasPermi="['sz:run:jc:task:edit']"  type="text" size="small" @click="handleEdit(scope.row)"
              >编辑</el-button
            >
            <el-button v-hasPermi="['df:run:jc:task:delete']"  type="text" size="small" @click="handleDel(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="pagination"
        style="margin-top: 16px; margin-right: 16px; float: right"
        :current-page="pageData.pageNum"
        :page-sizes="pageData.pageSizes"
        layout="total, prev, pager, next, sizes, jumper"
        :total="pageData.total"
        @size-change="(e) => handlePageSizeChange(e)"
        @current-change="(e) => handleCurrentPageChange(e)"
      >
      </el-pagination>
    </div>
  </div>
</template>

<style scoped lang="less">
.body {
  width: 100%;
  min-height: calc(100vh - 56px);
  padding-left: 24px;

  .top-title {
    height: 40px;
    background-color: white;
    display: flex;
    padding-left: 16px;
    align-items: center;
    font-weight: 600;
  }

  .table-box {
    width: 100%;
    min-height: calc(100vh - 56px - 64px);
    margin-top: 24px;
    padding: 16px;
    background-color: white;

    .top-search {
      margin-bottom: 8px;
    }

    .table {
      height: calc(680px - 34px);
    }
  }
  .search-input {
    width: 202px;
    margin-right: 10px;
  }

  .search-btn {
    margin-left: 10px;
  }
}
</style>
