<template>
  <div class="wait-task-mark">
    <div class="part-box part-box-pad">
      <el-table ref="TableList" :data="dataList" :height="tableHeight">
        <el-table-column
          type="index"
          label="序号"
          width="70"
          :index="indexMethod"
        ></el-table-column>
        <el-table-column
          prop="courseName"
          label="课程（代码）"
          min-width="300"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            {{ scope.row.courseName }}（{{ scope.row.courseCode }}）
          </template>
        </el-table-column>
        <el-table-column
          prop="paperNumber"
          label="试卷编号"
          min-width="200"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="groupQuestions"
          label="评阅题目"
          width="115"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="markedCount"
          label="已评"
          width="80"
        ></el-table-column>
        <el-table-column
          prop="leftCount"
          label="待评"
          width="80"
        ></el-table-column>
        <el-table-column prop="percent" label="评卷进度" width="90">
          <span slot-scope="scope"> {{ scope.row.percent || 0 }}%</span>
        </el-table-column>
        <el-table-column
          class-name="action-column"
          label="操作"
          width="100"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              class="btn-primary"
              type="text"
              @click="toMark(scope.row)"
              >点击评卷</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div v-if="!isOnePage" class="part-page">
        <el-pagination
          background
          layout="total, prev, pager, next, jumper"
          :pager-count="5"
          :current-page="current"
          :total="total"
          :page-size="size"
          @current-change="toPage"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions } from "vuex";
import markMinxin from "@/modules/mark/markMinxin";
import { markWaitTaskListPage } from "../api";

export default {
  name: "wait-task-mark",
  mixins: [markMinxin],
  data() {
    return {
      current: 1,
      size: 2,
      total: 0,
      dataList: [],
      curTask: {},
    };
  },
  computed: {
    ...mapState("exam", ["waitTask"]),
    isOnePage() {
      return this.waitTask.mark <= 3;
    },
    pageSize() {
      return this.isOnePage ? 3 : 2;
    },
    tableHeight() {
      return this.isOnePage ? 174 : 127;
    },
  },
  mounted() {
    window.addEventListener("focus", this.updateList);
    this.getList();
  },
  beforeDestroy() {
    window.removeEventListener("focus", this.updateList);
  },
  methods: {
    ...mapActions("exam", ["updateWaitTaskCount"]),
    async updateList() {
      await this.updateWaitTaskCount();
      await this.getList();
    },
    async getList() {
      const datas = {
        pageNumber: this.current,
        pageSize: this.pageSize,
      };
      const data = await markWaitTaskListPage(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    search() {
      this.toPage(1);
    },
    toMark(row) {
      this.toMarkMark(row);
    },
  },
};
</script>
