print.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <ele-modal title="二维码" :visible.sync="QRvisible" v-if="QRvisible" width="800px" :maxable="true">
  3. <div id="printSection">
  4. <div v-for="(item, index) in codeList" :key="index"
  5. style=" display: flex; padding-left: 20px; align-items: center; justify-content: center; margin: auto; margin-bottom: 30px;">
  6. <div style="width: 250px; height: 240px; ">
  7. <img :src="item.qrcode" alt="QR Code" style=" width: 200px; height: 200px;">
  8. </div>
  9. <div
  10. style="width: 440px; display: flex; flex-direction: column; flex-wrap: wrap; justify-content: space-between; align-items:flex-start;">
  11. <div style="text-align: left; font-size: 16px; ">
  12. <span style="display: inline-block; width: 100px;">产品编码:</span>
  13. <span style="color: #000;">{{ item.productCode }}</span>
  14. </div>
  15. <div style="text-align: left; font-size: 16px; ">
  16. <span style="display: inline-block; width: 100px;">名称:</span>
  17. <span style="color: #000;">{{ item.productName }}</span>
  18. </div>
  19. <div style="text-align: left; font-size: 16px; ">
  20. <span style="display: inline-block; width: 100px;">牌号:</span>
  21. <span style="color: #000;">{{ item.brandNo }}</span>
  22. </div>
  23. <div style="text-align: left; font-size: 16px; ">
  24. <span style="display: inline-block; width: 100px;">型号:</span>
  25. <span style="color: #000;">{{ item.model }}</span>
  26. </div>
  27. <div style="text-align: left; font-size: 16px; ">
  28. <span style="display: inline-block; width: 100px;">生产数量:</span>
  29. <span style="color: #000;">{{ item.formingNum }} {{ item.unit }}</span>
  30. </div>
  31. <div style="text-align: left; font-size: 16px; ">
  32. <span style="display: inline-block; width: 100px;">生产重量:</span>
  33. <span style="color: #000;">{{ item.formingWeight }} {{ item.weightUnit }}</span>
  34. </div>
  35. <div style="text-align: left; font-size: 16px; ">
  36. <span style="display: inline-block; width: 100px;">状态:</span>
  37. <span style="color: #000;">{{ statusList[item.status] }}</span>
  38. </div>
  39. <div style="text-align: left; font-size: 16px; ">
  40. <span style="display: inline-block; width: 100px;">工艺路线:</span>
  41. <span style="color: #000;">{{ item.produceRoutingName }} </span>
  42. </div>
  43. <div style="text-align: left; font-size: 16px; ">
  44. <span style="display: inline-block; width: 100px;">颜色:</span>
  45. <span style="color: #000;">{{ item.colorKey }} </span>
  46. </div>
  47. <div style="text-align: left; font-size: 16px; ">
  48. <span style="display: inline-block; width: 100px;">机型:</span>
  49. <span style="color: #000;">{{ item.modelKey }} </span>
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54. <div slot="footer">
  55. <el-button @click="print">打印预览</el-button>
  56. <el-button @click="close">关闭</el-button>
  57. </div>
  58. </ele-modal>
  59. </template>
  60. <script>
  61. import QRCode from 'qrcode'
  62. import {
  63. queryPrint
  64. } from '@/api/produceOrder/index.js';
  65. export default {
  66. name: 'print',
  67. data() {
  68. return {
  69. QRvisible: false,
  70. codeList: [],
  71. statusList: {
  72. 4: '待生产',
  73. 5: '生产中',
  74. 6: '已完成',
  75. 7: '已延期',
  76. 8: '待下达'
  77. }
  78. }
  79. },
  80. methods: {
  81. open(ids) {
  82. queryPrint({ ids }).then(res => {
  83. this.codeList = res;
  84. this.QRvisible = true
  85. this.$nextTick(() => {
  86. this.generateQRCodes()
  87. })
  88. })
  89. },
  90. generateQRCodes() {
  91. this.codeList.forEach(item => {
  92. QRCode.toDataURL(item.id)
  93. .then(url => {
  94. item.qrcode = url
  95. this.$forceUpdate()
  96. })
  97. .catch(err => {
  98. console.error(err)
  99. })
  100. })
  101. },
  102. close() {
  103. this.QRvisible = false
  104. },
  105. print() {
  106. const printSection = document.getElementById('printSection');
  107. // 创建打印任务
  108. const printWindow = window.open('', '_blank');
  109. printWindow.document.open();
  110. printWindow.document.write('<html><head><title>打印预览</title>');
  111. printWindow.document.write('<link rel="stylesheet" href="your-stylesheet-url.css" type="text/css" />');
  112. printWindow.document.write('</head><body>');
  113. printWindow.document.write(printSection.innerHTML);
  114. printWindow.document.write('</body></html>');
  115. printWindow.document.close();
  116. printWindow.onload = function () {
  117. printWindow.print();
  118. };
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. @media print {
  125. #printSection {
  126. font-size: 34px;
  127. span {
  128. font-size: 34px;
  129. }
  130. }
  131. }
  132. </style>