<template>
  <div class="app-container">
    <el-form :model="queryParams" :inline="true" v-show="showSearch">
      <el-form-item label="行政区划">
        <el-input v-model="queryParams.adCode" placeholder="请输入行政区划编码" clearable style="width:180px" />
      </el-form-item>
      <el-form-item label="事件类型">
        <el-input v-model="queryParams.evType" placeholder="请输入事件类型" clearable style="width:150px" />
      </el-form-item>
      <el-form-item label="关键词">
        <el-input v-model="queryParams.keyWord" placeholder="河段名/描述/区划" clearable style="width:200px" @keyup.enter="getList" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="getList">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" />
    </el-row>

    <el-table v-loading="loading" :data="eventList" border>
      <el-table-column label="序号" type="index" width="55" align="center" />
      <el-table-column label="河段名称" prop="OBJECT_NAME" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="事件类型" prop="EV_TYPE" width="110" />
      <el-table-column label="事件类别" prop="EVENT_TYPES" width="110" />
      <el-table-column label="问题描述" prop="EVENT_DESC" :show-overflow-tooltip="true" min-width="200" />
      <el-table-column label="当前情况" prop="STATUS" width="100" />
      <el-table-column label="整改情况" prop="DEAL_DESC" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="检查情况" width="100">
        <template #default="scope">{{ scope.row.STATUS === '1' ? '已整改' : '未整改' }}</template>
      </el-table-column>
      <el-table-column label="发现时间" prop="FIND_TS" width="160" />
      <el-table-column label="整改完成" prop="DONE_DATE" width="160" />
      <el-table-column label="上报人" prop="USER_NAME" width="100" />
      <el-table-column label="行政区域" prop="AD_NAME" width="150" />
    </el-table>
    <pagination v-show="total > 0" :total="total" v-model:page="pageNum" v-model:limit="pageSize" @pagination="getList" />
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { listEventClear } from '@/api/hzz/eventclear'

const showSearch = ref(true)
const loading = ref(false)
const total = ref(0)
const pageNum = ref(1)
const pageSize = ref(10)
const eventList = ref([])
const queryParams = ref({ adCode: '', evType: '', keyWord: '', objectType: '' })

const getList = async () => {
  loading.value = true
  try {
    const res = await listEventClear({ ...queryParams.value, pageNum: pageNum.value, pageSize: pageSize.value })
    eventList.value = res.rows || []
    total.value = res.total || 0
  } finally { loading.value = false }
}
const resetQuery = () => { queryParams.value = { adCode: '', evType: '', keyWord: '', objectType: '' }; getList() }

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