<template>
  <div class="part-box is-filter">
    <el-form inline>
      <el-form-item label="科目">
        <select-subject v-model="searchModel.subjectCode"></select-subject>
      </el-form-item>
      <el-form-item label="分组">
        <el-input-number
          v-model.number="searchModel.groupNumber"
          :min="1"
          :max="999"
          :step="1"
          :precision="0"
          :controls="false"
          step-strictly
          placeholder="请输入"
          style="width: 120px"
        >
        </el-input-number>
      </el-form-item>
      <el-form-item label="打回原因">
        <el-input
          v-model.trim="searchModel.rejectReason"
          placeholder="请输入"
          clearable
          style="width: 120px"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="评卷员">
        <el-input
          v-model.trim="searchModel.markerId"
          placeholder="请输入"
          clearable
          style="width: 120px"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="打回人">
        <el-input
          v-model.trim="searchModel.headerId"
          placeholder="请输入"
          clearable
          style="width: 120px"
        >
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="toPage(1)">查询</el-button>
        <el-button @click="onExport">导出</el-button>
      </el-form-item>
    </el-form>
  </div>
  <div class="part-box">
    <el-table
      class="page-table"
      :data="dataList"
      :loading="loading"
      border
      stripe
    >
      <el-table-column type="index" label="序号" width="60" />
      <el-table-column prop="subjectName" label="科目" min-width="100" />
      <el-table-column prop="groupNumber" label="分组序号" width="100" />
      <el-table-column prop="examNumber" label="准考证号" width="120" />
      <el-table-column prop="secretNumber" label="密号" width="100" />
      <el-table-column prop="rejectReason" label="打回原因" min-width="150" />
      <el-table-column prop="markerName" label="评卷员" width="100" />
      <el-table-column prop="scoreList" label="给分明细" min-width="120" />
      <el-table-column prop="headerName" label="打回人" width="100" />
      <el-table-column label="打回时间" width="180">
        <template #default="scope">
          {{ timestampFilter(scope.row.rejectTime) }}
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      v-model:current-page="pagination.pageNumber"
      v-model:page-size="pagination.pageSize"
      :layout="pagination.layout"
      :total="pagination.total"
      @size-change="pageSizeChange"
      @current-change="toPage"
    />
  </div>
</template>

<script setup lang="ts">
  import { reactive } from 'vue';
  import { getRejectRecordList } from '@/api/reject';
  import { RejectItem, RejectListFilter } from '@/api/types/reject';
  import useTable from '@/hooks/table';
  import { timestampFilter } from '@/utils/filter';
  import { downloadExport } from '@/utils/download-export';

  defineOptions({
    name: 'RejectRecord',
  });

  const searchModel = reactive<RejectListFilter>({
    subjectCode: null,
    groupNumber: undefined,
    rejectReason: '',
    markerId: null,
    headerId: null,
  });

  const { dataList, pagination, loading, toPage, pageSizeChange } =
    useTable<RejectItem>(getRejectRecordList, searchModel, false);

  async function onExport() {
    await downloadExport('exportRejectRecord', searchModel);
  }
</script>
