<template>
  <div class="part-box is-filter">
    <el-form inline>
      <el-form-item label="科目">
        <select-subject v-model="searchModel.subject"></select-subject>
      </el-form-item>
      <el-form-item label="分组">
        <el-input-number
          v-model.number="searchModel.groupNo"
          :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.marker"
          placeholder="请输入"
          clearable
          style="width: 120px"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="打回人">
        <el-input
          v-model.trim="searchModel.rejectBy"
          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="exportData">导出</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 property="subject" label="科目" min-width="100" />
      <el-table-column property="groupNo" label="分组序号" width="100" />
      <el-table-column property="examNo" label="准考证号" width="120" />
      <el-table-column property="secretNo" label="密号" width="100" />
      <el-table-column
        property="rejectReason"
        label="打回原因"
        min-width="150"
      />
      <el-table-column property="marker" label="评卷员" width="100" />
      <el-table-column
        property="scoreDetails"
        label="给分明细"
        min-width="120"
      />
      <el-table-column property="rejectBy" 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';

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

  const searchModel = reactive<RejectListFilter>({
    subject: null,
    groupNo: undefined,
    rejectReason: '',
    marker: '',
    rejectBy: '',
  });

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

  function exportData() {
    // TODO: 实现导出功能
    console.log('导出问题卷数据');
  }
</script>
