<template>
  <div class="score-archive">
    <div class="part-box part-box-filter">
      <el-form ref="FilterForm" label-position="left" inline>
        <template v-if="checkPrivilege('condition', 'condition')">
          <el-form-item label="学期：">
            <semester-select
              v-model="filter.semesterId"
              default-select
              :clearable="false"
            ></semester-select>
          </el-form-item>
          <el-form-item label="考试：">
            <exam-select
              v-model="filter.examId"
              :semester-id="filter.semesterId"
              default-select
              :clearable="false"
              @default-selected="toPage(1)"
            ></exam-select>
          </el-form-item>
          <el-form-item label="课程：">
            <course-select
              v-model="filter.courseId"
              placeholder="课程"
              filterable
              clearable
              :semester-id="filter.semesterId"
              :exam-id="filter.examId"
            ></course-select>
          </el-form-item>
        </template>
        <el-form-item label-width="0px">
          <el-button
            v-if="checkPrivilege('button', 'select')"
            type="primary"
            @click="toPage(1)"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <div class="part-box part-box-pad">
      <el-table ref="TableList" :data="dataList">
        <el-table-column
          type="index"
          label="序号"
          width="70"
          :index="indexMethod"
        ></el-table-column>
        <el-table-column prop="name" label="课程名称（代码）" min-width="260">
          <span slot-scope="scope"
            >{{ scope.row.courseName }}（{{ scope.row.courseCode }}）</span
          >
        </el-table-column>
        <el-table-column
          prop="paperNumber"
          label="试卷编号"
          width="200"
        ></el-table-column>
        <el-table-column
          prop="studentCount"
          label="总考生"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="classCount"
          label="参考班级"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="absentCount"
          label="缺考人数"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="avgScore"
          label="平均分"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="maxScore"
          label="最高分"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="minScore"
          label="最低分"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="passCount"
          label="及格人数"
          width="100"
        ></el-table-column>
        <el-table-column prop="passRate" label="及格率" width="100">
          <template slot-scope="scope">{{ scope.row.passRate || 0 }}%</template>
        </el-table-column>
        <el-table-column
          prop="excellentCount"
          label="优秀人数"
          width="100"
        ></el-table-column>
        <el-table-column prop="excellentRate" label="优秀率" width="100">
          <template slot-scope="scope"
            >{{ scope.row.excellentRate || 0 }}%</template
          >
        </el-table-column>
        <el-table-column
          class-name="action-column"
          label="操作"
          width="100px"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              v-if="checkPrivilege('link', 'ClassScoreDetail')"
              class="btn-primary"
              type="text"
              @click="toClass(scope.row)"
              >查看详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="part-page">
        <el-pagination
          background
          layout="total, sizes, prev, pager, next, jumper"
          :pager-count="5"
          :current-page="current"
          :total="total"
          :page-size="size"
          @current-change="toPage"
          @size-change="pageSizeChange"
        >
        </el-pagination>
      </div>
      <div class="tips-markedness">
        <p>
          如果成绩查询菜单下没有数据，请先在评卷管理模块—评卷管理菜单下，结束评卷
          <el-button
            type="text"
            class="btn-primary btn-link ml-2"
            @click="toMarkManage"
            >点击跳转评卷管理</el-button
          >
        </p>
      </div>
    </div>

    <!-- ScoreClassDetail -->
    <score-class-detail
      ref="ScoreClassDetail"
      :instance="curRow"
    ></score-class-detail>
  </div>
</template>

<script>
import { scoreListPage } from "../api";
import ScoreClassDetail from "../components/ScoreClassDetail.vue";

export default {
  name: "score-manage",
  components: { ScoreClassDetail },
  data() {
    return {
      filter: {
        semesterId: "",
        examId: "",
        courseId: "",
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: [],
      curRow: {},
    };
  },
  methods: {
    async getList() {
      if (!this.checkPrivilege("list", "list")) return;
      const datas = {
        ...this.filter,
        pageNumber: this.current,
        pageSize: this.size,
      };
      const data = await scoreListPage(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    toClass(row) {
      this.curRow = row;
      this.$refs.ScoreClassDetail.open();
    },
    toMarkManage() {
      this.$router.push({ name: "MarkManage" });
    },
  },
};
</script>
