<template>

  <div class="ng-scope">
    <el-table v-loading="listLoading" :data="list" border fit highlight-current-row>
      <el-table-column label="No.">
        <template slot-scope="{row, $index}">
          <span>{{$index+1}}</span>
        </template>
      </el-table-column>

      <el-table-column label="编号">
        <template slot-scope="{row}">
          <span>{{row.examId}}</span>
        </template>
      </el-table-column>

      <el-table-column label="成绩">
        <template slot-scope="{row}">
          <span>{{row.score}}</span>
        </template>
      </el-table-column>

      <el-table-column label="考试时长">
        <template slot-scope="{row}">
          <span>{{row.duration/60}}分钟</span>
        </template>
      </el-table-column>

      <el-table-column label="本次考试用时">
        <template slot-scope="{row}">
          <span>{{row.useTime|formatTime}}</span>
        </template>
      </el-table-column>

      <el-table-column label="考试时间">
        <template slot-scope="{row}">
          <span>{{row.startTime|toDatetime}}</span>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @current-change="handleCurrentChange" :current-page="page" :page-size="size" layout="total, prev,pager, next"
      :total="total">
    </el-pagination>
  </div>

</template>

<script>
  import {httpServer} from "@/components/httpServer/httpServer.js";
  import {toDatetime} from "@/utils/date.js"
  export default {
    name: "Index",
    data() {
      return {
        page: 1,
        size: 12,
        total: 1,
        list: [],
        listLoading: false
      };
    },
    props:{
      courseId: {
        type: Number,
        default:0
      }
    },
    filters:{
      toDatetime,
      formatTime(val){
        if( val < 60 ){
          return val +"秒"
        }else{
          return parseInt( val/60 ) +"分"+ (val%60)+'秒'
        }
      }
    },
    beforeMount() {
      this.getData()
    },
    methods: {
      getData() {
        let param = {
          from: (this.page - 1) * this.size,
          size: this.size,
          courseId: this.courseId
        }
        httpServer('course.CourseExamList', param).then( res => {
          if( res.code == 200){
            this.list = res.data.list || 0;
            this.total = res.data.total || 0;
          }
        })
      },
      handleCurrentChange: function(page) {
        this.page = page
        this.getData()
      }
    }
  }
</script>

<style>
</style>
