print-data.js 2.9 KB

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