preview.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 :loading="waitShowPrinter" type="primary" icon="printer" @click.stop="print">打印</el-button>
  16. </div>
  17. </template>
  18. <template slot="footer">
  19. <el-button key="close" type="info" @click="hideModal"> 关闭 </el-button>
  20. </template>
  21. </el-dialog>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'PrintPreview',
  26. props: {
  27. addPrint: {
  28. type: Function,
  29. default: null
  30. },
  31. },
  32. data() {
  33. return {
  34. visible: false,
  35. spinning: true,
  36. waitShowPrinter: false,
  37. // 纸张宽 mm
  38. width: 0,
  39. // 模板
  40. hiprintTemplate: {},
  41. // 数据
  42. printData: {}
  43. }
  44. },
  45. computed: {},
  46. watch: {},
  47. created() {},
  48. mounted() {},
  49. methods: {
  50. hideModal() {
  51. this.visible = false
  52. this.waitShowPrinter = false
  53. // console.log(this.$parent);
  54. },
  55. show(hiprintTemplate, printData, width = '210') {
  56. this.visible = true
  57. this.width = width
  58. this.hiprintTemplate = hiprintTemplate
  59. setTimeout(() => {
  60. // eslint-disable-next-line no-undef
  61. $('#preview_content').html(hiprintTemplate.getHtml(printData))
  62. this.spinning = false
  63. }, 500)
  64. },
  65. print() {
  66. this.hiprintTemplate.print()
  67. setTimeout(() => {
  68. this.hideModal()
  69. this.$emit('refreshList')
  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>