<template>
  <div class="">
    <!-- 考试成绩表 -->
    <div class="common-card a-card-margin-top">
      <div class="information-title">考试成绩</div>
      <a-table
        :columns="testScoreTableColumns"
        :data-source="testScoreTableData"
        :row-key="(record) => record.id"
        :pagination="false"
      >
        <template slot="nickName" slot-scope="text, record">
          <span>{{ record.user ? record.user.nickName : '' }}</span>
        </template>
      </a-table>
      <div class="a-pagination-display">
        <a-pagination
          v-model="testScoreTablePagination.current"
          :pageSize="testScoreTablePagination.pageSize"
          :total.sync="testScoreTablePagination.total"
          show-less-items
          show-quick-jumper
          @change="getTestScoreList"
        />
      </div>
    </div>

    <!-- 未参考人员表 -->
    <div class="common-card a-card-margin-top">
      <div class="information-title">未参考人员</div>
      <a-table
        :columns="unReferencedColumns"
        :data-source="unReferencedTableData"
        :row-key="(record, index) => index"
        :pagination="false"
      >
        <!-- <template slot="nickName" slot-scope="text, record">
          <span>{{ record.user ? record.user.nickName : '' }}</span>
        </template> -->
      </a-table>
      <div class="a-pagination-display">
        <a-pagination
          v-model="unReferencedPagination.current"
          :pageSize="unReferencedPagination.pageSize"
          :total.sync="unReferencedPagination.total"
          show-less-items
          show-quick-jumper
          @change="getUnReferencedListAxios"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { formatePathParams } from '@/filters';
export default {
  props: {
    examId: {
      type: [Number, String],
    },
  },
  components: {},
  data() {
    return {
      tableDataAll: [], // 所有数据

      testScoreTableColumns: [],
      testScoreTablePagination: {
        pageSize: 10,
        current: 1,
        total: 0,
      }, // 分页参数
      testScoreTableData: [], // 列表
      unReferencedColumns: [],
      unReferencedPagination: {
        pageSize: 10,
        current: 1,
        total: 0,
      }, // 分页参数
      unReferencedTableData: [], // 列表
    };
  },
  created() {
    this.initDataFun(); //初始化数据
  },
  mounted() {},
  beforeDestroy() {},
  watch: {},
  computed: {},
  methods: {
    //初始化数据
    initDataFun() {
      if (!this.examId) {
        return;
      }
      // 表单的列的配置参数
      this.testScoreTableColumns = [
        {
          title: '姓名',
          dataIndex: 'nickName',
          key: 'nickName',
          scopedSlots: { customRender: 'nickName' },
        },
        {
          title: '成绩',
          dataIndex: 'totalPoints',
          key: 'totalPoints',
        },
        {
          title: '时间',
          dataIndex: 'endTime',
          key: 'endTime',
        },
      ];
      this.unReferencedColumns = [
        {
          title: '姓名',
          dataIndex: 'nickName',
          key: 'nickName',
          scopedSlots: { customRender: 'nickName' },
        },
      ];
      this.getExamCountInfo(); // 查询：考试的统计信息
      this.getUnReferencedListAxios(); // 查询：未参考人员统计信息
    },

    // 查询：考试的统计信息
    getExamCountInfo() {
      let params = {
        examId: this.examId,
        page: this.testScoreTablePagination.current - 1,
        size: this.testScoreTablePagination.pageSize,
      };
      this.$_http
        .get(
          formatePathParams(this.$_API.INTERFACE_GET_EXAM_DETAIL_MORE, params)
        )
        .then((res) => {
          let resData = res.data;
          if (resData.historyList) {
            this.tableDataAll = resData.historyList;

            this.testScoreTablePagination.current = 1;
            this.testScoreTablePagination.total = this.tableDataAll.length; // 总条数
            this.testScoreTableData = this.getCurrenPageData(
              this.tableDataAll,
              this.testScoreTablePagination.current,
              this.testScoreTablePagination.pageSize
            );
          } else {
            this.tableDataAll = [];
            this.testScoreTableData = [];
            this.testScoreTablePagination.total = 0;
          }
        })
        .catch(() => {});
    },

    // 查询：未参考人员统计信息
    getUnReferencedListAxios() {
      let params = {
        examId: this.examId,
        page: this.unReferencedPagination.current - 1,
        size: this.unReferencedPagination.pageSize,
      };
      this.$_http
        .get(this.$_API.INTERFACE_GET_EXAM_DETAIL_MORE_UNREFERENCED, params)
        .then((res) => {
          let resData = res.data.content;
          this.unReferencedTableData = [...resData];
          this.unReferencedTableData.total = res.data.totalElements; // 总条数
        })
        .catch(() => {});
    },

    // 获取指定页码的数据
    getCurrenPageData(array, current, pageSize) {
      let returnArr = [];
      for (let i = 0; i < array.length; i++) {
        if (i + 1 > (current - 1) * pageSize && i + 1 <= current * pageSize) {
          returnArr.push(array[i]);
        }
      }
      return returnArr;
    },
    getTestScoreList() {
      this.testScoreTableData = this.getCurrenPageData(
        this.tableDataAll,
        this.testScoreTablePagination.current,
        this.testScoreTablePagination.pageSize
      );
    },
    // getUnReferencedList() {
    //   this.unReferencedTableData = this.getCurrenPageData(
    //     this.tableDataAll,
    //     this.testScoreTablePagination.current,
    //     this.testScoreTablePagination.pageSize
    //   );
    // },
  },
};
</script>

<style lang="less"></style>

<style lang="less" scoped>
@import '~@/styles/common/variable.less';
.information-title {
  font-size: 18px;
  font-weight: bold;
  color: @mainColorBlack65;
  margin-bottom: @paddingMarginVal;
}
</style>
