<template>
  <div class="part-box is-border">
    <el-form inline>
      <el-form-item label="科目">
        <select-subject v-model="searchModel.subject"></select-subject>
      </el-form-item>
      <el-form-item label="分组">
        <el-input
          v-model.trim="searchModel.group"
          placeholder="请输入分组"
          clearable
          style="width: 120px"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="准考证号">
        <el-input
          v-model.trim="searchModel.examCardNo"
          placeholder="请输入准考证号"
          clearable
          style="width: 150px"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="密号">
        <el-input
          v-model.trim="searchModel.secretNo"
          placeholder="请输入密号"
          clearable
          style="width: 120px"
        >
        </el-input>
      </el-form-item>
    </el-form>
    <el-divider class="form-divider" />
    <div class="part-action">
      <el-space wrap>
        <el-button type="primary" @click="toPage(1)">查询</el-button>
        <el-button @click="onExport">导出</el-button>
      </el-space>
    </div>

    <el-table
      class="page-table"
      :data="dataList"
      :loading="loading"
      border
      stripe
      @sort-change="handleSortChange"
    >
      <el-table-column prop="subjectCode" label="科目代码" min-width="200" />
      <el-table-column prop="groupNo" label="分组序号" width="110" sortable />
      <el-table-column prop="examCardNo" label="准考证号" width="150" />
      <el-table-column prop="secretNo" label="密号" width="120" />
      <el-table-column prop="marker" label="评卷员" width="120" sortable />
      <el-table-column
        prop="totalScore"
        label="评卷总分"
        width="110"
        sortable
      />
      <el-table-column
        prop="giveScoreDetail"
        label="给分明细"
        min-width="200"
        show-overflow-tooltip
      />
      <el-table-column
        prop="markingTime"
        label="评卷时间"
        width="200"
        sortable
      />
      <el-table-column label="操作" width="120" fixed="right">
        <template #default="scope">
          <el-button
            type="primary"
            size="small"
            link
            @click="onView(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 { ElMessage } from 'element-plus';
  import { getMarkTrialList } from '@/api/mark';
  import { MarkTrialItem, MarkTrialListFilter } from '@/api/types/mark';
  import useTable from '@/hooks/table';

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

  const searchModel = reactive<MarkTrialListFilter>({
    subject: null,
    group: '',
    examCardNo: '',
    secretNo: '',
  });

  const {
    dataList,
    pagination,
    loading,
    toPage,
    pageSizeChange,
    handleSortChange,
  } = useTable<MarkTrialItem>(getMarkTrialList, searchModel, false);

  // 查看详情
  function onView(row: MarkTrialItem) {
    ElMessage.info(`查看试卷：${row.examCardNo}`);
    // TODO: 实现查看试卷详情的逻辑
  }

  function onExport() {
    // TODO: 导出试卷
    ElMessage.info('导出试卷');
  }
</script>
