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

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

          <el-table-column label="证书编号"  align="center" width="160">
            <template slot-scope="{row}">
              <span>{{row.rzCode||'---'}}</span>
            </template>
          </el-table-column>

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


          <el-table-column label="费用(元)" align="center" width="80">
            <template slot-scope="{row}">
              <span>￥{{ row.fee/100 }}</span>
            </template>
          </el-table-column>

          <el-table-column label="学习时间" align="center" min-width="120">
            <template slot-scope="{row}">
              <span>{{ row.startDate }} 到 {{ row.endDate }}</span>
            </template>
          </el-table-column>


          <el-table-column label="操作" fixed="right" align="center" min-width="80">
            <template slot-scope="{row}">
              <el-button v-if="row.signUrl" @click="showSign(row.signUrl )" type="primary" size="small">打印证书</el-button>
              <el-button v-else  @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="total">
        </el-pagination>

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

<script>
  import {
    httpServer
  } from "@/components/httpServer/httpServer.js";
  export default {
    name: "Index",
    data() {
      return {
        page: 1,
        size: 12,
        total: 1,
        list: [],
        listLoading: false
      };
    },
    beforeMount() {
      this.getData()
    },
    methods: {
      getData() {
        let param = {from: (this.page - 1) * this.size,size:this.size}
        httpServer('Cert.getCertList', param).then(({
          data,
          code
        }) => {
          if( code != 200 ) return;
          this.list = data.list.map(v => {
            this.$set(v, 'edit', false)
            return v
          });
          this.total = data.total || 0;
        })
      },
      initEdit( row ) {
        row.temp = Object.assign({}, row);
        row.edit = true;
      },
      cancelEdit(row) {
       row = Object.assign(row, row.temp);
       row.edit = false;
      },
      printCert( row  ){
        httpServer('Cert.printCert', {id:row.id}).then( res => {
          if( res.code != 200 ) return;
          row.signUrl = res.data.url
          this.showSign( row.signUrl )
          this.$message.success("录入成功")
        })
      },
      showSign( url ){
        window.open( url )
      },
      confirmEdit(row) {
       let {rzCode, id} = row
       httpServer('Cert.addRzCode', {rzCode, id}).then( res => {
         if( res.code != 200 ) return;
         this.showSign( res.data.url );
       })
      },
      handleCurrentChange: function(page) {
        this.page = page
        this.getData()
      }
    }
  }
</script>

<style>
  @import './index.css'
</style>
