<template>
  <el-dialog
    class="business-data"
    :visible.sync="modalIsShow"
    title="导入考务数据预览"
    top="10vh"
    width="840px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    @open="visibleChange"
  >
    <el-table ref="TableList" :data="dataList" border stripe>
      <el-table-column
        prop="sceneNumberId"
        label="场次ID"
        width="80"
      ></el-table-column>
      <el-table-column prop="examSite" label="考点名称"></el-table-column>
      <el-table-column prop="examRoom" label="考场名称"></el-table-column>
      <el-table-column
        prop="courseCodeAndName"
        label="科目名称(编码)"
      ></el-table-column>
      <el-table-column
        prop="examTotal"
        label="应考科次"
        width="100"
      ></el-table-column>
    </el-table>
    <div class="table-tips">
      将导入 <span>{{ total }}</span> 条数据
    </div>
    <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 slot="footer" style="text-align: right">
      <el-button type="primary" @click="cancel">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { examBusinessData } from "../api";

export default {
  name: "business-data",
  props: {
    examCode: {
      type: [String, Number]
    }
  },
  data() {
    return {
      modalIsShow: false,
      current: 1,
      size: this.GLOBAL.pageSize,
      total: 0,
      dataList: [],
      res: {
        success: true,
        msg: ""
      }
    };
  },
  methods: {
    visibleChange() {
      this.toPage(1);
    },
    async getList() {
      if (!this.examCode) return;
      const datas = {
        examCode: this.examCode,
        pageNumber: this.current,
        pageSize: this.size
      };
      const data = await examBusinessData(datas);
      this.dataList = data.records;
      this.total = data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    cancel() {
      this.modalIsShow = false;
    },
    open() {
      this.modalIsShow = true;
    },
    confirm() {
      this.$emit("confirm");
    }
  }
};
</script>

<style lang="css" scoped>
.table-tips {
  color: #888;
  float: left;
  margin-top: 21px;
}
.table-tips > span {
  color: rgba(254, 108, 105, 1);
}
</style>
