<template>
  <div class="main-content illegal-print">
    <div class="content-header">
      <span class="title">拟列入严重违法失信企业名单决定书</span>
      <div class="back-btn">
        <el-button type="primary" size="mini" @click="$router.back()">返回</el-button>
        <el-button type="primary" size="mini" @click="printCurrent">打印当前页</el-button>
        <el-button type="primary" size="mini" @click="printAll">全部打印</el-button>
      </div>
    </div>
    <div id="content-body" class="content-body">
      <div class="preview-box">
        <paper-swiper ref="swiper">
          <paper v-for="({tsBizSerIllegal,tsWrit},index) in paperInfo" :key="index" style="width:700px;line-height: 30px;margin: 0 auto;">
            <div style="height: 1000px">
              <div style="font-size:25px;text-align:center">
                <span>关于{{tsBizSerIllegal.entname}}列入企业经营异常名录满三年提示公告</span>
              </div>
              <!--副标题，决定书号-->
              <div style="text-align:center;font-size:16px;transform: scale(0.8)">
                <h2 style="font-weight:normal">{{ tsWrit.writsno }}</h2>
              </div>
              <br>
              <br>
              <!--主内容-->
              <div style="font-size:16px">
                <span style="text-decoration:underline">&nbsp;{{ tsBizSerIllegal.entname }}&nbsp;</span><br>
                (统一信用代码/身份证件号码：<span style="text-decoration:underline">&nbsp;{{ tsBizSerIllegal.uniscid || tsBizSerIllegal.regno }}&nbsp;</span>）：<br>
                <br>
                <div
                  style="text-indent: 2em;"
                  v-html="tsWrit.content"
                />
                <br>
                <br>
                <span style="float:right">{{ decorgCn }}&nbsp;</span>
                <br>
                <span style="float:right">{{ $moment(tsWrit.createtime).format('YYYY') }}&nbsp;年&nbsp;{{ $moment(tsWrit.createtime).format('M') }}&nbsp;月&nbsp;{{ $moment(tsWrit.createtime).format('D') }}&nbsp;日</span>
                <br>
                <br>
                <br>
                <!-- <span style="text-align:center;margin-left:auto;margin-right:auto;"> <font style="text-align:center" contenteditable="true">
                  注：本文书适用于因具有《严重违法失信企业名单管理暂行办法》第五条第一款第（一）项规定的情形，被列入严重违法失信企业名单的企业。
                </font> </span> -->
              </div>
            </div>
            <!--标题-->
          </paper>
        </paper-swiper>
      </div>
    </div>
  </div>
</template>

<script>
import { getIllegalInclusionWritByBizSeqId } from '@/api/illegal'
export default {
  data() {
    return {
      bizseq: '',
      paperInfo: [],
      decorgCn: ''
    }
  },
  mounted() {
    this.bizseq = this.$route.query.bizseq
    // 获取文书信息
    getIllegalInclusionWritByBizSeqId(this.bizseq).then(res => {
      if (res.code === 0) {
        this.paperInfo = res.data.paperInfo
        this.decorgCn = res.data.decorgCn
        this.paperInfo.forEach(each => {
          console.log(each.tsWrit.content.lastIndexOf('\n'))
          console.log(each.tsWrit.content.substr(each.tsWrit.content.lastIndexOf('\n'), each.tsWrit.content.length))
          each.tsWrit.content = each.tsWrit.content.substr(each.tsWrit.content.lastIndexOf('\n'), each.tsWrit.content.length)
        })
      }
    })
  },
  methods: {
    printCurrent() {
      const swiper = this.$refs.swiper
      const page = swiper.getPaperElement()
      const printHtml = page.outerHTML// 获取到要打印的节点内容
      // 打开新窗口
      const newWindow = window.open('打印', '_blank')
      newWindow.document.write(printHtml)
      // 关闭文档
      newWindow.document.close()
      // 调用打印机
      newWindow.print()
      newWindow.close()
    },
    printAll() {
      let html = ''
      const swiper = this.$refs.swiper
      for (let i = 0; i < this.paperInfo.length; i++) {
        const page = swiper.getPaperElement(i)
        const printHtml = page.outerHTML
        html += printHtml
      }
      const style = '<style type="text/css">body>div:not(:first-child){margin-top:600px}</style>'
      html += style

      // 打开新窗口
      const newWindow = window.open('打印', '_blank')
      newWindow.document.write(html)
      // // 关闭文档
      newWindow.document.close()
      // 调用打印机
      newWindow.print()
      newWindow.close()
    }
  }
}
</script>
<style lang='scss' scoped>
.main-content{
  padding: 10pt;
    .back-btn{
    display: inline-block;
    position: absolute;
    right: 40pt;
  }
  .content-header,.content-body{
    background: white;
    padding:20PX 10PX;
    border:1PX solid #eee;
  }
  .content-header{
    height:60PX;
    .title{
      font-weight: 700;
      font-size: $font-size-sub-title;
    }
  }
  .content-body{
    padding:20pt;
      .tab{
        .tab-title{
          label{
            background: $color-primary;
            display:inline-block;
            color:$color-title-color;
            padding:5px;
          }
        }
      }
    .form{
      margin-bottom: 20pt;
    }
  }
}
</style>
