<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="部门名称" prop="deptName">
        <el-input v-model="queryParams.deptName" placeholder="请输入部门名称" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="队室/班组" prop="teamName">
        <el-input v-model="queryParams.teamName" placeholder="请输入队室/班组" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="小组" prop="groupName">
        <el-input v-model="queryParams.groupName" placeholder="请输入小组" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="姓名" prop="personName">
        <el-input v-model="queryParams.personName" placeholder="请输入姓名" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="类别" prop="examCategory">
        <el-input v-model="queryParams.examCategory" placeholder="请输入类别" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="期数" prop="examPeriod">
        <el-input v-model="queryParams.examPeriod" 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:examScore: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="examDate" width="110">
        <template #default="{ row }">{{ parseTime(row.examDate, '{y}-{m}-{d}') }}</template>
      </el-table-column>
      <el-table-column label="部门名称" align="center" prop="deptName" />
      <el-table-column label="队室/班组" align="center" prop="teamName" />
      <el-table-column label="小组" align="center" prop="groupName" />
      <el-table-column label="姓名" align="center" prop="personName" />
      <el-table-column label="类别" align="center" prop="examCategory" />
      <el-table-column label="期数" align="center" prop="examPeriod" />
      <el-table-column label="理论成绩" align="center" prop="theoryScore" width="100" />
      <el-table-column label="图像成绩" align="center" prop="imageScore" width="100" />
    </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 { listExamScore, exportExamScore } from '@/api/ledger/index'
import { parseTime } from '@/utils/ruoyi'
defineOptions({ name: 'LedgerExamScore' })
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, deptName: '', teamName: '', groupName: '', personName: '', examCategory: '', examPeriod: '' })
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] }
  listExamScore(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] }
  exportExamScore(p)
}
onMounted(getList)
</script>
