<template>
  <div class="wait-task-stmms">
    <div class="part-box part-box-pad">
      <el-table ref="TableList" :data="dataList">
        <el-table-column
          type="index"
          label="序号"
          width="50"
          :index="indexMethod"
        ></el-table-column>
        <el-table-column prop="thirdRelateId" label="考试ID"></el-table-column>
        <el-table-column
          prop="thirdRelateName"
          label="考试名称"
        ></el-table-column>
        <el-table-column prop="paperNumber" label="试卷ID"></el-table-column>
        <el-table-column
          prop="paperType"
          label="试卷类型"
          width="80"
        ></el-table-column>
        <el-table-column prop="statusStr" label="状态" width="100">
        </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="toDo(scope.row)"
              >立即处理</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="part-page">
        <el-pagination
          background
          layout="total,prev, pager, next"
          :current-page="current"
          :total="total"
          :page-size="size"
          @current-change="toPage"
        >
        </el-pagination>
      </div>
    </div>

    <!-- UploadPaperAnswerDialog -->
    <UploadPaperAnswerDialog
      ref="UploadPaperAnswerDialog"
      :instance="curTask"
      @modified="taskModified"
    />
  </div>
</template>

<script>
import { mapActions, mapMutations } from "vuex";
import { stmmsTaskListPage } from "../api";
import UploadPaperAnswerDialog from "../../stmms/components/UploadPaperAnswerDialog";

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

      const presetTask = this.$ls.get("wait_task_stmms");
      if (presetTask) {
        this.$nextTick(() => {
          this.toDo(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();
    },
    toDo(row) {
      this.curTask = row;
      this.$refs.UploadPaperAnswerDialog.open();
    },
    taskModified() {
      this.getList();
      this.updateWaitTaskCount();
    }
  }
};
</script>
