preview.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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('getDtailPrintDis').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. this.hideModal()
  95. this.$emit('refreshList')
  96. }, 1000)
  97. }
  98. }
  99. )
  100. }).catch(() => {
  101. this.$confirm('系统提示:单被商家取消预约,请刷新页面,重新选择打印', '提示', {
  102. confirmButtonText: '确定',
  103. showCancelButton: false,
  104. type: 'warning',
  105. center: true
  106. }).then(() => {
  107. this.hideModal()
  108. this.$emit('refreshList')
  109. })
  110. })
  111. } else {
  112. console.log(333)
  113. // throw new Error('加载失败,刷新重试')
  114. }
  115. } catch (e) {
  116. this.$errorMsg(e)
  117. // '调用打印次数接口失败'
  118. }
  119. }
  120. // toPdf() {
  121. // downloadPDF(this.$refs.printDom);
  122. // this.hiprintTemplate.toPdf({}, '打印预览');
  123. // },
  124. }
  125. }
  126. </script>
  127. <style scoped>
  128. ::v-deep .el-dialog__body {
  129. padding: 0;
  130. }
  131. ::v-deep tr {
  132. height: 40px !important;
  133. }
  134. ::v-deep td {
  135. height: 40px !important;
  136. overflow: hidden;
  137. /* display: -webkit-box; */
  138. -webkit-line-clamp: 2;
  139. /* 数值代表显示几行 */
  140. -webkit-box-orient: vertical;
  141. }
  142. ::v-deep .hiprint-printPaper {
  143. margin: 0 auto;
  144. }
  145. /* ::v-deep tr td {
  146. border: 0 !important;
  147. } */
  148. ::v-deep .hiprint-paperNumber {
  149. display: none;
  150. }
  151. .ant-modal-body {
  152. padding: 0px;
  153. }
  154. .ant-modal-content {
  155. margin-bottom: 24px;
  156. }
  157. @media print {
  158. /*
  159. td {
  160. border: none !important;
  161. } */
  162. .drag_item_box {
  163. height: 100%;
  164. padding: 6px;
  165. }
  166. .drag_item_box > div {
  167. height: 100%;
  168. width: 100%;
  169. background-color: #fff;
  170. display: flex;
  171. justify-content: center;
  172. align-items: center;
  173. }
  174. .drag_item_box > div > a {
  175. text-align: center;
  176. text-decoration-line: none;
  177. }
  178. .drag_item_box > div > a > span {
  179. font-size: 28px;
  180. }
  181. .drag_item_box > div > a > p {
  182. margin: 0;
  183. }
  184. .drag_item_title {
  185. font-size: 16px;
  186. padding: 12px 6px 0 6px;
  187. font-weight: bold;
  188. }
  189. .card-design {
  190. overflow: hidden;
  191. overflow-x: auto;
  192. overflow-y: auto;
  193. }
  194. ::v-deep .el-dialog__body {
  195. padding: 0;
  196. }
  197. ::v-deep table {
  198. height: 240px !important;
  199. }
  200. ::v-deep tr {
  201. height: 40px !important;
  202. }
  203. ::v-deep .hiprint-printPaper {
  204. margin: 0 auto;
  205. }
  206. ::v-deep tr td {
  207. border: 0 !important;
  208. /* width: 911px !important;
  209. height: 529px !important; */
  210. }
  211. .ant-modal-body {
  212. padding: 0px;
  213. }
  214. .ant-modal-content {
  215. margin-bottom: 24px;
  216. }
  217. }
  218. </style>