<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" width="160">
            <template slot-scope="{row, $index}">
              <span>{{row.courseName}}- {{row.nd}}</span>
            </template>
          </el-table-column>

          <el-table-column label="证书类型" align="center" width="80">
            <template slot-scope="{row, $index}">
              <span>施工现场专业人员</span>
            </template>
          </el-table-column>


          <el-table-column label="考试地点" align="center">
            <template slot-scope="{row}">
              <span>{{ row.address }}</span>
            </template>
          </el-table-column>

          <el-table-column label="考试时间" align="center">
            <template slot-scope="{row}">
              <span>{{ row|rangeTime }}</span>
            </template>
          </el-table-column>

          <el-table-column label="考试座位" align="center" width="80">
            <template slot-scope="{row}">
              <span>{{ row.seat }}</span>
            </template>
          </el-table-column>


          <el-table-column label="操作" fixed="right" align="center" width="120">
            <template slot-scope="{row}">
              <el-button  @click="printCert( row )" type="primary" size="small" v-if="canPrint(row)">打印准考证</el-button>
              <el-button v-else type="text" 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";
  import {formatTimeToStr} from "@/utils/date.js";
  export default {
    name: "Index",
    data() {
      return {
        page:1,
        size:10,
        total: 20,
        list: [],
        listLoading: false
      };
    },
    beforeMount() {
      this.getData()
    },
    filters:{
      rangeTime(row){
        let mdate= formatTimeToStr(row.startAt, "yyyy-MM-dd")
        return mdate +"  "+ formatTimeToStr(row.startAt, "hh:mm:ss") + "到"+ formatTimeToStr(row.endAt, "hh:mm:ss")
      }
    },
    methods: {
      getData() {
        this.listLoading = true
        httpServer('Train.GetUserCertList', {}).then( res=>{
            if( res.code == 200){
              this.list = res.data||[]
            }
            this.listLoading = false
        })
      },
      canPrint(row){
        if( !row.certificateUrl ) return false;
        let mytime = formatTimeToStr(+Date.now(), "yyyy-MM-dd")
        let printStartAt= formatTimeToStr(row.printStartAt, "yyyy-MM-dd")
        return  mytime >= printStartAt;
      },
      printCert( row  ){
        window.open(row.certificateUrl, "_brank" )
      },

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

<style>
</style>
