oldOutBoundPrint.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. function oldOutBoundPrint(data, domId, isRetail = false) {
  2. console.log(data);
  3. let { outStockDate, remark, unitName, printUser } = data.form
  4. let { tableData } = data
  5. let date = new Date(outStockDate)
  6. console.log(date);
  7. let yy = date.getFullYear();
  8. let mm = date.getMonth() + 1;
  9. if (mm < 10) {
  10. mm = "0" + mm;
  11. }
  12. let dd = date.getDate();
  13. if (dd < 10) {
  14. dd = "0" + dd;
  15. }
  16. let tableHeader = ``
  17. if (isRetail) { //零售
  18. tableHeader = `<td style="width: 100px;">名称</td>
  19. <td style="width: 100px;">规格</td>
  20. <td style="width: 100px;">单位</td>
  21. <td style="width: 100px;">数量</td>
  22. <td style="width: 100px;">单价</td>
  23. <td style="width: 100px;">金额</td>`
  24. } else {
  25. tableHeader = `<td style="width: 100px;">名称</td>
  26. <td style="width: 100px;">规格</td>
  27. <td style="width: 100px;">批号</td>
  28. <td style="width: 100px;">单位</td>
  29. <td style="width: 100px;">数量</td>
  30. <td style="width: 100px;">单价</td>
  31. <td style="width: 100px;">金额</td>`
  32. }
  33. let printContent = `<div style="width: 700px;position: relative;">
  34. <div
  35. style="width: 100%;position: relative;text-align: center;display: flex;flex-direction: column;margin-bottom: 10px;">
  36. <span style="font-size: 24px;font-weight: 500;">诸暨市新丝维化纤有限公司</span>
  37. <span>销售出库单</span>
  38. </div>
  39. <div>
  40. <div style="margin-bottom: 3px; padding: 0 10px;"><span>单位名称:${unitName}</span></div>
  41. <div style="display: flex;justify-content: space-between;padding: 0 20px;">
  42. <span>备注:${remark}</span><span>出库日期:&ensp;${yy}&ensp;年&ensp;${mm}&ensp;月&ensp;${dd}&ensp;日</span>
  43. </div>
  44. </div>
  45. <table style="width: 100%;border-collapse:collapse;" cellpadding="10" border="1">
  46. <tr style="text-align: center;">
  47. ${tableHeader}
  48. </tr>`;
  49. let totalPrice = 0, totalWeight = 0;
  50. for (let i = 0; i < tableData.length; i++) {
  51. let item = tableData[i];
  52. let { productName, productSpecifications, lotNumber, unit, productNumber, productUnitPrice, productAmounts, actualWeight } = item
  53. if (Number(productAmounts)) {
  54. totalPrice += Number(productAmounts);
  55. }
  56. if (Number(actualWeight)) {
  57. totalWeight += Number(actualWeight);
  58. }
  59. printContent += `<tr style="text-align: center;">
  60. <td>${productName}</td>
  61. <td>${productSpecifications}</td>
  62. <td>${lotNumber}</td>
  63. <td>${unit}</td>
  64. <td>${actualWeight}</td>
  65. <td>${productUnitPrice}</td>
  66. <td>${productAmounts}</td>
  67. </tr>`
  68. }
  69. totalPrice = totalPrice.toFixed(2);
  70. totalWeight = totalWeight.toFixed(2);
  71. printContent += `<tr style="text-align: center;border: none;">
  72. <td style="width: 100px;">合计</td>
  73. <td style="width: 100px;"></td>
  74. ${isRetail ? '' : '<td style="width: 100px;"></td>'}
  75. <td style="width: 100px;"></td>
  76. <td style="width: 100px;">${totalWeight}</td>
  77. <td style="width: 100px;"></td>
  78. <td style="width: 100px;">${totalPrice}</td>
  79. </tr>`
  80. printContent += `</table>
  81. <div><span>制表人:${printUser}</span></div>
  82. </div>`
  83. document.body.innerHTML = document.getElementById(domId).innerHTML = printContent;
  84. window.print(); //打印
  85. window.location.reload();
  86. return false;
  87. }
  88. export default oldOutBoundPrint