<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-select
          v-model="searchModel.paperType"
          placeholder="请选择"
          clearable
          style="width: 150px"
        >
          <el-option label="A卷" value="A" />
          <el-option label="B卷" value="B" />
          <el-option label="C卷" value="C" />
        </el-select>
      </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="questionName" label="题目名称" min-width="150" />
      <el-table-column prop="bigQuestionNo" label="大题号" min-width="80" />
      <el-table-column prop="smallQuestionNo" label="小题号" min-width="80" />
      <el-table-column
        prop="singleQuestionScore"
        label="单题分数"
        min-width="100"
      />
      <el-table-column
        prop="singleQuestionAverageScore"
        label="单题平均分"
        min-width="120"
      >
        <template #default="scope">
          {{ scope.row.singleQuestionAverageScore?.toFixed(2) }}
        </template>
      </el-table-column>
      <el-table-column
        prop="singleQuestionStandardDeviation"
        label="单题标准差"
        min-width="120"
      >
        <template #default="scope">
          {{ scope.row.singleQuestionStandardDeviation?.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 label="满分率" min-width="100">
        <template #default="scope">
          {{ (scope.row.fullScoreRate * 100).toFixed(2) }}%
        </template>
      </el-table-column>
      <el-table-column prop="paperType" 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 { getObjectiveQuestionAnalysisList } from '@/api/analysis';
  import {
    QuestionAnalysisItem,
    QuestionAnalysisFilter,
  } from '@/api/types/analysis';
  import useTable from '@/hooks/table';

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

  const searchModel = reactive<QuestionAnalysisFilter>({
    subject: null,
    paperType: '',
  });

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

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