<template>
  <div class="app-container">
    <el-alert
      title="本页面仅供总集系统对接使用"
      type="warning"
      show-icon
      :closable="false"
      class="mb10"
    />

    <el-card shadow="never" class="mb10">
      <div class="desc-text">
        总集接口面向外部集成系统，提供事故基础数据的查询与导出能力。数据范围涵盖全部上报事故，
        支持按事故名称、发生时间段等条件筛选。本页面仅开放查询与导出操作，不提供新增、修改、删除功能。
      </div>
    </el-card>

    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="事故名称" prop="acciName">
        <el-input v-model="queryParams.acciName" placeholder="请输入事故名称" clearable style="width: 240px" @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="发生时间" style="width: 308px">
        <el-date-picker v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></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">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns" storageKey="acci-zjindex"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="objAcciList">
      <el-table-column label="事故名称" align="center" prop="acciName" v-if="columns.acciName.visible" :show-overflow-tooltip="true" />
      <el-table-column label="事故等级" align="center" prop="acciGrad" v-if="columns.acciGrad.visible">
        <template #default="scope">
          <dict-tag :options="acci_grad" :value="scope.row.acciGrad" />
        </template>
      </el-table-column>
      <el-table-column label="事故类别" align="center" prop="acciCate" v-if="columns.acciCate.visible">
        <template #default="scope">
          <dict-tag :options="acci_cate" :value="scope.row.acciCate" />
        </template>
      </el-table-column>
      <el-table-column label="报告状态" align="center" prop="repStat" v-if="columns.repStat.visible">
        <template #default="scope">
          <dict-tag :options="rep_stat" :value="scope.row.repStat" />
        </template>
      </el-table-column>
      <el-table-column label="发生时间" align="center" prop="occuTime" v-if="columns.occuTime.visible" width="180" />
      <el-table-column label="发生地点" align="center" prop="occuLoc" v-if="columns.occuLoc.visible" :show-overflow-tooltip="true" />
      <el-table-column label="死亡/重伤/失踪" align="center" width="160" v-if="columns.casNum.visible">
        <template #default="scope">
          {{ scope.row.casNum || 0 }}/{{ scope.row.serInjNum || 0 }}/{{ scope.row.missNum || 0 }}
        </template>
      </el-table-column>
      <el-table-column label="经济损失(万元)" align="center" prop="econLoss" v-if="columns.econLoss.visible" width="130" />
    </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 name="AcciZjIndex">
import { listObjAcci } from "@/api/slaj/acci"

const { proxy } = getCurrentInstance()
const { acci_grad, acci_cate, rep_stat } = proxy.useDict("acci_grad", "acci_cate", "rep_stat")

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

const columns = ref({
  acciName: { label: '事故名称', visible: true },
  acciGrad: { label: '事故等级', visible: true },
  acciCate: { label: '事故类别', visible: true },
  repStat: { label: '报告状态', visible: true },
  occuTime: { label: '发生时间', visible: true },
  occuLoc: { label: '发生地点', visible: true },
  casNum: { label: '死亡/重伤/失踪', visible: true },
  econLoss: { label: '经济损失(万元)', visible: true }
})

const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  acciName: undefined
})

function getList() {
  loading.value = true
  listObjAcci(proxy.addDateRange(queryParams, dateRange.value)).then(res => {
    loading.value = false
    objAcciList.value = res.rows
    total.value = res.total
  })
}

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

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

function handleExport() {
  proxy.download("acci/objacci/export", {
    ...queryParams,
    params: proxy.addDateRange(queryParams, dateRange.value)
  }, `acciZjIndex_${new Date().getTime()}.xlsx`)
}

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

<style scoped>
.desc-text {
  font-size: 14px;
  line-height: 1.8;
  color: var(--el-text-color-secondary);
}
</style>
