preview.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. },
  54. show(hiprintTemplate, printData, width = '210') {
  55. this.visible = true
  56. this.width = width
  57. this.hiprintTemplate = hiprintTemplate
  58. setTimeout(() => {
  59. $('#preview_content').html(hiprintTemplate.getHtml(printData))
  60. this.spinning = false
  61. }, 500)
  62. },
  63. print() {
  64. this.hiprintTemplate.print()
  65. setTimeout(() => {
  66. this.hideModal()
  67. this.$emit('refreshList')
  68. }, 2000)
  69. }
  70. }
  71. }
  72. </script>
  73. <style scoped>
  74. ::v-deep .el-dialog__body {
  75. padding: 0;
  76. }
  77. ::v-deep tr {
  78. height: 40px !important;
  79. }
  80. ::v-deep .hiprint-printPaper {
  81. margin: 0 auto;
  82. }
  83. ::v-deep .hiprint-paperNumber {
  84. display: none;
  85. }
  86. .ant-modal-body {
  87. padding: 0px;
  88. }
  89. .ant-modal-content {
  90. margin-bottom: 24px;
  91. }
  92. </style>