print-data.js 4.3 KB

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