<!-- 监督检查-统计分析 -->
<script>
import {
  getSuperviseWayTaskListData,
  getSuperviseStatisticTotal,
} from "@/api/dike";
import { getAreasData } from "@/api/areas";
import Pie from "./components/Pie.vue";

export default {
  name: "InspectionItems",
  components: {
    Pie,
  },
  data() {
    return {
      areasOptionProps: {
        emitPath: false,
        checkStrictly: true, //选择任意一级
      },
      areasOptions: [],
      riverLocationList: [], // 流域数据
      tasksList: [], // 任务列表数据
      projectTypeOptions: [], // 工程类型
      paramsData: {
        riverLocation: "",
        dikeType: "",
        adcd: "",
        taskId: "",
      },
      questionLevelList: [],
    };
  },
  methods: {
    // 获取列表数据
    initData() {
      getSuperviseStatisticTotal({
        dikeType: this.paramsData.dikeType || null,
        adcd: this.paramsData.adcd || null,
        taskId: this.paramsData.taskId || null,
        riverLocation: this.paramsData.riverLocation || null,
      }).then((res) => {
        let list = [
          {
            text: "问题总数",
            key: "problemTotal",
            value: 0,
          },
          {
            text: "一般问题",
            key: "same",
            value: 0,
          },
          {
            text: "较重问题",
            key: "heavy",
            value: 0,
          },
          {
            text: "严重问题",
            key: "serious",
            value: 0,
          },
          {
            text: "特别严重问题",
            key: "superSerious",
            value: 0,
          },
          {
            text: "问题处置",
            key: "problemDispose",
            value: 0,
          },
          {
            text: "下发",
            key: "distributeCount",
            value: 0,
          },
          {
            text: "处置",
            key: "handleCount",
            value: 0,
          },
          {
            text: "确认",
            key: "confirmCount",
            value: 0,
          },
          {
            text: "完成",
            key: "finishCount",
            value: 0,
          },
        ];
        if (res?.data) {
          list.forEach((item) => {
            item.value = res.data[item.key] || 0;
          });
        }
        this.questionLevelList = list;
      });
    },
    handleChangeType() {
      this.remoteOptions = [];
      this.paramsData = {
        wagaType: "",
        adcd: "",
        remoteValue: "",
      };
      if (this.typeSelect === "") {
        this.initData();
      }
    },
    handleChangeQuery() {
      this.initData();
    },
    handleGetRemoteRiverLocationData() {
      // 获取远程搜索数据
      // api({
      //   data: {
      //     name: query,
      //   },
      //   pageSize: 20,
      //   pageNum: 1,
      // }).then((res) => {
      //   if (res) {
      //     this.remoteOptions = res.records.map((item) => {
      //       return {
      //         label: item.name,
      //         value: item.id,
      //       };
      //     });
      //   }
      // });
    },
    // 获取远程搜索数据
    handleGetRemoteTasksData(query) {
      getSuperviseWayTaskListData({
        data: {
          name: query,
        },
        pageSize: 20,
        pageNum: 1,
      }).then((res) => {
        if (res) {
          this.tasksList = res.records.map((item) => {
            return {
              label: item.name,
              value: item.id,
            };
          });
        }
      });
    },
    // 获取行政区划数据
    getTreeData() {
      getAreasData().then((items) => {
        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;
      });
    },
  },
  created() {
    // 水闸类型
    this.getDicts("embankment_type").then((response) => {
      this.projectTypeOptions = response.data;
    });
  },
  mounted() {
    this.getTreeData();
    this.initData();
  },
};
</script>

<template>
  <div class="body slider-right">
    <div class="top-title">统计分析</div>
    <div class="table-box">
      <div class="flex title-box justify-between items-center">
        <div class="title">监督检查任务统计分析</div>
        <div class="select-box flex items-center font-14">
          <span class="mr-12">所属流域</span>
          <el-select
            size="mini"
            class="statistic-analysis-select-style"
            v-model="paramsData.riverLocation"
            filterable
            link
            remote
            placeholder="请输入关键词"
            :remote-method="handleGetRemoteRiverLocationData"
            @focus="handleGetRemoteRiverLocationData('')"
            @change="handleChangeQuery"
          >
            <el-option label="全部" value=""> </el-option>
            <el-option
              v-for="item in riverLocationList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <span class="ml-32 mr-12">工程类型</span>
          <el-select
            size="mini"
            class="statistic-analysis-select-style"
            v-model="paramsData.wagaType"
            filterable
            @change="handleChangeQuery"
            placeholder="请选择"
          >
            <el-option label="全部" value=""> </el-option>
            <el-option
              v-for="item in projectTypeOptions"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
          <span class="ml-32 mr-12">行政区划</span>
          <el-cascader
            size="mini"
            class="statistic-analysis-select-style"
            :options="areasOptions"
            v-model="paramsData.adcd"
            :props="areasOptionProps"
            placeholder="请选择行政区划"
            clearable
            @change="handleChangeQuery"
          >
          </el-cascader>
          <span class="ml-32 mr-12">监督检查任务</span>
          <el-select
            size="mini"
            class="statistic-analysis-select-style"
            v-model="paramsData.taskId"
            filterable
            link
            remote
            placeholder="请输入关键词"
            :remote-method="handleGetRemoteTasksData"
            @focus="handleGetRemoteTasksData('')"
            @change="handleChangeQuery"
          >
            <el-option label="全部" value=""> </el-option>
            <el-option
              v-for="item in tasksList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
      </div>

      <!-- 问题列表 -->
      <div class="question-box" v-if="questionLevelList.length">
        <Pie
          title="问题统计"
          echartsTitle="问题总数"
          :itemData="questionLevelList.slice(1, 5)"
          ref="pieRef1"
          class="question-item"
        ></Pie>
        <Pie
          ref="pieRef2"
          title="处理统计"
          echartsTitle="问题处置"
          class="question-item ml-20"
          :itemData="questionLevelList.slice(6, 10)"
        ></Pie>
      </div>
    </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;
    background-color: white;
    .title-box {
      padding: 16px;
      border-bottom: 1px solid #f0f0f0;
      .title {
        padding-left: 20px;
        position: relative;
        &::before {
          position: absolute;
          left: 0;
          top: 0;
          content: "";
          width: 4px;
          height: 16px;
          background-color: #1890ff;
        }
      }
    }
    .question-box {
      display: flex;
      flex-wrap: wrap;
      padding: 24px;
      .question-item {
        flex: 1;
        min-width: 250px;
        margin-right: 10px;
        margin-bottom: 12px;
      }
    }
  }
}
</style>
