<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>
        <el-space wrap>
          <el-button type="primary" @click="toPage(1)">查询</el-button>
          <el-button @click="exportData">导出</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="bigQuestionName"
        label="大题名称"
        min-width="150"
      />
      <el-table-column prop="bigQuestionNo" label="大题号" min-width="80" />
      <el-table-column prop="totalScore" label="满分" min-width="80" />
      <el-table-column prop="highestScore" label="最高分" min-width="100" />
      <el-table-column prop="lowestScore" label="最低分" min-width="100" />
      <el-table-column prop="averageScore" label="平均分" min-width="100">
        <template #default="scope">
          {{ scope.row.averageScore?.toFixed(2) }}
        </template>
      </el-table-column>
      <el-table-column prop="standardDeviation" label="标准差" min-width="100">
        <template #default="scope">
          {{ scope.row.standardDeviation?.toFixed(2) }}
        </template>
      </el-table-column>
      <el-table-column
        prop="differenceCoefficient"
        label="差异系数"
        min-width="100"
      >
        <template #default="scope">
          {{ scope.row.differenceCoefficient?.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="zeroScoreStudents"
        label="零分人数"
        min-width="100"
      />
      <el-table-column
        prop="fullScoreStudents"
        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';

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

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

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

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