print-data.js 3.9 KB

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