print-data.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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: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: '',
  65. pickCar:item.pickCar || '',
  66. createBy: JSON.parse(
  67. localStorage.getItem("supply_user")
  68. ).nickName,
  69. table
  70. })
  71. }
  72. })
  73. }
  74. }
  75. function nowDate() {
  76. var date = new Date();
  77. var seperator1 = "-";
  78. var year = date.getFullYear();
  79. var month = date.getMonth() + 1;
  80. var strDate = date.getDate();
  81. if (month >= 1 && month <= 9) {
  82. month = "0" + month;
  83. }
  84. if (strDate >= 0 && strDate <= 9) {
  85. strDate = "0" + strDate;
  86. }
  87. var currentdate = year + seperator1 + month + seperator1 + strDate;
  88. console.log(currentdate);
  89. return currentdate;
  90. }
  91. function dateToDayFilter(date) {
  92. if (!date) { return '' }
  93. return date.slice(0, 10)
  94. }
  95. function getCompanyLists() {
  96. getCompanyList().then(res => {
  97. company = res.data ? res.data[0].companyName : ''
  98. })
  99. return company
  100. }
  101. // 添加次数
  102. function addPrint() {
  103. let ids = detailData.map(item => {
  104. if (item.invoicePickBeans && item.invoicePickBeans.length) {
  105. for (let index = 0; index < item.invoicePickBeans.length; index++) {
  106. const element = item.invoicePickBeans[index];
  107. // console.log(element.id ,'element.id ');
  108. return element.id
  109. }
  110. } else {
  111. // console.log(item.invoiceOrderId ,'item.invoiceOrderId ');
  112. return item.invoiceOrderId || item.id
  113. }
  114. })
  115. // console.log(document.execCommand('print'),'4545');
  116. addPrints({ ids: ids.join(',') }).then(res => {
  117. console.log('chenggong ');
  118. // this.$successMsg('提交成功');
  119. // this.$parent.getList()
  120. })
  121. }
  122. export {
  123. getDetail, getCompanyLists,
  124. detailArr,
  125. addPrint
  126. }