lrf402788946 4 лет назад
Родитель
Сommit
ad70b0f981
2 измененных файлов с 78 добавлено и 14 удалено
  1. 59 7
      app/service/order/transport.js
  2. 19 7
      app/service/util/excel.js

+ 59 - 7
app/service/order/transport.js

@@ -181,13 +181,19 @@ class TransportService extends CrudService {
     const countArr = this.getCount(data, eletter); // 占 5-6行
     arr.push(...countArr);
     // 各部分
-    // 收入部分 前4个(A-D), 运输支出部分中间4个(E-H),日常维修部分最后4个(I-L)
-    const excelData = this.getExcelData(data);
+    // 收入部分 前4个(A-D), 运输支出部分中间4个(E-H),日常维护部分最后4个(I-L)
+    let excelData = this.getExcelData(data);
+    excelData = excelData.map(i => {
+      const obj = { content: i };
+      return obj;
+    });
+    arr.push(...excelData);
+    console.log(arr);
     // 文字位置样式,都加上
-    const text = { vertAlign: 'superscript', size: 16 };
+    const text = { vertAlign: 'superscript', size: 18 };
     const alignment = { vertical: 'middle', horizontal: 'center' };
     arr = arr.map(i => {
-      i.alignment = alignment;
+      i.alignment = i.alignment = { ...alignment, ..._.get(i, alignment, {}) };
       i.font = { ...text, ..._.get(i, 'font', {}) };
       return i;
     });
@@ -203,7 +209,51 @@ class TransportService extends CrudService {
     const outBill = _.get(data, 'outBill', []);
     const daily = _.get(data, 'daily', []);
     const max = _.max([ inBill.length, outBill.length, daily.length ]);
-
+    const lineSeven = {
+      A7: '订单号',
+      B7: '运输单号',
+      C7: '货物',
+      D7: '收入金额',
+      E7: '运输单号',
+      F7: '支出项目',
+      G7: '支出金额',
+      H7: '运输支出备注',
+      I7: '维护项目',
+      J7: '维护金额',
+      K7: '维护日期',
+      L7: '维护备注',
+    };
+    // 默认第八行开始=>标题1-4行,合计5-6行,7行上面
+    const num = 8;
+    const arr = [];
+    arr.push(lineSeven);
+    // 先取出收入(A-D),再去运输支出(E-H),再取日常支出(I-L)
+    for (let i = 1; i <= max; i++) {
+      const lineInBill = _.get(inBill, i - 1, {});
+      const lineOutBill = _.get(outBill, i - 1, {});
+      const lineDaily = _.get(daily, i - 1, {});
+      // console.log(lineInBill);
+      // console.log(lineOutBill);
+      // console.log(lineDaily);
+      // 收入部分
+      const obj = {};
+      obj[`A${num - 1 + i}`] = _.get(lineInBill, 'order_no');
+      obj[`B${num - 1 + i}`] = _.get(lineInBill, 'no');
+      obj[`C${num - 1 + i}`] = _.get(lineInBill, 'name');
+      obj[`D${num - 1 + i}`] = _.get(lineInBill, 'sh_ss');
+      // 运输支出
+      obj[`E${num - 1 + i}`] = _.get(lineOutBill, 'no');
+      obj[`F${num - 1 + i}`] = _.get(lineOutBill, 'item');
+      obj[`G${num - 1 + i}`] = _.get(lineOutBill, 'money');
+      obj[`H${num - 1 + i}`] = _.get(lineOutBill, 'remark');
+      // 日常维护
+      obj[`I${num - 1 + i}`] = _.get(lineDaily, 'item');
+      obj[`J${num - 1 + i}`] = _.get(lineDaily, 'money');
+      obj[`K${num - 1 + i}`] = _.get(lineDaily, 'date');
+      obj[`L${num - 1 + i}`] = _.get(lineDaily, 'remark');
+      arr.push(obj);
+    }
+    return arr;
   }
 
   /**
@@ -247,7 +297,7 @@ class TransportService extends CrudService {
     // 日常支出
     if (count.dm || count.dm === 0) {
       const countDaily = {
-        content: `日常维支出${count.om || 0}`,
+        content: `日常维支出${count.om || 0}`,
         scell: 'I6',
         ecell: 'L6',
       };
@@ -266,7 +316,9 @@ class TransportService extends CrudService {
       content: '核算单',
       scell: 'A1',
       ecell: `${letter}4`,
-      font: { size: 20, bold: true },
+      font: { size: 22, bold: true },
+      alignment: { vertical: 'middle' },
+
     };
     return headObj;
   }

+ 19 - 7
app/service/util/excel.js

@@ -29,7 +29,6 @@ class ExcelService extends CrudService {
    * @property fn 文件名
    */
   async toExcel({ data = [], meta, fn = 'excel导出结果' } = {}) {
-    console.log('in function:');
     const nowDate = new Date().getTime();
     const filename = `${fn}.xlsx`; // -${nowDate}
     const path = `${this.root_path}${this.file_type}${this.excel_path}`;
@@ -46,14 +45,27 @@ class ExcelService extends CrudService {
       sheet.columns = meta;
       sheet.addRows(data);
     } else {
-      console.log(data);
+      // console.log(data);
       for (const row of data) {
-        const { scell, ecell, content, alignment } = row;
-        if (scell && ecell) sheet.mergeCells(scell, ecell);
-        sheet.getCell(ecell).value = content;
-        if (alignment) sheet.getCell(ecell).alignment = alignment;
+        const { scell, ecell, content, alignment, font } = row;
+        if (scell && ecell) {
+          sheet.mergeCells(scell, ecell);
+          sheet.getCell(ecell).value = content;
+          if (alignment) sheet.getCell(ecell).alignment = alignment;
+          if (font) sheet.getCell(ecell).font = font;
+        } else {
+          console.log('in function:');
+          if (_.isObject(content)) {
+            const keys = Object.keys(content);
+            for (const cell of keys) {
+              const value = content[cell];
+              sheet.getCell(cell).value = value;
+              if (alignment) sheet.getCell(cell).alignment = alignment;
+              if (font) sheet.getCell(cell).font = font;
+            }
+          }
+        }
       }
-      // sheet.mergeCells(1,1,1,2); //合并单元格,起始行,列 ,终止行,列
     }
     // 导出
     const filepath = `${path}${filename}`;