<template>
  <div class="score-check">
    <div class="part-box part-box-filter part-box-flex">
      <el-form ref="FilterForm" label-position="left" label-width="85px" inline>
        <template v-if="checkPrivilege('condition', 'condition')">
          <secp-select
            v-model="filter"
            defaultSelectExam
            @exam-default="search"
          ></secp-select>
        </template>
        <el-form-item label-width="0px">
          <el-button
            v-if="checkPrivilege('button', 'select')"
            type="primary"
            @click="search"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
      <div class="part-box-action"></div>
    </div>

    <div class="part-box part-box-pad">
      <el-table
        ref="TableList"
        :data="dataList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
          align="center"
        ></el-table-column>
        <el-table-column prop="courseName" label="课程（代码）" min-width="200">
          <template slot-scope="scope">
            {{ scope.row.courseName }}（{{ scope.row.courseCode }}）
          </template>
        </el-table-column>
        <el-table-column
          prop="paperNumber"
          label="试卷编号"
          min-width="140"
        ></el-table-column>
        <el-table-column prop="studentCount" label="参考人数" width="100">
        </el-table-column>
        <el-table-column
          class-name="action-column"
          label="操作"
          width="200"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              v-if="checkPrivilege('link', 'Detail')"
              class="btn-primary"
              type="text"
              @click="toDetail(scope.row)"
              >查看详情</el-button
            >
            <el-button
              v-if="checkPrivilege('link', 'PackageDetail')"
              class="btn-primary"
              type="text"
              @click="toViewSign(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>

    <!-- ScoreCheckDetail -->
    <score-check-detail
      ref="ScoreCheckDetail"
      :instance="curRow"
    ></score-check-detail>
    <!-- ScoreCheckSign -->
    <score-check-sign
      ref="ScoreCheckSign"
      :instance="curRow"
    ></score-check-sign>
  </div>
</template>

<script>
import { scoreCheckListPage } from "../api";
import ScoreCheckDetail from "../components/ScoreCheckDetail.vue";
import ScoreCheckSign from "../components/ScoreCheckSign.vue";

export default {
  name: "score-check",
  components: { ScoreCheckDetail, ScoreCheckSign },
  data() {
    return {
      filter: {
        semesterId: "",
        examId: "",
        courseCode: "",
        paperNumber: "",
        progressStatus: null,
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: [],
      curRow: {},
      multipleSelection: [],
      downloading: false,
      // img view
      curImage: {},
      curImageIndex: 0,
      imageList: [],
    };
  },
  methods: {
    async getList() {
      if (!this.checkPrivilege("list", "list")) return;

      const datas = {
        ...this.filter,
        pageNumber: this.current,
        pageSize: this.size,
      };
      if (datas.progressStatus !== null && datas.progressStatus !== "")
        datas.progressStatus = !!datas.progressStatus;

      const data = await scoreCheckListPage(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    search() {
      this.toPage(1);
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    toDetail(row) {
      this.curRow = row;
      this.$refs.ScoreCheckDetail.open();
    },
    toViewSign(row) {
      this.curRow = row;
      this.$refs.ScoreCheckSign.open();
    },
  },
};
</script>
