preview.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <el-dialog
  3. class="sub-main"
  4. :visible.sync="visible"
  5. :show-close="false"
  6. :mask-closable="false"
  7. :close-on-click-modal="false"
  8. :width="350 + 'mm'"
  9. @cancel="hideModal"
  10. >
  11. <div v-loading="spinning" style="min-height: 100px">
  12. <div id="preview_content" ref="printDom" />
  13. </div>
  14. <template slot="title">
  15. <div>
  16. <!-- <div style="margin-right: 20px">打印预览</div> -->
  17. <el-button :loading="waitShowPrinter" type="primary" icon="printer" @click.stop="print">打印</el-button>
  18. <!-- <el-button type="primary" icon="printer" @click.stop="toPdf">pdf</el-button> -->
  19. </div>
  20. </template>
  21. <template slot="footer">
  22. <el-button key="close" type="info" @click="hideModal"> 关闭</el-button>
  23. </template>
  24. </el-dialog>
  25. </template>
  26. <script>
  27. // import { downloadPDF } from '@/utils/pdf'
  28. import { addPrint } from './print-data'
  29. import { detailArr } from './print-data'
  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. loading: true
  45. }
  46. },
  47. computed: {},
  48. watch: {},
  49. created() {
  50. },
  51. mounted() {
  52. },
  53. methods: {
  54. // handleExport() {
  55. // downloadPDF(this.$refs.printDom);
  56. // },
  57. hideModal() {
  58. this.visible = false
  59. this.waitShowPrinter = false
  60. this.$parent.initPrint()
  61. // console.log(this.$parent);
  62. },
  63. show(hiprintTemplate, printData, width = '210') {
  64. this.visible = true
  65. this.width = width
  66. this.hiprintTemplate = hiprintTemplate
  67. this.printData = printData
  68. setTimeout(() => {
  69. // eslint-disable-next-line no-undef
  70. $('#preview_content').html(hiprintTemplate.getHtml(printData))
  71. this.spinning = false
  72. }, 500)
  73. },
  74. print() {
  75. try {
  76. if (typeof this.$parent.addPrint === 'function') {
  77. this.$parent.addPrint('addPrints').then(() => {
  78. this.hiprintTemplate.print(
  79. this.printData,
  80. {},
  81. {
  82. callback: async() => {
  83. this.hiprintTemplate = {}
  84. this.$parent.tableSelection = []
  85. // setTimeout(() => {
  86. // console.error('更新发货汇总列表')
  87. // // this.$successMsg('更新成功')
  88. // }, 1000)
  89. setTimeout(() => {
  90. console.error('更新发货汇总列表')
  91. this.$parent.getList()
  92. }, 1000)
  93. }
  94. }
  95. )
  96. })
  97. } else {
  98. throw new Error('加载失败,刷新重试')
  99. }
  100. } catch (e) {
  101. this.$errorMsg(e)
  102. // '调用打印次数接口失败'
  103. }
  104. setTimeout(() => {
  105. this.hideModal()
  106. }, 2000)
  107. }
  108. // toPdf() {
  109. // downloadPDF(this.$refs.printDom);
  110. // this.hiprintTemplate.toPdf({}, '打印预览');
  111. // },
  112. }
  113. }
  114. </script>
  115. <style scoped>
  116. ::v-deep .el-dialog__body {
  117. padding: 0;
  118. }
  119. ::v-deep tr {
  120. height: 40px !important;
  121. }
  122. ::v-deep td {
  123. height: 40px !important;
  124. overflow: hidden;
  125. /* display: -webkit-box; */
  126. -webkit-line-clamp: 2;
  127. /* 数值代表显示几行 */
  128. -webkit-box-orient: vertical;
  129. }
  130. ::v-deep .hiprint-printPaper {
  131. margin: 0 auto;
  132. }
  133. /* ::v-deep tr td {
  134. border: 0 !important;
  135. } */
  136. ::v-deep .hiprint-paperNumber {
  137. display: none;
  138. }
  139. .ant-modal-body {
  140. padding: 0px;
  141. }
  142. .ant-modal-content {
  143. margin-bottom: 24px;
  144. }
  145. @media print {
  146. /*
  147. td {
  148. border: none !important;
  149. } */
  150. .drag_item_box {
  151. height: 100%;
  152. padding: 6px;
  153. }
  154. .drag_item_box > div {
  155. height: 100%;
  156. width: 100%;
  157. background-color: #fff;
  158. display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. }
  162. .drag_item_box > div > a {
  163. text-align: center;
  164. text-decoration-line: none;
  165. }
  166. .drag_item_box > div > a > span {
  167. font-size: 28px;
  168. }
  169. .drag_item_box > div > a > p {
  170. margin: 0;
  171. }
  172. .drag_item_title {
  173. font-size: 16px;
  174. padding: 12px 6px 0 6px;
  175. font-weight: bold;
  176. }
  177. .card-design {
  178. overflow: hidden;
  179. overflow-x: auto;
  180. overflow-y: auto;
  181. }
  182. ::v-deep .el-dialog__body {
  183. padding: 0;
  184. }
  185. ::v-deep table {
  186. height: 240px !important;
  187. }
  188. ::v-deep tr {
  189. height: 40px !important;
  190. }
  191. ::v-deep .hiprint-printPaper {
  192. margin: 0 auto;
  193. }
  194. ::v-deep tr td {
  195. border: 0 !important;
  196. /* width: 911px !important;
  197. height: 529px !important; */
  198. }
  199. .ant-modal-body {
  200. padding: 0px;
  201. }
  202. .ant-modal-content {
  203. margin-bottom: 24px;
  204. }
  205. }
  206. </style>