<template>
  <div>

    <el-table
      :data="tableData"
      style="width: 100%"
    >
      <el-table-column
        prop="idcard"
        label="身份证号码"
        min-width="10%">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        min-width="6%">
      </el-table-column>
      <el-table-column
        prop="idcard"
        label="社会保障号码"
        min-width="10%">
      </el-table-column>
      <el-table-column
        prop="nation"
        label="民族"
        min-width="8%">
      </el-table-column>
      <el-table-column
        prop="telphone"
        label="移动电话"
        min-width="8%">
      </el-table-column>
      <el-table-column
        prop="adress"
        label="居住地址"
        min-width="18%">
      </el-table-column>
      <el-table-column
        prop="villageId"
        label="村民小组id"
        min-width="8%">
      </el-table-column>
      <el-table-column
        prop="remark"
        label="备注"
        min-width="20%">
      </el-table-column>
      <el-table-column label="操作"
                       min-width="8%">
        <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: []
      }
    },
    methods: {
      toPdf(s, d) {
        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
          })
          .catch(err => {
            console.log(err);
          });
      },
      current_change(s) {
        var data = {
          "pageNum": s,
          "pageSize": 10
        }
        Loading.service();
        this.$api.getlist.selexxbgdc(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
            this.pageNum = res.data.pageNum
          }

        }).catch((res) => {

        });
      },
      toexcel() {
        axios.get(baseUrl + '/exportExcel/updateBaseInfo', {
          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
          })
          .catch(err => {
            console.log(err);
          });
        //   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.selexxbgdc(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
          this.pageNum = res.data.pageNum
        }

      }).catch((res) => {

      });
    },
  }

</script>

