<template>
  <div class="card-check">
    <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.auditingStatus"
            style="width: 142px;"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="(val, key) in AUDITING_STATUS"
              :key="key"
              :value="key"
              :label="val"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="印刷时间：">
          <el-date-picker
            v-model="filter.printTime"
            type="date"
            placeholder="请选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="标题：" label-width="55px">
          <el-input
            style="width: 210px;"
            v-model.trim="filter.title"
            placeholder="请输入内容"
            clearable
          ></el-input>
        </el-form-item>

        <el-form-item label-width="0px">
          <el-button type="primary" icon="icon icon-search" @click="toPage(1)"
            >查询</el-button
          >
          <el-button type="warning" icon="icon icon-plus" @click="toAdd"
            >创建题卡</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <div class="part-box">
      <el-table ref="TableList" :data="examPages" border stripe>
        <el-table-column prop="id" label="题目ID"></el-table-column>
        <el-table-column label="科目(代码)">
          <template slot-scope="scope">
            <span>{{ scope.row.courseName }}({{ scope.row.courseCode }})</span>
          </template>
        </el-table-column>
        <el-table-column prop="title" label="标题"></el-table-column>
        <el-table-column prop="printTime" label="打印时间"></el-table-column>
        <el-table-column prop="cardStatus" label="处理节点"></el-table-column>
        <el-table-column prop="overtime" label="剩余时间"></el-table-column>
        <el-table-column
          prop="auditingTime"
          label="提交审核时间"
        ></el-table-column>
        <el-table-column
          prop="auditingStatus"
          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-edit"
              @click="toEdit(scope.row)"
              title="确认"
            ></el-button>
            <el-button
              class="btn-table-icon"
              type="text"
              icon="icon icon-delete"
              @click="toEdit(scope.row)"
              title="确认"
            ></el-button>
            <el-button
              class="btn-table-icon"
              type="text"
              icon="icon icon-circle-share"
              @click="toEdit(scope.row)"
              title="确认"
            ></el-button>
            <el-button
              class="btn-table-icon"
              type="text"
              icon="icon icon-copy"
              @click="toEdit(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>

    <!-- modify-data -->
    <modify-data
      :instance="curExam"
      @modified="getList"
      ref="ModifyData"
    ></modify-data>
  </div>
</template>

<script>
import { AUDITING_STATUS } from "@/constants/enumerate";
import { printTaskListPage, examList } from "../api";
import ModifyData from "../components/ModifyData";

export default {
  name: "card-check",
  components: { ModifyData },
  data() {
    return {
      filter: {
        title: "",
        auditingStatus: "",
        printTime: ""
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      visible: false,
      AUDITING_STATUS,
      exams: [],
      examPages: [{ id: "" }],
      curExam: {}
    };
  },
  created() {
    // this.getList();
  },
  methods: {
    async getList() {
      const datas = {
        ...this.filter,
        pageNumber: this.current,
        pageSize: this.size
      };
      const data = await printTaskListPage(datas);
      this.examPages = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    async getExamList() {
      const data = await examList();
      this.exams = data.records.map(item => {
        return {
          id: item.examCode,
          name: item.examName
        };
      });
    },
    toAdd() {
      this.$router.push({
        name: "CardDesign"
      });
    },
    toEdit(row) {
      this.curExam = row;
      this.$refs.ModifyData.open();
    }
  }
};
</script>
