<template>
  <div class="wait-task-stmms">
    <div class="part-box part-box-pad">
      <el-table ref="TableList" :data="dataList">
        <el-table-column prop="courseName" label="课程（代码）" min-width="200">
          <span slot-scope="scope">
            {{ scope.row.courseName }}（{{ scope.row.courseCode }}）
          </span>
        </el-table-column>
        <el-table-column
          prop="paperNumber"
          label="试卷编号"
          min-width="160"
        ></el-table-column>
        <el-table-column
          prop="paperType"
          label="试卷类型"
          width="100"
        ></el-table-column>
        <el-table-column
          class-name="action-column"
          label="操作"
          width="160"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              class="btn-primary"
              type="text"
              :disabled="scope.row.taskStatus === 'RUNNING'"
              @click="toSetParams(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>

    <ModifyMarkParams
      ref="ModifyMarkParams"
      :instance="curTask"
      @modified="updateList"
    />
  </div>
</template>

<script>
import { mapActions, mapMutations } from "vuex";
import { stmmsTaskListPage } from "../api";
import ModifyMarkParams from "../../mark/components/markParam/ModifyMarkParams";

export default {
  name: "wait-task-stmms",
  components: {
    ModifyMarkParams,
  },
  data() {
    return {
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: [],
      curTask: {},
      curMarkLeaders: [],
    };
  },
  mounted() {
    this.initData();
  },
  methods: {
    ...mapMutations("exam", ["updateWaitTask"]),
    ...mapActions("exam", ["updateWaitTaskCount"]),
    updateList() {
      this.getList();
      this.updateWaitTaskCount();
    },
    async initData() {
      await this.getList();

      const presetTask = this.$ls.get("wait_task_stmms");
      if (presetTask) {
        this.$nextTick(() => {
          this.toSetParams(presetTask);
        });
        this.$ls.remove("wait_task_stmms");
      }
    },
    async getList() {
      const datas = {
        pageNumber: this.current,
        pageSize: this.size,
      };
      const data = await stmmsTaskListPage(datas);
      this.dataList = data.records;
      this.total = data.total;
      this.updateWaitTask({ stmms: this.total });
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    toSetParams(row) {
      this.curTask = row;
      this.$refs.ModifyMarkParams.open();
    },
  },
};
</script>
