123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <template>
- <el-dialog
- :visible.sync="visible"
- :show-close="false"
- :maskClosable="false"
- :close-on-click-modal="false"
- @cancel="hideModal"
- :width="350 + 'mm'"
- >
- <div v-loading="spinning" style="min-height: 100px">
- <div id="preview_content" ref="printDom"></div>
- </div>
- <template slot="title">
- <div>
- <el-button
- :loading="waitShowPrinter"
- type="primary"
- icon="printer"
- @click.stop="print"
- >打印</el-button
- >
- </div>
- </template>
- <template slot="footer">
- <el-button key="close" type="info" @click="hideModal"> 关闭 </el-button>
- </template>
- </el-dialog>
- </template>
- <script>
- export default {
- name: "printPreview",
- props: {},
- data() {
- return {
- visible: false,
- spinning: true,
- waitShowPrinter: false,
- // 纸张宽 mm
- width: 0,
- // 模板
- hiprintTemplate: {},
- // 数据
- printData: {},
- };
- },
- computed: {},
- watch: {},
- created() {},
- mounted() {},
- methods: {
- hideModal() {
- this.visible = false;
- this.waitShowPrinter = false;
- // console.log(this.$parent);
- },
- show(hiprintTemplate, printData, width = "210") {
- this.visible = true;
- this.width = width;
- this.hiprintTemplate = hiprintTemplate;
- setTimeout(() => {
- // eslint-disable-next-line no-undef
- $("#preview_content").html(hiprintTemplate.getHtml(printData));
- this.spinning = false;
- }, 500);
- },
- print() {
- this.hiprintTemplate.print();
- setTimeout(() => {
- this.hideModal();
- }, 2000);
- },
- // toPdf() {
- // downloadPDF(this.$refs.printDom);
- // this.hiprintTemplate.toPdf({}, '打印预览');
- // },
- },
- };
- </script>
- <style scoped>
- ::v-deep .el-dialog__body {
- padding: 0;
- }
- ::v-deep tr {
- height: 40px !important;
- }
- ::v-deep .hiprint-printPaper {
- margin: 0 auto;
- }
- /* ::v-deep tr td {
- border: 0 !important;
- } */
- ::v-deep .hiprint-paperNumber {
- display: none;
- }
- .ant-modal-body {
- padding: 0px;
- }
- .ant-modal-content {
- margin-bottom: 24px;
- }
- </style>
|