<template>
  <div class="part-box is-border">
    <div class="part-action">
      <el-space wrap>
        <el-button>查重</el-button>
        <el-button>批量校验：{{ dataList.length }}</el-button>
        <el-button @click="onExport">导出</el-button>
      </el-space>
    </div>
    <el-divider class="form-divider" />
    <el-table
      class="page-table"
      :data="dataList"
      :loading="loading"
      border
      stripe
    >
      <el-table-column type="selection" width="55" />
      <el-table-column prop="studentCode" label="考生编号" width="150" />
      <el-table-column prop="subjectName" label="科目" width="200" />
      <el-table-column prop="fullScore" label="满分" width="100" />
      <el-table-column label="状态" width="120">
        <template #default="scope">
          <el-tag :type="getStatusType(scope.row.status)">
            {{ scope.row.status }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="totalScore" label="试卷总分" width="100" />
      <el-table-column
        prop="subjectiveScoreList"
        label="得分明细"
        min-width="200"
      >
      </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 { getScoreCheckList } from '@/api/review';
  import { ScoreCheckItem } from '@/api/types/review';
  import useTable from '@/hooks/table';
  import { downloadExport } from '@/utils/download-export';

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

  // 由于接口不需要参数，使用空对象
  const searchModel = reactive({});

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

  // 获取状态标签类型
  function getStatusType(status: string) {
    switch (status) {
      case '已上传':
        return 'success';
      case '正常':
        return 'success';
      case '未上传':
        return 'warning';
      default:
        return 'info';
    }
  }

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