preview.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. addPrint: {
  34. type: Function,
  35. default: null
  36. },
  37. },
  38. data() {
  39. return {
  40. visible: false,
  41. spinning: true,
  42. waitShowPrinter: false,
  43. // 纸张宽 mm
  44. width: 0,
  45. // 模板
  46. hiprintTemplate: {},
  47. // 数据
  48. printData: {},
  49. loading: true
  50. }
  51. },
  52. computed: {},
  53. watch: {},
  54. created() {
  55. },
  56. mounted() {
  57. },
  58. methods: {
  59. // handleExport() {
  60. // downloadPDF(this.$refs.printDom);
  61. // },
  62. hideModal() {
  63. this.visible = false
  64. this.waitShowPrinter = false
  65. this.$emit('initPrint')
  66. // console.log(this.$parent);
  67. },
  68. show(hiprintTemplate, printData, width = '210') {
  69. this.visible = true
  70. this.width = width
  71. this.hiprintTemplate = hiprintTemplate
  72. this.printData = printData
  73. setTimeout(() => {
  74. // eslint-disable-next-line no-undef
  75. $('#preview_content').html(hiprintTemplate.getHtml(printData))
  76. this.spinning = false
  77. }, 500)
  78. },
  79. print() {
  80. try {
  81. if (typeof this.addPrint === 'function') {
  82. this.addPrint('addPrints').then(() => {
  83. this.hiprintTemplate.print(
  84. this.printData,
  85. {},
  86. {
  87. callback: async() => {
  88. this.hiprintTemplate = {}
  89. // setTimeout(() => {
  90. // console.error('更新发货汇总列表')
  91. // // this.$successMsg('更新成功')
  92. // }, 1000)
  93. setTimeout(() => {
  94. console.error('更新发货汇总列表')
  95. this.$emit('refreshList')
  96. }, 1000)
  97. }
  98. }
  99. )
  100. }).catch(err=>{
  101. this.$errorMsg('刷新重试打印')
  102. })
  103. } else {
  104. throw new Error('加载失败,刷新重试')
  105. }
  106. } catch (e) {
  107. this.$errorMsg(e)
  108. // '调用打印次数接口失败'
  109. }
  110. setTimeout(() => {
  111. this.hideModal()
  112. }, 2000)
  113. }
  114. // toPdf() {
  115. // downloadPDF(this.$refs.printDom);
  116. // this.hiprintTemplate.toPdf({}, '打印预览');
  117. // },
  118. }
  119. }
  120. </script>
  121. <style scoped>
  122. ::v-deep .el-dialog__body {
  123. padding: 0;
  124. }
  125. ::v-deep tr {
  126. height: 40px !important;
  127. }
  128. ::v-deep td {
  129. height: 40px !important;
  130. overflow: hidden;
  131. /* display: -webkit-box; */
  132. -webkit-line-clamp: 2;
  133. /* 数值代表显示几行 */
  134. -webkit-box-orient: vertical;
  135. }
  136. ::v-deep .hiprint-printPaper {
  137. margin: 0 auto;
  138. }
  139. /* ::v-deep tr td {
  140. border: 0 !important;
  141. } */
  142. ::v-deep .hiprint-paperNumber {
  143. display: none;
  144. }
  145. .ant-modal-body {
  146. padding: 0px;
  147. }
  148. .ant-modal-content {
  149. margin-bottom: 24px;
  150. }
  151. @media print {
  152. /*
  153. td {
  154. border: none !important;
  155. } */
  156. .drag_item_box {
  157. height: 100%;
  158. padding: 6px;
  159. }
  160. .drag_item_box > div {
  161. height: 100%;
  162. width: 100%;
  163. background-color: #fff;
  164. display: flex;
  165. justify-content: center;
  166. align-items: center;
  167. }
  168. .drag_item_box > div > a {
  169. text-align: center;
  170. text-decoration-line: none;
  171. }
  172. .drag_item_box > div > a > span {
  173. font-size: 28px;
  174. }
  175. .drag_item_box > div > a > p {
  176. margin: 0;
  177. }
  178. .drag_item_title {
  179. font-size: 16px;
  180. padding: 12px 6px 0 6px;
  181. font-weight: bold;
  182. }
  183. .card-design {
  184. overflow: hidden;
  185. overflow-x: auto;
  186. overflow-y: auto;
  187. }
  188. ::v-deep .el-dialog__body {
  189. padding: 0;
  190. }
  191. ::v-deep table {
  192. height: 240px !important;
  193. }
  194. ::v-deep tr {
  195. height: 40px !important;
  196. }
  197. ::v-deep .hiprint-printPaper {
  198. margin: 0 auto;
  199. }
  200. ::v-deep tr td {
  201. border: 0 !important;
  202. /* width: 911px !important;
  203. height: 529px !important; */
  204. }
  205. .ant-modal-body {
  206. padding: 0px;
  207. }
  208. .ant-modal-content {
  209. margin-bottom: 24px;
  210. }
  211. }
  212. </style>