preview.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <el-dialog
  3. :visible.sync="visible"
  4. :show-close="false"
  5. :maskClosable="false"
  6. :close-on-click-modal="false"
  7. @cancel="hideModal"
  8. :width="350 + 'mm'"
  9. >
  10. <div v-loading="spinning" style="min-height: 100px">
  11. <div id="preview_content" ref="printDom"></div>
  12. </div>
  13. <template slot="title">
  14. <div>
  15. <el-button
  16. :loading="waitShowPrinter"
  17. type="primary"
  18. icon="printer"
  19. @click.stop="print"
  20. >打印</el-button
  21. >
  22. </div>
  23. </template>
  24. <template slot="footer">
  25. <el-button key="close" type="info" @click="hideModal"> 关闭 </el-button>
  26. </template>
  27. </el-dialog>
  28. </template>
  29. <script>
  30. export default {
  31. name: "printPreview",
  32. props: {},
  33. data() {
  34. return {
  35. visible: false,
  36. spinning: true,
  37. waitShowPrinter: false,
  38. // 纸张宽 mm
  39. width: 0,
  40. // 模板
  41. hiprintTemplate: {},
  42. // 数据
  43. printData: {},
  44. };
  45. },
  46. computed: {},
  47. watch: {},
  48. created() {},
  49. mounted() {},
  50. methods: {
  51. hideModal() {
  52. this.visible = false;
  53. this.waitShowPrinter = false;
  54. // console.log(this.$parent);
  55. },
  56. show(hiprintTemplate, printData, width = "210") {
  57. this.visible = true;
  58. this.width = width;
  59. this.hiprintTemplate = hiprintTemplate;
  60. setTimeout(() => {
  61. // eslint-disable-next-line no-undef
  62. $("#preview_content").html(hiprintTemplate.getHtml(printData));
  63. this.spinning = false;
  64. }, 500);
  65. },
  66. print() {
  67. this.hiprintTemplate.print();
  68. setTimeout(() => {
  69. this.hideModal();
  70. }, 2000);
  71. },
  72. // toPdf() {
  73. // downloadPDF(this.$refs.printDom);
  74. // this.hiprintTemplate.toPdf({}, '打印预览');
  75. // },
  76. },
  77. };
  78. </script>
  79. <style scoped>
  80. ::v-deep .el-dialog__body {
  81. padding: 0;
  82. }
  83. ::v-deep tr {
  84. height: 40px !important;
  85. }
  86. ::v-deep .hiprint-printPaper {
  87. margin: 0 auto;
  88. }
  89. /* ::v-deep tr td {
  90. border: 0 !important;
  91. } */
  92. ::v-deep .hiprint-paperNumber {
  93. display: none;
  94. }
  95. .ant-modal-body {
  96. padding: 0px;
  97. }
  98. .ant-modal-content {
  99. margin-bottom: 24px;
  100. }
  101. </style>