<template>
  <div class="wait-task">
    <div class="part-box part-box-filter">
      <el-form ref="FilterForm" label-position="left" label-width="85px" inline>
        <el-form-item label="考试名称：">
          <el-select
            v-model="filter.examId"
            style="width: 315px;"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="item in exams"
              :key="item.id"
              :value="item.id"
              :label="item.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label-width="0px">
          <el-button type="primary" icon="icon icon-search" @click="toPage(1)"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <div class="part-box">
      <el-table ref="TableList" :data="tasks" border stripe>
        <el-table-column prop="id" label="考试ID"></el-table-column>
        <el-table-column prop="examName" label="考试名称"></el-table-column>
        <el-table-column prop="courseNameCode" label="科目名称(编码)">
        </el-table-column>
        <el-table-column prop="paperStatus" label="试卷"></el-table-column>
        <el-table-column prop="cardStatus" label="答题卡"></el-table-column>
        <el-table-column prop="endTime" label="任务截止日期"></el-table-column>
        <el-table-column prop="overTime" label="剩余时间"></el-table-column>
        <el-table-column prop="receiveTime" label="接收时间"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              class="btn-table-icon"
              type="text"
              icon="icon icon-circle-right"
              @click="toDetail(scope.row)"
              title="详情"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="part-page">
        <el-pagination
          background
          layout="prev, pager, next"
          :current-page="current"
          :total="total"
          :page-size="size"
          @current-change="toPage"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { waitTaskListPage, examList } from "../api";

export default {
  name: "wait-task",
  data() {
    return {
      filter: {
        examId: ""
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      visible: false,
      exams: [],
      tasks: []
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      this.getExamList();
      this.getList();
    },
    async getList() {
      const datas = {
        ...this.filter,
        pageNumber: this.current,
        pageSize: this.size
      };
      const result = await waitTaskListPage(datas);
      const data = result || { records: [], total: 0 };
      this.tasks = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    async getExamList() {
      const data = await examList();
      this.exams = data.map(item => {
        return {
          id: item.id,
          name: item.examName
        };
      });
    },
    toDetail(row) {
      this.$router.push({
        name: "WaitTaskDetail",
        params: {
          taskId: row.id
        }
      });
    }
  }
};
</script>
