<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-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="subject" label="科目" min-width="100" />
      <el-table-column prop="groupNo" label="分组序号" width="100" />
      <el-table-column prop="examNo" label="准考证号" width="120" />
      <el-table-column prop="secretNo" label="密号" width="100" />
      <el-table-column prop="rejectReason" label="打回原因" min-width="150" />
      <el-table-column prop="marker" label="评卷员" width="100" />
      <el-table-column prop="scoreDetails" label="给分明细" min-width="120" />
      <el-table-column prop="rejectBy" label="打回人" width="100" />
      <el-table-column label="打回时间" width="180">
        <template #default="scope">
          {{ timestampFilter(scope.row.rejectTime) }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="100" fixed="right">
        <template #default="scope">
          <el-button type="primary" link @click="onViewDetail(scope.row)">
            查看详情
          </el-button>
        </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 { getRejectList } from '@/api/reject';
  import { RejectItem, RejectListFilter } from '@/api/types/reject';
  import useTable from '@/hooks/table';
  import { timestampFilter } from '@/utils/filter';

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

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

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

  function onViewDetail(row: RejectItem) {
    // TODO: 实现查看详情功能
    console.log('查看详情:', row);
  }
</script>
