<template>
  <div class="part-box is-border">
    <el-form inline>
      <el-form-item label="科目">
        <select-subject v-model="searchModel.subjectCode"></select-subject>
      </el-form-item>
      <el-form-item>
        <el-space wrap>
          <el-button type="primary" @click="toPage(1)">查询</el-button>
          <el-button @click="onExport">导出</el-button>
        </el-space>
      </el-form-item>
    </el-form>
    <el-divider class="form-divider" />

    <el-table
      class="page-table"
      :data="dataList"
      :loading="loading"
      border
      stripe
    >
      <el-table-column type="index" label="序号" width="60" />
      <el-table-column prop="mainTitle" label="大题名称" min-width="150" />
      <el-table-column prop="mainNumber" label="大题号" min-width="80" />
      <el-table-column prop="totalScore" label="满分" min-width="80" />
      <el-table-column prop="maxScore" label="最高分" min-width="100" />
      <el-table-column prop="minScore" label="最低分" min-width="100" />
      <el-table-column prop="avgScore" label="平均分" min-width="100">
        <template #default="scope">
          {{ scope.row.avgScore?.toFixed(2) }}
        </template>
      </el-table-column>
      <el-table-column prop="stdev" label="标准差" min-width="100">
        <template #default="scope">
          {{ scope.row.stdev?.toFixed(2) }}
        </template>
      </el-table-column>
      <el-table-column prop="coefficient" label="差异系数" min-width="100">
        <template #default="scope">
          {{ scope.row.coefficient?.toFixed(2) }}
        </template>
      </el-table-column>
      <el-table-column label="得分率" min-width="100">
        <template #default="scope">
          {{ (scope.row.scoreRate * 100).toFixed(2) }}%
        </template>
      </el-table-column>
      <el-table-column prop="zeroCount" label="零分人数" min-width="100" />
      <el-table-column prop="fullCount" label="满分人数" min-width="100" />
    </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 { getBigQuestionAnalysisList } from '@/api/analysis';
  import {
    BigQuestionAnalysisItem,
    AnalysisListFilter,
  } from '@/api/types/analysis';
  import useTable from '@/hooks/table';
  import { downloadExport } from '@/utils/download-export';

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

  const searchModel = reactive<AnalysisListFilter>({
    subjectCode: null,
  });

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

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