<template>
  <el-dialog
    class="breach-detail-dialog gray-dialog"
    :visible.sync="modalIsShow"
    title="违纪明细"
    width="1000px"
    top="94px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    @open="visibleChange"
  >
    <el-table ref="TableList" :data="dataList">
      <el-table-column
        prop="status"
        label="违纪处理/撤销违纪"
      ></el-table-column>
      <el-table-column prop="createName" label="操作人"></el-table-column>
      <el-table-column prop="endTime" label="异常处理结束时间">
        <span slot-scope="scope">{{ scope.row.endTime | datetimeFilter }}</span>
      </el-table-column>
      <el-table-column prop="type" label="类型/原因"></el-table-column>
      <el-table-column prop="description" label="详情备注"></el-table-column>
    </el-table>
    <div class="part-page">
      <el-pagination
        background
        layout="prev, pager, next,total,sizes,jumper"
        :current-page="current"
        :total="total"
        :page-size.sync="size"
        @size-change="toPage(1)"
        @current-change="toPage"
      >
      </el-pagination>
    </div>
    <div slot="footer"></div>
  </el-dialog>
</template>

<script>
import {
  reportBreachDetail,
  reportCancelBreachDetail,
} from "@/api/invigilation";

export default {
  name: "breach-detail-dialog",
  props: {
    detailId: {
      type: [String, Number],
      required: true,
    },
    isCancel: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      modalIsShow: false,
      current: 1,
      total: 0,
      size: 10,
      dataList: [],
    };
  },
  methods: {
    visibleChange() {
      this.toPage(1);
    },
    async getList() {
      const datas = {
        examStudentId: this.detailId,
        pageNumber: this.current,
        pageSize: this.size,
      };

      const func = this.isCancel
        ? reportCancelBreachDetail
        : reportBreachDetail;

      const res = await func(datas);

      this.dataList = res.data.data.records;
      this.total = res.data.data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    cancel() {
      this.modalIsShow = false;
    },
    open() {
      this.modalIsShow = true;
    },
  },
};
</script>
