<template>
  <el-dialog
    custom-class="statistics-dialog"
    title="试卷分析"
    :visible.sync="modalIsShow"
    :modal="true"
    fullscreen
    append-to-body
    @open="toPage(1)"
  >
    <div class="statistics">
      <el-table
        v-loading="loading"
        element-loading-text="加载中"
        :data="tableData"
      >
        试卷名称
        <el-table-column prop="paperName" label="试卷名称"> </el-table-column>
        <el-table-column prop="totalScore" label="试卷总分" width="100">
        </el-table-column>
        <el-table-column prop="difficult" label="难度" width="100">
        </el-table-column>
        <el-table-column prop="paperDetailCount" label="大题数" width="100">
        </el-table-column>
        <el-table-column prop="unitCount" label="小题数" width="100">
        </el-table-column>
        <el-table-column prop="creatorName" label="创建人" width="120">
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="170">
        </el-table-column>
      </el-table>
      <div class="part-page">
        <el-pagination
          :current-page.sync="currentPage"
          :page-size.sync="pageSize"
          :page-sizes="[10, 20, 50, 100, 200, 300]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @current-change="toPage"
          @size-change="handleSizeChange"
        />
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { coursePaperInfoApi } from "../api";

export default {
  name: "StatisticsPaperDialog",
  props: {
    courseId: {
      type: [String, Number],
      default: null,
    },
  },
  data() {
    return {
      modalIsShow: false,
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      total: 10,
      loading: false,
    };
  },
  methods: {
    cancel() {
      this.modalIsShow = false;
    },
    open() {
      this.modalIsShow = true;
    },
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
      this.getList();
    },
    toPage(val) {
      this.currentPage = val;
      this.getList();
    },
    async getList() {
      this.tableData = [];
      this.loading = true;
      const res = await coursePaperInfoApi({
        courseId: this.courseId,
        pageNumber: this.currentPage,
        pageSize: this.pageSize,
      }).catch(() => {});
      this.loading = false;
      if (!res) return;
      this.total = res.data.totalElements;
      this.tableData = res.data.content || [];
    },
  },
};
</script>
