<template>
  <div ref="containerRef" class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="单位性质" prop="unitType">
        <el-select v-model="queryParams.unitType" placeholder="请选择" clearable style="width: 180px">
          <el-option label="直属单位" value="1" />
          <el-option label="下级水行政主管部门" value="2" />
          <el-option label="流域机构" value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="单位名称" prop="orgName">
        <el-input v-model="queryParams.orgName" placeholder="请输入" clearable style="width: 180px" />
      </el-form-item>
      <el-form-item label="统计时间" prop="createTime">
        <el-date-picker v-model="queryParams.createTime" type="date" placeholder="选择日期" value-format="YYYY-MM-DD" clearable style="width: 160px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <div class="table-wrapper">
    <el-table :height="tableHeight" v-loading="loading" :data="statList" border style="width:100%"
      :header-cell-style="{ 'text-align': 'center', 'white-space': 'nowrap' }">
      <el-table-column label="序号" align="center" type="index" width="60" />
      <el-table-column label="单位" align="center" min-width="130" :show-overflow-tooltip="true" prop="orgName" />
      <el-table-column label="隐患排查情况" align="center">
        <el-table-column label="排查率" align="center" width="70">
          <template #default="scope">
            {{ scope.row.pcl != null ? scope.row.pcl + '%' : '-' }}
          </template>
        </el-table-column>
        <el-table-column label="非工程单位" align="center">
          <el-table-column label="总数" align="center" width="65" prop="oengOrg" />
          <el-table-column label="已排查" align="center" width="65" prop="hiddOrg" />
        </el-table-column>
        <el-table-column label="工程单位" align="center">
          <el-table-column label="总数" align="center" width="65" prop="engNum" />
          <el-table-column label="已排查" align="center" width="65" prop="hiddEng" />
        </el-table-column>
      </el-table-column>
      <el-table-column label="隐患整改情况" align="center">
        <el-table-column label="综合整改率" align="center" width="80">
          <template #default="scope">
            {{ scope.row.hiddZgl != null ? scope.row.hiddZgl + '%' : '-' }}
          </template>
        </el-table-column>
        <el-table-column label="重大隐患" align="center">
          <el-table-column label="整改率" align="center" width="70">
            <template #default="scope">
              {{ scope.row.zdZgl != null ? scope.row.zdZgl + '%' : '-' }}
            </template>
          </el-table-column>
          <el-table-column label="总数" align="center" width="65" prop="zdHidd" />
          <el-table-column label="已整改" align="center" width="65" prop="zgZdHidd" />
        </el-table-column>
        <el-table-column label="一般隐患" align="center">
          <el-table-column label="整改率" align="center" width="70">
            <template #default="scope">
              {{ scope.row.ybZgl != null ? scope.row.ybZgl + '%' : '-' }}
            </template>
          </el-table-column>
          <el-table-column label="总数" align="center" width="65" prop="ybHidd" />
          <el-table-column label="已整改" align="center" width="65" prop="zgYbHidd" />
        </el-table-column>
      </el-table-column>
    </el-table>
    </div>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script setup name="HiddStat">
import { listTBusiHiddCount } from "@/api/slaj/hidd"
import { useTableHeight } from '@/hooks/useTableHeight'

const { tableHeight, containerRef } = useTableHeight()

const { proxy } = getCurrentInstance()

const loading = ref(false)
const showSearch = ref(true)
const statList = ref([])
const total = ref(0)

const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  unitType: undefined,
  orgName: undefined,
  createTime: undefined
})

function getList() {
  loading.value = true
  listTBusiHiddCount(queryParams).then(res => {
    statList.value = res.rows || []
    total.value = res.total || 0
    loading.value = false
  }).catch(() => { loading.value = false })
}

function handleQuery() {
  queryParams.pageNum = 1
  getList()
}

onMounted(() => {
  getList()
})
</script>
