print-data.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { getDetail, addPrint } from "@/api/supply/pickup";
  2. // import { addPrints } from '@/api/supply/pickup'
  3. import { getCompanyList } from '@/api/user'
  4. let detailArr = []
  5. let detailData = []
  6. let company = ''
  7. // 获取详情
  8. getCompanyLists()
  9. function getDetails(ids) {
  10. detailArr = []
  11. // detailData = ids
  12. let newIds = []
  13. newIds = ids
  14. let filterId =[]
  15. filterId = newIds.map(k=>{
  16. return k.id
  17. })
  18. filterId = [...new Set(filterId)]
  19. for (let i = 0; i < filterId.length; i++) {
  20. getDetail({ id: filterId[i] }).then(res => {
  21. const item = res.data
  22. detailData.push(item)
  23. const table = []
  24. item.invoicePickBeans.length = 5
  25. item.invoicePickBeans.forEach(e => {
  26. table.push({
  27. salesId: e.salesOrderId,
  28. invoiceId: e.invoiceId,
  29. id: e.id,
  30. createTime: e.id ? dateToDayFilter(item.createTime) : '',
  31. enginOrderType: e.enginOrderType == 'HOME' || e.enginOrderType == 'TRADE' ? e.enginOrderNo : e.mainOrderId,
  32. materialName: e.materialName || '',
  33. specification: e.specification || '',
  34. refundableQty: e.refundableQty || 0,
  35. // headerRemark:e.headerRemark,
  36. pjxh1Text: e.pjxh1Text || ''
  37. })
  38. });
  39. console.log(company);
  40. detailArr.push({
  41. type: item.type,
  42. tiTui:item.type === 2 ? `退货人` : `提货人`,
  43. headerRemark:item.remark,
  44. total_num: item.total_num,
  45. company: item.type === 2 ? `${company}销售退货单` : `${company}销售发货单`,
  46. pickOrderWater: item.pickOrderWater,
  47. customerNumber: item.customerNumber,
  48. nowDate: nowDate(),
  49. customerName: item.customerName || '',
  50. correspondName: item.correspondName || '',
  51. createBy: item.createBy,
  52. table
  53. })
  54. })
  55. }
  56. }
  57. function nowDate() {
  58. var date = new Date();
  59. var seperator1 = "-";
  60. var year = date.getFullYear();
  61. var month = date.getMonth() + 1;
  62. var strDate = date.getDate();
  63. if (month >= 1 && month <= 9) {
  64. month = "0" + month;
  65. }
  66. if (strDate >= 0 && strDate <= 9) {
  67. strDate = "0" + strDate;
  68. }
  69. var currentdate = year + seperator1 + month + seperator1 + strDate;
  70. console.log(currentdate);
  71. return currentdate;
  72. }
  73. function dateToDayFilter(date) {
  74. if (!date) { return '' }
  75. return date.slice(0, 10)
  76. }
  77. function getCompanyLists() {
  78. getCompanyList().then(res => {
  79. company = res.data ? res.data[0].companyName : ''
  80. })
  81. return company
  82. }
  83. // 添加次数
  84. function addPrints() {
  85. // console.log(detailData);
  86. let ids = detailData.map(item => {
  87. console.log(item.invoicePickBeans);
  88. if (item.invoicePickBeans && item.invoicePickBeans.length) {
  89. for (let index = 0; index < item.invoicePickBeans.length; index++) {
  90. const element = item.invoicePickBeans[index];
  91. // console.log(element.id ,'element.id ');
  92. return element.invoiceOrderId
  93. }
  94. } else {
  95. // console.log(item.invoiceOrderId ,'item.invoiceOrderId ');
  96. return item.invoiceOrderId || item.id
  97. }
  98. })
  99. ids = [...new Set(ids)]
  100. // console.log(document.execCommand('print'),'4545');
  101. addPrint({ ids: ids.join(',') }).then(res => {
  102. console.log('chenggong ');
  103. // this.$successMsg('提交成功');
  104. // this.$parent.getList()
  105. })
  106. }
  107. export {
  108. getDetails, getCompanyLists,
  109. detailArr,
  110. addPrints
  111. }