<template>
  <div class="m-right-block fr mh576" style="position: relative;">
    <div class="right-block-bd">
      <div class="mb10 tc mt20">
        <span class="p-ico2 worm-ico-o"></span>
        注：<span class="txt-o"></span>考试前三天才会生成,若未看到，请联系管理员
      </div>

      <div  class="ng-scope">
        <el-table v-loading="listLoading" :data="list" border fit highlight-current-row>
          <el-table-column label="考试科目" align="center" >
            <template slot-scope="{row, $index}">
              <span>{{row.courseName}}- {{row.nd}}</span>
            </template>
          </el-table-column>

          <el-table-column label="证书类型" align="center">
            <template slot-scope="{row, $index}">
              <span>{{row.type}}</span>
            </template>
          </el-table-column>


          <el-table-column label="获得学时" align="center">
            <template slot-scope="{row, $index}">
              <span>{{row.getXs/10}}</span>
            </template>
          </el-table-column>

          <el-table-column label="总学时" align="center">
            <template slot-scope="{row, $index}">
              <span>{{row.totalXs/10}}</span>
            </template>
          </el-table-column>


          <el-table-column label="分数" align="center">
            <template slot-scope="{row}">
              <span>{{ row.score }}</span>
            </template>
          </el-table-column>


          <el-table-column label="操作" fixed="right" align="center" width="200">
            <template slot-scope="{row}">
              <el-button  @click="printCert( row )" type="warning" size="small">下载准考证</el-button>
            </template>
          </el-table-column>
        </el-table>

        <el-pagination
            @current-change="handleCurrentChange"
            :current-page="page"
           :page-size="size"
           layout="total, prev,pager, next"
           :total="list.length">
        </el-pagination>

      </div>
    </div>
  </div>
</template>

<script>
  import {httpServer} from "@/components/httpServer/httpServer.js";
  export default {
    name: "Index",
    data() {
      return {
        page:1,
        size:10,
        total: 20,
        list: [],
        listLoading: false
      };
    },
    beforeMount() {
      this.getData()
    },
    methods: {
      getData() {
        this.listLoading = true
        httpServer('Course.GetCertificateList', {}).then( res=>{
            if( res.code == 200){
              this.list = res.data||[]
            }
            this.listLoading = false
        })
      },
      printCert( row  ){
        let mytime = Date.now()
        let printDate = +new Date( row.certificateAt)
        console.log(mytime, printDate )
        if( printDate > mytime){
          this.$message.errorMsg("考试前三天来打印")
          return;
        }
        // if( row.score < 60){
        //   this.$message.errorMsg("考试分数不达标")
        //   return;
        // }
        if( row.getXs < row.totalXs){
          this.$message.errorMsg("还未培训完成")
          return;
        }
        window.open(row.certificateUrl, "_brank" )
      },

      handleCurrentChange: function(page) {
        this.page = page
        this.getData()
      }
    }
  }
</script>

<style>
</style>
