print-data.js 4.0 KB

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