<!-- 测试报告管理页 -->
<template>
  <div class="patrol-manage-page">
    <div class="top-title">水雨情测报</div>
    <div class="table-box">
      <div class="top-search">
        <span>起/终点所在地：</span>
        <el-cascader
          :options="areasOptions"
          v-model="paramsData.startArea"
          :props="areasOptionProps"
          placeholder="请选择"
          clearable
          size="small"
        >
        </el-cascader>
        <span>-</span>
        <el-cascader
          :options="areasOptions"
          v-model="paramsData.endArea"
          :props="areasOptionProps"
          placeholder="请选择"
          clearable
          size="small"
        >
        </el-cascader>
        <span class="ml-12">堤防类型：</span>
        <el-select v-model="paramsData.dikeGrad" placeholder="请选择">
          <el-option
            v-for="item in dikeGradList"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue"
          >
          </el-option>
        </el-select>
        <span class="ml-12">堤防名称：</span>
        <el-input
          class="search-input"
          v-model="paramsData.dikeName"
          placeholder="请输入"
        ></el-input>
        <el-button class="!ml-10" type="success" @click="getTableData()"
          >搜索</el-button
        >
        <el-button @click="resetSearch()">重置</el-button>
      </div>
      <el-table class="mt-16" height="625" :data="tableData" border>
        <el-table-column type="index" align="center" label="序号" width="80" />
        <el-table-column prop="dikeName" align="center" label="堤防名称" />
        <el-table-column prop="dikeGrad" align="center" label="堤防级别">
          <template #default="{ row }">{{
            getDikeGrad(row.dikeGrad)
          }}</template>
        </el-table-column>
        <el-table-column prop="dikeType" align="center" label="堤防类别" />
        <el-table-column prop="dikeLen" align="center" label="堤防长度" />
        <el-table-column prop="project" 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
              @click="handleGoReport(scope.row)"
              type="text"
              size="small"
              >水雨情监测</el-button
            >
            <el-button
              @click="handleGoAnalyse(scope.row)"
              type="text"
              size="small"
              >智能分析</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="getTableData()"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { getAreasData } from "@/api/areas/index";
import { regionData, codeToText, TextToCode } from "element-china-area-data";

import { getDikeWaterRainProjectList } from "@/api/dike";

export default {
  data() {
    return {
      dialogVisible: false,
      areasOptionProps: {
        emitPath: false,
        checkStrictly: true, //选择任意一级
      },
      pageData: {
        pageNum: 1,
        pageSize: 10,
        total: 0,
      },
      paramsData: {
        startArea: "",
        endArea: "",
        dikeGrad: "",
        dikeName: "",
      },
      areasOptions: [],
      dikeTypeList: [], // 堤防类型列表
      dikeGradList: [], // 堤防级别列表
      tableData: [],
    };
  },
  created() {
    this.getDicts("embankment_level").then((response) => {
      this.dikeGradList = response.data;
    });
    this.getDicts("embankment_type").then((response) => {
      this.dikeTypeList = response.data;
    });
  },
  mounted() {
    this.getTableData();
    this.getTreeData();
  },
  methods: {
    // 获取列表信息
    getTableData() {
      getDikeWaterRainProjectList({
        pageNum: this.pageData.pageNum,
        pageSize: this.pageData.pageSize,
        data: {
          startArea: this.paramsData.startArea || "",
          endArea: this.paramsData.endArea || "",
          dikeGrad: this.paramsData.dikeGrad || "",
          dikeName: this.paramsData.dikeName || "",
        },
      }).then((res) => {
        if (res) {
          this.tableData = res.records;
          this.pageData.total = res.total;
        }
      });
    },
    // 重置搜索条件
    resetSearch() {
      this.paramsData.dikeGrad = "";
      this.paramsData.dikeName = "";
      this.paramsData.startArea = "";
      this.paramsData.endArea = "";
      this.getTableData();
    },
    // 水雨情监测
    handleGoReport(row) {
      this.$router.push({
        path: "waterRainMonitoring",
        query: {
          dikeCode: row.dikeCode,
          dikeName: row.dikeName,
        },
      });
    },
    // 智能分析
    handleGoAnalyse(row) {
      this.$router.push({
        path: "waterRainSmartAnalyse",
        query: {
          dikeCode: row.dikeCode,
          dikeName: row.dikeName,
        },
      });
    },
    // 获取地区树数据
    getTreeData() {
      getAreasData().then((items) => {
        if (items?.data) {
          let res = [];
          let getChildren = (res, pid) => {
            for (const i of items.data) {
              if (i.parentid === pid) {
                const newItem = {
                  label: i.name,
                  value: i.id,
                };
                if (i.layer != 3) newItem.children = [];
                res.push(newItem);
                getChildren(newItem.children, newItem.value);
              }
            }
          };
          getChildren(res, items.data[0].parentid);
          this.areasOptions = res;
        }
      });
    },
    getDikeGrad(key) {
      return (
        this.dikeGradList?.filter((v) => v.dictValue === key)?.[0]?.dictLabel ||
        key
      );
    },
  },
};
</script>
<style scoped lang="scss">
.patrol-manage-page {
  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;

      .search-input {
        width: 202px;
        margin-right: 10px;
      }
    }

    .table {
      height: calc(680px - 34px);
    }
  }
}
</style>
