<template>
  <div class="exam-room-detail">
    <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: 193px;"
            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="场次ID：" label-width="75px">
          <el-select
            v-model="filter.examId"
            style="width: 193px;"
            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="考点：" label-width="55px">
          <el-select
            v-model="filter.examId"
            style="width: 193px;"
            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-button @click="goback">返回</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 prop="examName" label="考试名称"></el-table-column>
        <el-table-column prop="paperStatus" label="考场名称"></el-table-column>
        <el-table-column
          prop="cardStatus"
          label="科目名称(ID)"
        ></el-table-column>
        <el-table-column prop="createTime" 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 { PRINT_STATUS } from "@/constants/enumerate";
import { examRoomDetail, examList } from "../api";

export default {
  name: "exam-room-detail",
  data() {
    return {
      filter: {
        examId: this.$route.params.examId,
        examSite: "",
        sceneNumberId: ""
      },
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      visible: false,
      PRINT_STATUS,
      exams: [],
      examPages: []
    };
  },
  created() {
    this.getList();
    this.getExamList();
  },
  methods: {
    async getList() {
      const datas = {
        ...this.filter,
        pageNumber: this.current,
        pageSize: this.size
      };
      const data = await examRoomDetail(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.map(item => {
        return {
          id: item.id,
          name: item.examName
        };
      });
    },
    toDetail(row) {
      this.$router.push({
        name: "ExamRomeStudentDetail",
        params: {
          examRoomId: "1"
        }
      });
    }
  }
};
</script>
