printSr.vue 5.5 KB

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