<template>
  <div class="preview-box">
    <div class="head">
      <div class="title">打印预览</div>
      <div class="btn"><a-button type="primary"  @click.stop="print">打印</a-button></div>
    </div>
    <div id="preview_content_design"></div>
  </div>
  
</template>

<script>
import { hiprint } from "./../index";

let hiprintTemplate;

export default {
  name: "printDesign",
  props: {
    printApiData: {
      type: Object|Array,
      default: {},
    },
    defaultList: {
      type: Array,
      default: [],
    },
    panel: {
      type: Object,
      default: {},
    },
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      hiprintTemplate = new hiprint.PrintTemplate({
        template: this.panel,
      });
      this.show(hiprintTemplate);
    },
    show(hiprintTemplate) {
      setTimeout(() => {
        $('#preview_content_design').html(hiprintTemplate.getHtml(this.printApiData))
      }, 500)
    },
    print() {
      hiprintTemplate.print(this.printApiData);
    },
  },
};
</script>

<style lang="less" scoped>
/deep/ .hiprint-printPaper{
  margin: 0 auto;
}
.head{
  display: flex;
  justify-content: space-between;
  padding: 0 20px;
  align-items: center;
  border-bottom: 1px solid #eaeaea;
}
.head .title{
  font-size: 18px;
  font-weight: 500;
}
</style>
