<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="寝室位置" prop="dormLocation">
        <el-input v-model="queryParams.dormLocation" placeholder="请输入寝室位置" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="寝室号" prop="dormNo">
        <el-input v-model="queryParams.dormNo" placeholder="请输入寝室号" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="提交人" prop="submitter">
        <el-input v-model="queryParams.submitter" placeholder="请输入提交人" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="检查日期">
        <el-date-picker v-model="dateRange" type="daterange" value-format="YYYY-MM-DD"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" clearable />
      </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="['ledger:dormFireSafety:export']">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" />
    </el-row>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="检查日期" align="center" prop="checkDate" width="110">
        <template #default="{ row }">{{ parseTime(row.checkDate, '{y}-{m}-{d}') }}</template>
      </el-table-column>
      <el-table-column label="寝室所在位置" align="center" prop="dormLocation" width="120" />
      <el-table-column label="寝室号" align="center" prop="dormNo" width="90" />
      <el-table-column label="自查覆盖项" align="center" prop="checkItems" min-width="200" show-overflow-tooltip />
      <el-table-column label="风险类型排查情况" align="center" prop="riskStatus" min-width="150" show-overflow-tooltip />
      <el-table-column label="发现具体隐患" align="center" prop="foundRisk" min-width="150" show-overflow-tooltip />
      <el-table-column label="整改责任人" align="center" prop="rectifyPerson" width="110" />
      <el-table-column label="整改完成时间" align="center" prop="rectifyTime" width="120">
        <template #default="{ row }">{{ parseTime(row.rectifyTime, '{y}-{m}-{d}') }}</template>
      </el-table-column>
      <el-table-column label="提交人" align="center" prop="submitter" width="100" />
      <el-table-column label="提交时间" align="center" prop="submitTime" width="160">
        <template #default="{ row }">{{ parseTime(row.submitTime) }}</template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  </div>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue'
import { listDormFireSafety, exportDormFireSafety } from '@/api/ledger/index'
import { parseTime } from '@/utils/ruoyi'
defineOptions({ name: 'LedgerDormFireSafety' })
const loading = ref(false), list = ref([]), total = ref(0), showSearch = ref(true)
const dateRange = ref([]), queryRef = ref(null)
const queryParams = reactive({ pageNum: 1, pageSize: 10, dormLocation: '', dormNo: '', submitter: '' })
function getList() {
  loading.value = true
  const p = { ...queryParams }
  if (dateRange.value?.length === 2) { p['params[beginTime]'] = dateRange.value[0]; p['params[endTime]'] = dateRange.value[1] }
  listDormFireSafety(p).then(r => { list.value = r.rows; total.value = r.total }).finally(() => loading.value = false)
}
function handleQuery() { queryParams.pageNum = 1; getList() }
function resetQuery() { dateRange.value = []; queryRef.value?.resetFields(); handleQuery() }
function handleExport() {
  const p = { ...queryParams }
  if (dateRange.value?.length === 2) { p['params[beginTime]'] = dateRange.value[0]; p['params[endTime]'] = dateRange.value[1] }
  exportDormFireSafety(p)
}
onMounted(getList)
</script>
