<template>
  <el-dialog
    class="exception-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="startTime" label="异常处理开始时间">
        <span slot-scope="scope">{{
          scope.row.startTime | datetimeFilter
        }}</span>
      </el-table-column>
      <el-table-column prop="endTime" label="异常处理结束时间">
        <span slot-scope="scope">
          <span v-if="scope.row.endTime">{{
            scope.row.endTime | datetimeFilter
          }}</span>
          <span v-else>--</span>
        </span>
      </el-table-column>
      <el-table-column prop="reason" label="异常原因"></el-table-column>
      <el-table-column prop="totalTimeStr" 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 { reportExceptionDetail } from "@/api/invigilation";
import { timeNumberToText } from "@/utils/utils";

export default {
  name: "exception-detail-dialog",
  props: {
    detailId: {
      type: [String, Number],
      required: true,
    },
  },
  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 res = await reportExceptionDetail(datas);

      this.dataList = res.data.data.records.map((item) => {
        return {
          ...item,
          totalTimeStr: timeNumberToText(item.totalTime * 1000) || "--",
        };
      });
      this.total = res.data.data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    cancel() {
      this.modalIsShow = false;
    },
    open() {
      this.modalIsShow = true;
    },
  },
};
</script>
