<template>
  <div>

    <el-table
      v-loading.fullscreen.lock="loading"
      :data="tableData"
      style="width: 100%"
    >
      <el-table-column
        prop="idcard"
        label="身份证号码"
        min-width="20%">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        min-width="20%">
      </el-table-column>
      <el-table-column
        prop="bankAccount"
        label="银行账号"
        min-width="20%">
      </el-table-column>
      <el-table-column
        prop="bank"
        label="所属银行"
        min-width="20%">
      </el-table-column>
      <el-table-column label="操作"
        min-width="20%">
        <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="PageNum"
      @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 {
        PageNum: 1,
        totals: 0,
        tableData: [],
        loading: false
      }
    },
    methods: {
      toPdf(s, d) {
        this.loading = true;
        console.log(d)
        axios.get(baseUrl + '/exportPdf/informationChange?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();
            // let objectUrl = URL.createObjectURL(blob);  //生成一个url
            // window.location.href = objectUrl;   //浏览器打开这个url
            this.loading = false;
          })
          .catch(err => {
            console.log(err);
            this.loading = false;
          });
      },
      current_change(s) {
        var data = {
          "pageNum": s,
          "pageSize": 10
        }
        Loading.service();
        this.$api.getlist.seleyhkbgdc(data).then((res) => {
          let loadingInstance = Loading.service();
          this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
            loadingInstance.close();
          });
          if (res.code == 200) {
            this.tableData = res.data.content
            this.totals = res.data.totalSize
          }

        }).catch((res) => {

        });
      },
      toexcel() {
        this.loading = true;
        axios.get(baseUrl + '/exportExcel/updateBankCard', {
          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 = "银行卡变更表" + Date.now() + ".xlsx";
            a.click();
            // let objectUrl = URL.createObjectURL(blob);  //生成一个url
            // window.location.href = objectUrl;   //浏览器打开这个url
            this.loading = false;
          })
          .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 = {
        "pageNum": 1,
        "pageSize": 10
      }
      Loading.service();
      this.$api.getlist.seleyhkbgdc(data).then((res) => {
        let loadingInstance = Loading.service();
        this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
          loadingInstance.close();
        });
        if (res.code == 200) {
          this.tableData = res.data.content
          this.totals = res.data.totalSize
        }

      }).catch((res) => {

      });
    },
  }

</script>

