<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="时间范围">
        <el-date-picker v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 260px"></el-date-picker>
      </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">
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <div class="table-wrapper">
    <el-table :height="tableHeight" v-loading="loading" :data="recList" stripe>
      <el-table-column label="上报时间" align="center" prop="repTime" width="180" />
      <el-table-column label="上报单位" align="center" prop="orgName" :show-overflow-tooltip="true" />
      <el-table-column label="月份" align="center" prop="mont" width="100" />
      <el-table-column label="上报状态" align="center" prop="montStat" width="120">
        <template #default="scope">
          <dict-tag :options="acci_mont_stat" :value="scope.row.montStat" />
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="note" :show-overflow-tooltip="true" />
    </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="AcciReportRec">
import { getCurrentInstance, onMounted, reactive, ref, toRefs } from 'vue'
import { useTableHeight } from '@/hooks/useTableHeight'
import { listBisAcciRecRep } from "@/api/slaj/acci"

const { tableHeight, containerRef } = useTableHeight()

const { proxy } = getCurrentInstance()
const { acci_mont_stat } = proxy.useDict("acci_mont_stat")

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

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10
  }
})
const { queryParams } = toRefs(data)

/** 查询上报记录 */
function getList() {
  loading.value = true
  listBisAcciRecRep(proxy.addDateRange(queryParams.value, dateRange.value)).then(res => {
    loading.value = false
    recList.value = res.rows || []
    total.value = res.total || 0
  }).catch(() => {
    loading.value = false
  })
}

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

function resetQuery() {
  dateRange.value = []
  proxy.resetForm("queryRef")
  handleQuery()
}

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