<template>
  <div class="report-statistics">
    <el-table ref="TableList" :data="dataList">
      <el-table-column type="index" label="排序"></el-table-column>
      <el-table-column prop="examName" label="批次名称（ID）"></el-table-column>
      <el-table-column prop="examActivityId" label="场次ID"></el-table-column>
      <el-table-column prop="roomName" label="考场名称（代码）">
        <span slot-scope="scope"
          >{{ scope.row.roomName }}({{ scope.row.roomCode }})</span
        >
      </el-table-column>
      <el-table-column prop="examTotal" label="应考（科次）">
        <template slot-scope="scope">
          <span class="color-primary">{{ scope.row.examTotal }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="actualExamTotal" label="实考（科次）">
        <template slot-scope="scope">
          <span class="color-success">{{ scope.row.actualExamTotal }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="deficiencyExamTotal" label="缺考（科次）">
        <template slot-scope="scope">
          <span class="color-danger">{{ scope.row.deficiencyExamTotal }}</span>
        </template>
      </el-table-column>
    </el-table>
    <div class="part-page">
      <div class="page-info stat-page-info">
        共计<span>应考{{ examTotal }}</span
        >科次，<span>实考{{ actualExamTotal }}分</span>科次，<span
          >缺考{{ deficiencyExamTotal }}</span
        >科次
      </div>
      <el-pagination
        background
        layout="prev, pager, next,total,sizes,jumper"
        :current-page="current"
        :total="total"
        :page-size="size"
        @size-change="toPage(1)"
        @current-change="toPage"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { reportOverviewData, reportStatisticsData } from "@/api/invigilation";

export default {
  name: "report-statistics",
  props: {
    filter: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {
      current: 1,
      total: 0,
      size: 10,
      examTotal: 0,
      actualExamTotal: 0,
      deficiencyExamTotal: 0,
      dataList: [],
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    async getList() {
      const datas = {
        ...this.filter,
        pageNumber: this.current,
        pageSize: this.size,
      };

      const res = await reportStatisticsData(datas);

      this.dataList = res.data.data.records;
      this.total = res.data.data.total;
    },
    toPage(page) {
      this.current = page;
      this.getList();
    },
    async getTotalCount() {
      const datas = {
        ...this.filter,
      };

      const res = await reportOverviewData(datas);
      const resData = res.data.data;
      this.examTotal = resData.examTotal;
      this.actualExamTotal = resData.actualExamTotal;
      this.deficiencyExamTotal = resData.deficiencyExamTotal;
    },
    getData() {
      this.toPage(1);
      this.getTotalCount();
    },
  },
};
</script>

<style lang="scss" scoped>
.stat-page-info {
  color: #626a82;

  span {
    color: #202b4b;
    margin: 0 5px;
    font-weight: 600;
  }
}
</style>
