printTg.vue 4.9 KB

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