<template>
  <div class="m-right-block" style="position: relative;">
    <div class="right-block-bd">
      <div class="text-xl leading-10 pb-4 text-blue">
        <p>学时证明</p>
      </div>
      <div  class="ng-scope">

        <el-table v-loading="listLoading" :data="list" border fit highlight-current-row>
          <el-table-column label="培训内容" align="center"  min-width="120">
            <template slot-scope="{row}">
              <span>{{row.name}}</span>
            </template>
          </el-table-column>

          <el-table-column label="学习年度" align="center" >
            <template slot-scope="{row}">
              <span>{{row.nd}}</span>
            </template>
          </el-table-column>



          <el-table-column label="学时" align="center">
            <template slot-scope="{row}">
              <span>{{row.totalXs/10}}</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
          class="m-pages"
            @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>
</style>
