print-data.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import { getDetail, addPrint,getDtailPrintDis} 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. let cNewIds = []
  8. // 获取详情
  9. getCompanyLists()
  10. function getDetails(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. let filterId = []
  19. const obj = []
  20. filterId = newIds.map(k => {
  21. obj.push(
  22. {
  23. id:k.id,
  24. invoiceId:k.invoiceId
  25. }
  26. )
  27. return k.id
  28. })
  29. filterId = [...new Set(filterId)]
  30. cNewIds =JSON.parse(JSON.stringify(filterId))
  31. getDtailPrintDis(obj).then(res=>{
  32. const item = res.data
  33. item.forEach(k=>{
  34. detailData.push(JSON.parse(JSON.stringify(k)))
  35. invoicePickBeans = k.invoicePickBeans
  36. let len = Math.ceil(invoicePickBeans.length / 5)
  37. console.log(len, '长度');
  38. for (let index = 0; index < len; index++) {
  39. const table = []
  40. if (invoicePickBeans.length) {
  41. invoicePickBeans.splice(0, 5).forEach(e => {
  42. table.push({
  43. salesId: e.salesOrderId,
  44. invoiceId: e.invoiceId,
  45. id: e.id,
  46. createTime: e.id ? dateToDayFilter(k.createTime) : '',
  47. enginOrderType: e.orderType == 'HOME' || e.orderType == 'TRADE' ? e.enginOrderNo : e.mainOrderId,
  48. materialName: e.materialName || '',
  49. specification: e.specification || '',
  50. refundableQty: e.refundableQty || 0,
  51. // headerRemark:e.headerRemark,
  52. pjxh1Text: e.pjxh1Text || ''
  53. })
  54. });
  55. }
  56. detailArr.push({
  57. pageNumber:`${len}-${index+1}`,
  58. type: k.type,
  59. tiTui: k.type === 2 ? `退货人` : `提货人`,
  60. takerPhone: k.takerPhone || '',
  61. headerRemark: k.remark,
  62. total_num: k.total_num,
  63. company: k.type === 2 ? `${company}销售退货单` : `${company}销售发货单`,
  64. pickOrderWater: k.pickOrderWater,
  65. customerNumber: k.customerNumber,
  66. takerDa: '',
  67. nowDate: nowDate(),
  68. takerName: k.type === 2 ? `退货人:${k.takerName || ''}` : `提货人:${k.takerName || ''}`,
  69. customerName: k.customerName || '',
  70. correspondName: k.correspondName,
  71. correspondNames:'',
  72. pickCar: k.pickCar || '',
  73. createBy: JSON.parse(
  74. localStorage.getItem("supply_user")
  75. ).nickName,
  76. table
  77. })
  78. }
  79. })
  80. })
  81. return
  82. for (let i = 0; i < filterId.length; i++) {
  83. getDetail({ id: filterId[i] }).then(res => {
  84. const item = res.data
  85. detailData.push(JSON.parse(JSON.stringify(item)))
  86. invoicePickBeans = item.invoicePickBeans
  87. let len = Math.ceil(invoicePickBeans.length / 5)
  88. console.log(len, '长度');
  89. for (let index = 0; index < len; index++) {
  90. const table = []
  91. if (invoicePickBeans.length) {
  92. invoicePickBeans.splice(0, 5).forEach(e => {
  93. table.push({
  94. salesId: e.salesOrderId,
  95. invoiceId: e.invoiceId,
  96. id: e.id,
  97. createTime: e.id ? dateToDayFilter(item.createTime) : '',
  98. enginOrderType: e.orderType == 'HOME' || e.orderType == 'TRADE' ? e.enginOrderNo : e.mainOrderId,
  99. materialName: e.materialName || '',
  100. specification: e.specification || '',
  101. refundableQty: e.refundableQty || 0,
  102. // headerRemark:e.headerRemark,
  103. pjxh1Text: e.pjxh1Text || ''
  104. })
  105. });
  106. }
  107. detailArr.push({
  108. pageNumber:`${len}-${index+1}`,
  109. type: item.type,
  110. tiTui: item.type === 2 ? `退货人` : `提货人`,
  111. takerPhone: item.takerPhone || '',
  112. headerRemark: item.remark,
  113. total_num: item.total_num,
  114. company: item.type === 2 ? `${company}销售退货单` : `${company}销售发货单`,
  115. pickOrderWater: item.pickOrderWater,
  116. customerNumber: item.customerNumber,
  117. takerDa: '',
  118. nowDate: nowDate(),
  119. takerName: item.type === 2 ? `退货人:${item.takerName || ''}` : `提货人:${item.takerName || ''}`,
  120. customerName: item.customerName || '',
  121. correspondName: item.correspondName,
  122. correspondNames:'',
  123. pickCar: item.pickCar || '',
  124. createBy: JSON.parse(
  125. localStorage.getItem("supply_user")
  126. ).nickName,
  127. table
  128. })
  129. }
  130. })
  131. }
  132. }
  133. function nowDate() {
  134. var date = new Date();
  135. var seperator1 = "-";
  136. var year = date.getFullYear();
  137. var month = date.getMonth() + 1;
  138. var strDate = date.getDate();
  139. if (month >= 1 && month <= 9) {
  140. month = "0" + month;
  141. }
  142. if (strDate >= 0 && strDate <= 9) {
  143. strDate = "0" + strDate;
  144. }
  145. var currentdate = year + seperator1 + month + seperator1 + strDate;
  146. console.log(currentdate);
  147. return currentdate;
  148. }
  149. function dateToDayFilter(date) {
  150. if (!date) { return '' }
  151. return date.slice(0, 10)
  152. }
  153. function getCompanyLists() {
  154. getCompanyList().then(res => {
  155. company = res.data ? res.data[0].companyName : ''
  156. })
  157. return company
  158. }
  159. // 添加次数
  160. function addPrints() {
  161. console.log(detailData);
  162. // let ids = detailData.map(item => {
  163. // console.log(item.invoicePickBeans);
  164. // if (item.invoicePickBeans && item.invoicePickBeans.length) {
  165. // for (let index = 0; index < item.invoicePickBeans.length; index++) {
  166. // const element = item.invoicePickBeans[index];
  167. // // console.log(element.id ,'element.id ');
  168. // return element.invoiceOrderId
  169. // }
  170. // } else {
  171. // // console.log(item.invoiceOrderId ,'item.invoiceOrderId ');
  172. // return item.invoiceOrderId || item.id
  173. // }
  174. // })
  175. // console.log(document.execCommand('print'),'4545');
  176. addPrint({ ids: cNewIds.join(',') }).then(res => {
  177. console.log('chenggong ');
  178. // this.$successMsg('提交成功');
  179. // this.$parent.getList()
  180. })
  181. }
  182. export {
  183. getDetails, getCompanyLists,
  184. detailArr,
  185. addPrints
  186. }