<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="wiunProp">
        <el-select v-model="queryParams.wiunProp" placeholder="请选择" clearable style="width: 150px">
          <el-option label="施工单位" value="7" />
          <el-option label="参建单位" value="6" />
        </el-select>
      </el-form-item>
      <el-form-item label="单位名称" prop="orgName">
        <el-input v-model="queryParams.orgName" placeholder="请输入" clearable style="width: 180px" @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="统计时间" prop="createTime">
        <el-date-picker v-model="dateRange" type="daterange" range-separator="至" start-placeholder="开始" end-placeholder="结束" value-format="YYYY-MM-DD" style="width: 250px" />
      </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="list" border style="width:100%" :header-cell-style="{ 'text-align': 'center' }">
      <el-table-column label="序号" align="center" type="index" width="60" />
      <el-table-column label="单位名称" align="center" prop="orgName" min-width="160" :show-overflow-tooltip="true" />
      <el-table-column label="有效辨识情况" align="center">
        <el-table-column label="一般危险源" align="center">
          <el-table-column label="应辨识" align="center" width="80" prop="ybYbs" />
          <el-table-column label="已辨识" align="center" width="80" prop="yxYbHaz" />
        </el-table-column>
        <el-table-column label="重大危险源" align="center">
          <el-table-column label="应辨识" align="center" width="80" prop="zdYbs" />
          <el-table-column label="已辨识" align="center" width="80" prop="yxZdHaz" />
        </el-table-column>
        <el-table-column label="应辨识总数" align="center" width="100" prop="ybsNum" />
        <el-table-column label="已辨识总数" align="center" width="100" prop="alrhaz" />
        <el-table-column label="辨识率(%)" align="center" width="90" prop="hazBsl" />
        <el-table-column label="应辨识工程" align="center" width="100" prop="engNum" />
        <el-table-column label="已辨识工程" align="center" width="100" prop="alrEngNum" />
      </el-table-column>
    </el-table>
    </div>

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

<script setup name="HazardStat">
import { listTBusiHazCount } from "@/api/slaj/hazard"
import { useTableHeight } from '@/hooks/useTableHeight'

const { tableHeight, containerRef } = useTableHeight()
const { proxy } = getCurrentInstance()

const loading = ref(false); const list = ref([]); const total = ref(0)
const showSearch = ref(true)
const dateRange = ref([])

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

function getList() {
  loading.value = true
  const params = { ...queryParams }
  if (dateRange.value && dateRange.value.length === 2) {
    params.beginCreateTime = dateRange.value[0]
    params.endCreateTime = dateRange.value[1]
  }
  listTBusiHazCount(params).then(res => {
    list.value = res.rows || []
    total.value = res.total || 0
    loading.value = false
  }).catch(() => { loading.value = false })
}

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

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