codeListPrint.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import moment from 'moment'
  2. import QRCode from 'qrcodejs2'
  3. import { v4 as uuidv4 } from "uuid";
  4. function codeListPrint(data, domId) {
  5. if (data.length == 0) {
  6. return
  7. }
  8. let preHtml = ` <div style="width: 800px;position: relative;">
  9. <div style="width: 100%;position: relative;text-align: center;">
  10. <span style="font-size: 24px;font-weight: 500;">诸暨市新丝维化纤有限公司</span>
  11. </div>`
  12. let endHtml = `<div style="display: flex;flex-direction: row-reverse;">
  13. <span>注:不同批号,请勿混用</span>
  14. </div>
  15. </div>`
  16. let res = ``;
  17. let uuidList = [];
  18. for (let i = 0; i < data.length; i++) {
  19. let item = data[i]
  20. let {
  21. qrCode,//序号
  22. machineTool,//机台
  23. boxWeight,//箱重-车重
  24. canisterweight,//筒重
  25. canisterNum,//筒数
  26. grossWeight,//毛重
  27. suttle,//净重
  28. workShifts,//班次
  29. tubecolor,//管色
  30. boxOrderNum, //生成的随机码
  31. myNO,//箱号
  32. productionDate, //日期
  33. printFormat, //格式
  34. productName, //产品名
  35. productSpecifications, //规格
  36. productColor, //色泽
  37. lotNum, //批次
  38. levels,//等级
  39. directionOfTwist,//捻向
  40. qrCodeData,
  41. boxNumber//箱号
  42. } = item
  43. let theNumber = Number(printFormat) //小包装:1 大包装:2
  44. while (theNumber > 0) {
  45. let uuid = uuidv4().slice(0, 8);
  46. theNumber--;
  47. res += preHtml;
  48. // let qrCodeData = '123456';
  49. uuidList.push({
  50. id: uuid,
  51. qrCodeData: qrCodeData
  52. })
  53. res += `<div style="width: 100%;display: flex;justify-content: center;margin:5px 0;">
  54. <div id="${uuid}" style="width: 120px;height: 120px;"></div>
  55. </div>
  56. <table style="width: 100%;border-collapse:collapse;" cellpadding="10" border="1">
  57. <tr style="text-align: center;">
  58. <td style="width: 100px;" colspan="1">品种</td>
  59. <td style="width: 300px;">${productName}</td>
  60. <td style="width: 100px;" colspan="1">规格</td>
  61. <td style="width: 300px;" colspan="2">${productSpecifications}</td>
  62. </tr>
  63. <tr style="text-align: center;">
  64. <td style="width: 100px;" colspan="1">批号</td>
  65. <td style="width: 300px;">${lotNum}</td>
  66. <td style="width: 100px;" colspan="1">色号</td>
  67. <td style="width: 300px;" colspan="2">${productColor}</td>
  68. </tr>
  69. <tr style="text-align: center;">
  70. <td style="width: 100px;" colspan="1">等级</td>
  71. <td style="width: 300px;">${levels}</td>
  72. <td style="width: 100px;" colspan="1">箱号</td>
  73. <td style="width: 250px;" colspan="1">${qrCode}</td>
  74. <td style="width: 50px;" colspan="1">${boxNumber}</td>
  75. </tr>
  76. <tr style="text-align: center;">
  77. <td style="width: 100px;" colspan="1">筒数</td>
  78. <td style="width: 300px;">${canisterNum}&ensp;&ensp;&ensp;${tubecolor}</td>
  79. <td style="width: 100px;" colspan="1">捻向</td>
  80. <td style="width: 300px;" colspan="2">${directionOfTwist}</td>
  81. </tr>
  82. <tr style="text-align: center;">
  83. <td style="width: 100px;" colspan="1">班次</td>
  84. <td style="width: 300px;">${workShifts}&ensp;&ensp;&ensp;${machineTool}</td>
  85. <td style="width: 100px;" colspan="1">日期</td>
  86. <td style="width: 300px;" colspan="2">${productionDate}</td>
  87. </tr>
  88. <tr style="text-align: center;">
  89. <td style="width: 100px;" colspan="1">毛重</td>
  90. <td style="width: 300px;">${grossWeight}</td>
  91. <td style="width: 100px;" colspan="1">净重</td>
  92. <td style="width: 300px;font-size: 20px;font-weight: 500;" colspan="2">${suttle}</td>
  93. </tr>
  94. </table>`
  95. res += endHtml;
  96. }
  97. }
  98. document.body.innerHTML = document.getElementById(domId).innerHTML = res;
  99. for (var i = 0; i < uuidList.length; i++) {
  100. let data = uuidList[i]
  101. new QRCode(document.getElementById("" + data.id), {
  102. text: sleep(1) + data.qrCodeData,
  103. width: 120,
  104. height: 120,
  105. colorDark: "#000000",
  106. colorLight: "#ffffff",
  107. correctLevel: QRCode.CorrectLevel.H,
  108. });
  109. }
  110. window.print();//打印
  111. // window.location.reload();
  112. return false;
  113. }
  114. // 延迟
  115. function sleep(ms) {
  116. var unixtime_ms = new Date().getTime();
  117. while (new Date().getTime() < unixtime_ms + ms) { }
  118. return "";
  119. }
  120. export default codeListPrint