<template>
  <div class="block" v-loading="loading">
    <TableLayout height="300"  :column="column" :data="table_data" :pageInfo="pageInfo"
        @current-change="(e) => pagingChange({ currentPage: e })" @size-change="(e) => pagingChange({ pageSize: e })">
        <template v-slot:action="props">
          <el-button type="text" icon="i-j-ksap-fuzhi" @click="lookPaper(props.row)" >查看</el-button>
        </template>
      </TableLayout>
  </div>
</template>

<script>
import { TableLayout } from '@/components/layout/index'

import { findStatisticDataApi } from '@/api/statistic'
export default {
  components: { TableLayout },
  props: {
    user: {}
  },
  watch: {
    user: {
      deep: true,
      immediate: true,
      handler (nv) {
        if (nv) {
          this.pageInfo = { currentPage: 1, pageSize: 5, total: 0, layout: 'total, prev, pager, next, jumper' }
          this.findData(nv.id)
        }
      }
    }
  },
  data: _ => ({
    loading: false,
    column: [
      // { label: '序号', type: 'index' },
      { prop: 'historyId', label: '序号', align: 'center', 'show-overflow-tooltip': true },
      { prop: 'examTitle', label: '考试名称', align: 'center', 'show-overflow-tooltip': true },
      { prop: 'totalScore', label: '总分', align: 'center', 'show-overflow-tooltip': true },
      { prop: 'passScore', label: '及格分', align: 'center', 'show-overflow-tooltip': true },
      { prop: 'userScore', label: '学员分数', align: 'center', 'show-overflow-tooltip': true },
      { prop: 'isPass', label: '通过考试状态', align: 'center', 'show-overflow-tooltip': true },
      { prop: 'scoreOrder', label: '考试排名', align: 'center', 'show-overflow-tooltip': true },
      {
        prop: 'action',
        label: '操作',
        //  width: 350,
        width: 100,
        align: 'center',
        'show-overflow-tooltip': true
      }
    ],
    table_data: [],
    pageInfo: { currentPage: 1, pageSize: 5, total: 0, layout: 'total, prev, pager, next, jumper' }
  }),
  // mounted () {
  //   this.findData(this.user?.id)
  // },
  methods: {
    lookPaper (row) {
      this.$router.push({ path: '/assessment-evaluation/human-evaluation/begin-eval/' + row.historyId, query: { preview: 1 } })
    },
    // 挂载页面时调用的函数。
    async findData (userId) {
      this.loading = true
      const data = await findStatisticDataApi('exam-details-student-score-table', { ...this.pageInfo, userId })
      this.table_data = data.data
      this.pageInfo.total = data.total
      this.pageInfo.currentPage = data.currentPage
      this.pageInfo.pageSize = data.pageSize
      this.loading = false
    },
    // 更改页面时调用的函数。
    pagingChange (event) {
      if ((typeof event.currentPage !== 'number') && (typeof event.pageSize !== 'number')) return

      this.pageInfo = { ...this.pageInfo, ...event }
      this.findData(this.user?.id)
    }
  }
}
</script>

<style>

</style>
