<template>
  <div class="app-container">
    <el-tabs v-model="activeTab" type="border-card" @tab-change="getList">
      <el-tab-pane label="工程隐患" name="eng">
        <el-form :model="queryParams" :inline="true" v-show="showSearch" label-width="80px">
          <el-form-item label="工程名称" prop="engName">
            <el-input v-model="queryParams.engName" placeholder="请输入" clearable style="width: 200px" />
          </el-form-item>
          <el-form-item label="单位名称" prop="orgName">
            <el-input v-model="queryParams.orgName" placeholder="请输入" clearable style="width: 200px" />
          </el-form-item>
          <el-form-item label="采集时间" prop="collTime">
            <el-date-picker v-model="queryParams.collTime" 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-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['hidd:query:export']">导出</el-button>
          </el-form-item>
        </el-form>

        <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="engName" min-width="150" :show-overflow-tooltip="true" />
          <el-table-column label="管理单位" align="center" prop="orgName" min-width="140" :show-overflow-tooltip="true" />
          <el-table-column label="总数" align="center" prop="totalCount" width="80" />
          <el-table-column label="一般隐患" align="center" prop="normalCount" width="90" />
          <el-table-column label="重大隐患" align="center" prop="majorCount" width="90" />
          <el-table-column label="已整改隐患" align="center" prop="solvedCount" width="100" />
        </el-table>

        <pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
      </el-tab-pane>
      <el-tab-pane label="非工程隐患" name="nonEng">
        <el-form :model="queryParams" :inline="true" v-show="showSearch" label-width="80px">
          <el-form-item label="单位名称" prop="orgName">
            <el-input v-model="queryParams.orgName" placeholder="请输入" clearable style="width: 200px" />
          </el-form-item>
          <el-form-item label="采集时间" prop="collTime">
            <el-date-picker v-model="queryParams.collTime" 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-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['hidd:query:export']">导出</el-button>
          </el-form-item>
        </el-form>

        <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="200" :show-overflow-tooltip="true" />
          <el-table-column label="总数" align="center" prop="totalCount" width="80" />
          <el-table-column label="一般隐患" align="center" prop="normalCount" width="90" />
          <el-table-column label="重大隐患" align="center" prop="majorCount" width="90" />
          <el-table-column label="已整改隐患" align="center" prop="solvedCount" width="100" />
        </el-table>

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

<script setup name="EngQuery">
import { getHiddGroupBy } from "@/api/slaj/hidd"

const { proxy } = getCurrentInstance()

const tableHeight = 'calc(100vh - 240px)'
const activeTab = ref('eng')
const showSearch = ref(true)
const list = ref([])
const loading = ref(false)
const total = ref(0)

const queryParams = reactive({ pageNum: 1, pageSize: 10, hiddSort: '1', engName: undefined, orgName: undefined, collTime: undefined })

function getList() {
  loading.value = true
  queryParams.hiddSort = activeTab.value === 'nonEng' ? '2' : '1'
  getHiddGroupBy(queryParams).then(res => {
    list.value = res.rows || []
    total.value = res.total || 0
    loading.value = false
  }).catch(() => { loading.value = false })
}

function handleQuery() { queryParams.pageNum = 1; getList() }
function handleExport() { proxy.download("hidd/objhidd/groupBy/export", { ...queryParams }, `隐患查询_${new Date().getTime()}.xlsx`) }

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