<template>
  <div class="wait-task-exam part-box part-box-pad part-box-border">
    <div class="task-head part-box part-box-flex">
      <h3>
        命题分配待办（<span class="color-danger">{{ total }}</span
        >）
      </h3>
      <div>
        <i class="el-icon-s-fold"></i>
      </div>
    </div>
    <div class="task-list">
      <div v-for="task in tasks" :key="task.id" class="task-item">
        <p>
          <span>试卷编号：</span>
          <span>{{ task.paperNumber }}</span>
        </p>
        <p>
          <span>课程（代码）：</span>
          <span>{{ task.courseName }}（{{ task.courseCode }}）</span>
        </p>
        <p>
          <span>命题结束时间：</span>
          <span>{{ task.endTime | timestampFilter }}</span>
        </p>
        <div class="part-box-flex">
          <el-tag :type="task.residueTips.status" effect="dark">
            {{ task.residueTips.title }}
          </el-tag>
          <span class="task-action" @click="toDo(task)"
            >立即处理 <i class="el-icon-arrow-right"></i
          ></span>
        </div>
      </div>
    </div>
    <div class="text-center">
      <el-pagination
        background
        layout="total,prev, pager, next"
        :current-page="current"
        :total="total"
        :page-size="size"
        @current-change="toPage"
      >
      </el-pagination>
    </div>

    <!-- ModifyExamTask -->
    <modify-exam-task
      ref="ModifyExamTask"
      :instance="curTask"
      :edit-type="editType"
      @modified="modified"
    ></modify-exam-task>
  </div>
</template>

<script>
import { waitExamTaskNewListPage } from "../api";
import ModifyExamTask from "./ModifyExamTask";
import { residueFloorTime } from "@/plugins/utils";
import { TASK_WARNING_TIME } from "@/constants/enumerate";

export default {
  name: "wait-task-exam",
  components: { ModifyExamTask },
  data() {
    return {
      total: 0,
      current: 1,
      size: this.GLOBAL.pageSize,
      tasks: [],
      curTask: {},
      editType: "EDIT"
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    async getList() {
      const datas = {
        pageNumber: this.current,
        pageSize: this.size
      };
      const data = await waitExamTaskNewListPage(datas);
      this.tasks = data.records.map(item => {
        item.residueTips = residueFloorTime(
          item.endTime - item.systemCurrentTime,
          TASK_WARNING_TIME
        );
        return item;
      });
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    toDo(task) {
      this.curTask = task;
      this.$refs.ModifyExamTask.open();
    },
    modified() {
      this.$emit("update-list");
    }
  }
};
</script>
