<template>
  <div ref="containerRef" class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="统计年份" prop="statYear">
        <el-date-picker v-model="queryParams.statYear" type="year" placeholder="选择年份" value-format="YYYY" />
      </el-form-item>
      <el-form-item label="统计月份" prop="statMonth">
        <el-select v-model="queryParams.statMonth" placeholder="请选择统计月份" clearable style="width: 240px">
          <el-option v-for="item in 12" :key="item" :label="item + '月'" :value="item" />
        </el-select>
      </el-form-item>
      <el-form-item label="机构名称" prop="orgGuid">
        <el-input v-model="queryParams.orgGuid" placeholder="请输入机构名称" clearable style="width: 240px" @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="隐患等级" prop="hiddGrad">
        <el-select v-model="queryParams.hiddGrad" placeholder="请选择隐患等级" clearable style="width: 240px">
          <el-option v-for="dict in hidd_grad" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="隐患状态" prop="hiddStat">
        <el-select v-model="queryParams.hiddStat" placeholder="请选择隐患状态" clearable style="width: 240px">
          <el-option v-for="dict in hidd_stat" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['hidd:count:export']">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns" storageKey="hidd-detailcount-index"></right-toolbar>
    </el-row>

    <div class="table-wrapper">
    <el-table :height="tableHeight" v-loading="loading" :data="detailCountList">
      <el-table-column label="机构名称" align="center" prop="orgName" :show-overflow-tooltip="true" />
      <el-table-column label="统计年份" align="center" prop="statYear" />
      <el-table-column label="统计月份" align="center" prop="statMonth" />
      <el-table-column label="隐患名称" align="center" prop="hiddName" :show-overflow-tooltip="true" />
      <el-table-column label="隐患等级" align="center" prop="hiddGrad">
        <template #default="scope">
          <dict-tag :options="hidd_grad" :value="scope.row.hiddGrad" />
        </template>
      </el-table-column>
      <el-table-column label="隐患类别" align="center" prop="hiddClas">
        <template #default="scope">
          <dict-tag :options="hidd_clas" :value="scope.row.hiddClas" />
        </template>
      </el-table-column>
      <el-table-column label="隐患状态" align="center" prop="hiddStat">
        <template #default="scope">
          <dict-tag :options="hidd_stat" :value="scope.row.hiddStat" />
        </template>
      </el-table-column>
      <el-table-column label="涉及部位" align="center" prop="proPart" :show-overflow-tooltip="true" />
      <el-table-column label="采集时间" align="center" prop="collTime" width="180" />
      <el-table-column label="操作" align="center" width="100">
        <template #default="scope">
          <el-tooltip content="详情" placement="top">
            <el-button link type="primary" icon="View" @click="handleDetail(scope.row)"></el-button>
          </el-tooltip>
        </template>
      </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="HiddDetailCount">
import { listObjHidd } from "@/api/slaj/hidd"
import { useTableHeight } from '@/hooks/useTableHeight'

const { tableHeight, containerRef } = useTableHeight()

const { proxy } = getCurrentInstance()
const { hidd_grad, hidd_stat, hidd_clas } = proxy.useDict("hidd_grad", "hidd_stat", "hidd_clas")

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

const columns = ref({
  orgName: { label: '机构名称', visible: true },
  statYear: { label: '统计年份', visible: true },
  statMonth: { label: '统计月份', visible: true },
  hiddName: { label: '隐患名称', visible: true },
  hiddGrad: { label: '隐患等级', visible: true },
  hiddClas: { label: '隐患类别', visible: true },
  hiddStat: { label: '隐患状态', visible: true },
  proPart: { label: '涉及部位', visible: true },
  collTime: { label: '采集时间', visible: true }
})

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    statYear: undefined,
    statMonth: undefined,
    orgGuid: undefined,
    hiddGrad: undefined,
    hiddStat: undefined
  }
})

const { queryParams } = toRefs(data)

/** 查询明细统计列表 */
function getList() {
  loading.value = true
  listObjHidd(queryParams.value).then(res => {
    loading.value = false
    detailCountList.value = res.rows
    total.value = res.total
  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

/** 详情按钮操作 */
function handleDetail(row) {
  proxy.$router.push({ path: '/slaj/hidd/detail', query: { guid: row.guid } })
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download("hidd/count/detailexport", {
    ...queryParams.value
  }, `hiddDetailCount_${new Date().getTime()}.xlsx`)
}

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