<template>
  <div class="wait-task-audit 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>
        <p>
          <span>命题老师：</span>
          <span>{{ task.userName }}</span>
        </p>
        <p>
          <span>提交时间：</span>
          <span>{{ task.createTime | 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, 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>

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

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

export default {
  name: "wait-task-audit",
  components: { ModifyTaskApply },
  data() {
    return {
      total: 0,
      current: 1,
      size: this.GLOBAL.pageSize,
      tasks: [],
      curTask: {},
      editType: "AUDIT",
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    async getList() {
      const datas = {
        pageNumber: this.current,
        pageSize: this.size,
      };
      const data = await waitTaskReviewListPage(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, source: "REVIEW" };
      this.$refs.ModifyTaskApply.open();
    },
    modified() {
      this.$emit("update-list");
    },
  },
};
</script>
