<template>
  <div>
    <Button class="oa-search-header-form-b2 ivu-btn" type="primary" @click="printTable()">打印</Button>
    <div  id="print-table" style="display: none;width: 100%;text-align: center">
      <p style=" margin: 20px 0; font-size: 20px; width: 1050px;" v-show="printTitle">{{printTitle}}</p>
      <Table stripe border :columns="printTableTitle" :data="printTableData" id="print-table-t">
      </Table>
    </div>
  </div>
</template>
<script>
export default {
  props: ['printTableTitle', 'printTableData', 'printTitle'],
  data () {
    return {
    }
  },
  methods: {
    printTable () {
      $('#print-table-t table').attr({width: '1050px', border: '1px'});
      let obj = document.getElementById('print-table');
      let newIframe = document.createElement('IFRAME');
      let doc = null;
      newIframe.setAttribute('style', 'width:0px;height:0px;position:absolute;left:-2000px;top:-2000px;');
      newIframe.setAttribute('align', 'center');
      document.body.appendChild(newIframe);
      doc = newIframe.contentWindow.document;
      doc.write('<div style="width:100%;height:auto;margin:0 auto;"align="center">' + obj.innerHTML + '</div>');
      doc.close();
      newIframe.contentWindow.focus();
      newIframe.contentWindow.print();
    }
  }
}
</script>
<style>
/*#print-table-t tr {*/
  /*border: 1px solid #ccc;*/
/*}*/
</style>
