<template>
    <div>

  <el-table
    v-loading.fullscreen.lock="loading"
    :data="tableData"
    style="width: 100%"
    >
    <el-table-column
      prop="documentsType"
      label="证件类型"
      width="180">
    </el-table-column>
    <el-table-column
      prop="documentsNumber"
      label="证件号码"
      width="180">
    </el-table-column>
    <el-table-column
      prop="idcard"
      label="身份证号码">
    </el-table-column>
     <el-table-column
      prop="nation"
      label="民族">
    </el-table-column>
     <el-table-column
      prop="name"
      label="姓名">
    </el-table-column>
     <el-table-column
      prop="grade"
      label="缴费档次">
    </el-table-column>
    <el-table-column
      prop="registerType"
      label="户口性质">
    </el-table-column>
    <el-table-column
      prop="villageId"
      label="村社区id">
    </el-table-column>
    <el-table-column
      prop="adress"
      label="户籍所在地">
    </el-table-column>
     <el-table-column
      prop="bank"
      label="银行id">
    </el-table-column>
     <el-table-column
      prop="bankAccount"
      label="银行账号">
    </el-table-column>
     <el-table-column
      prop="remark"
      label="备注">
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          type="primary"
          @click="toPdf(scope.$index, scope.row)">导出pdf</el-button>

      </template>
    </el-table-column>
  </el-table>
  <el-pagination
  	class="pone"
      :page-size='10'
      layout="total, prev, pager, next, jumper"
      :total="totals"
      :current-page.sync="Page"
      @current-change="current_change"
>

    </el-pagination>
    <el-button type="success" @click="toexcel" style="margin:50px">全部导出</el-button>
  </div>
</template>
<script>
import { Loading } from 'element-ui';
import {baseUrl} from "../../utils/global"
import axios from "axios"
import Cookies from "js-cookie";
export default {
    data(){
        return {
            Page:1,
            totals:0,
             tableData: [],
          loading: false
        }
    },
    methods:{
      toPdf(s,d){
        this.loading = true;
        console.log(d)
          axios.get(baseUrl+'/exportPdf/insuredRegistration?id='+d.eventId,{
  headers: {
    "token":Cookies.get("token")
  },
  responseType:'blob'      //告诉服务器我们需要的响应格式
})
.then(res => {
  let a = document.createElement("a");
  let blob = new Blob([res.data],{
    type:'application/vnd.ms-excel'      //将会被放入到blob中的数组内容的MIME类型
  });
  a.href = URL.createObjectURL(blob);  //生成一个url
  a.download = "西充县城乡居民社会养老保险参保登记表.pdf";
  a.click();
  this.loading = false;
  // let objectUrl = URL.createObjectURL(blob);  //生成一个url
  // window.location.href = objectUrl;   //浏览器打开这个url
})
.catch(err => {
  console.log(err);
  this.loading = false;
});
      },
        current_change(s){
            var data={
            "page": s,
            "pageSize": 10
        }
        Loading.service();
         this.$api.getlist.seledjdc(data).then((res) => {
            let loadingInstance = Loading.service();
              this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
              loadingInstance.close();
            });
           if(res.code==200){
                this.tableData=res.data.result
                this.totals=res.data.total
                }

        }).catch((res) => {

        });
        },
        toexcel(){
        this.loading = true;
         axios.get(baseUrl+'/exportExcel/insuredRegistration',{
  headers: {
    "token":Cookies.get("token")
  },
  responseType:'blob'      //告诉服务器我们需要的响应格式
})
.then(res => {
  let a = document.createElement("a");
  let blob = new Blob([res.data],{
    type:'application/vnd.ms-excel'      //将会被放入到blob中的数组内容的MIME类型
  });
  a.href = URL.createObjectURL(blob);  //生成一个url
  a.download = "居民养老保险表.xlsx";
  a.click();
  this.loading = false;
  // let objectUrl = URL.createObjectURL(blob);  //生成一个url
  // window.location.href = objectUrl;   //浏览器打开这个url
})
.catch(err => {
  console.log(err);
  this.loading = false;
});
        //   this.$api.getlist.dccc().then((res) => {
        //     let loadingInstance = Loading.service();
        //       this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
        //       loadingInstance.close();
        //     });
        //    if(res.code==200){
        //         this.tableData=res.data.result
        //         this.totals=res.data.total
        //         }

        // }).catch((res) => {

        // });
        }
    },
    created(){
        var data={
            "page": 1,
            "pageSize": 10
        }
        Loading.service();
         this.$api.getlist.seledjdc(data).then((res) => {
            let loadingInstance = Loading.service();
              this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
              loadingInstance.close();
            });
           if(res.code==200){
                this.tableData=res.data.result
                this.totals=res.data.total
                }

        }).catch((res) => {

        });
      },
    }

</script>

