瀏覽代碼

1. 台账分解,界面显示小数位数
2. 导入Excel清单,前端等待时长延长

MaiXinRong 6 年之前
父節點
當前提交
655c4e8c44

+ 18 - 0
app/controller/ledger_controller.js

@@ -58,8 +58,26 @@ module.exports = app => {
                     return cols.indexOf(c.field) > -1;
                 });
             }
+            function setColFormat(cols, field, formatter) {
+                const col = _.find(cols, function (c) {
+                    return c.field === field;
+                });
+                col.formatter = formatter;
+            }
+            const qtyFormatter = this.ctx.helper.getNumberFormatter(this.ctx.tender.info.decimal.qty);
+            const tpFormatter = this.ctx.helper.getNumberFormatter(this.ctx.tender.info.decimal.tp);
+            const upFormatter = this.ctx.helper.getNumberFormatter(2);
             const ledger = JSON.parse(JSON.stringify(spreadConst.ledgerSpread));
+            setColFormat(ledger.cols, 'quantity', qtyFormatter);
+            setColFormat(ledger.cols, 'dgn_qty1', qtyFormatter);
+            setColFormat(ledger.cols, 'dgn_qty2', qtyFormatter);
+            setColFormat(ledger.cols, 'deal_qty', qtyFormatter);
+            setColFormat(ledger.cols, 'unit_price', upFormatter);
+            setColFormat(ledger.cols, 'total_price', tpFormatter);
+            setColFormat(ledger.cols, 'deal_tp', tpFormatter);
             const pos = JSON.parse(JSON.stringify(spreadConst.ledgerPosSpread));
+            setColFormat(pos.cols, 'quantity', qtyFormatter);
+
             const tender = this.ctx.tender;
             if (this._ledgerReadOnly(tender.data)) {
                 ledger.readOnly = true;

+ 11 - 0
app/extend/helper.js

@@ -358,4 +358,15 @@ module.exports = {
         const reg2 = /([a-z0-9]+$)/i;
         return reg1.test(code) && reg2.test(code);
     },
+
+    getNumberFormatter(decimal) {
+        if (decimal <= 0) {
+            return "0";
+        }
+        let pre = "0.";
+        for (let i = 0; i < decimal; i++) {
+            pre += "#"
+        }
+        return pre;
+    }
 };

+ 6 - 9
app/lib/analysis_excel.js

@@ -197,9 +197,9 @@ class ImportBaseTree {
         for (const node of this.items) {
             if (node.children && node.children.length > 0) { continue; }
             if (!node.pos || node.pos.length === 0) { continue; }
-            node.quantity = _.sum(_.map(node.pos, 'quantity'));
+            node.quantity = _.round(_.sum(_.map(node.pos, 'quantity')), 6);
             if (node.quantity && node.unit_price) {
-                node.total_price = node.quantity * node.unit_price;
+                node.total_price = _.round(node.quantity * node.unit_price, 6);
             } else {
                 node.total_price = null;
             }
@@ -229,11 +229,8 @@ class AnalysisExcelTree {
     }
 
     toNumber (value) {
-        if (value) {
-            return _.isNumber(value) ? value : _.toNumber(value);
-        } else {
-            return null;
-        }
+        let num = _.toNumber(value);
+        return _.isNaN(num) ? null : num;
     }
 
     /**
@@ -254,7 +251,7 @@ class AnalysisExcelTree {
         node.drawing_code = row[this.colsDef.drawing_code];
         node.memo = row[this.colsDef.memo];
         if (node.quantity && node.unit_price) {
-            node.total_price = node.quantity * node.unit_price;
+            node.total_price = _.round(node.quantity * node.unit_price, 6);
         } else {
             node.total_price = null;
         }
@@ -276,7 +273,7 @@ class AnalysisExcelTree {
         node.drawing_code = row[this.colsDef.drawing_code];
         node.memo = row[this.colsDef.memo];
         if (node.quantity && node.unit_price) {
-            node.total_price = node.quantity * node.unit_price;
+            node.total_price = _.round(node.quantity * node.unit_price, 6);
         } else {
             node.total_price = null;
         }

二進制
app/public/files/template/ledger/渭武12标.xls


+ 1 - 1
app/public/js/global.js

@@ -159,7 +159,7 @@ const postDataCompress = function (url, data, successCallback, errorCallBack) {
         data: {'data': LZString.compressToUTF16(JSON.stringify(data))},
         dataType: 'json',
         cache: false,
-        timeout: 5000,
+        timeout: 60000, // 导入清单Excel(10w行)预计需要时间
         beforeSend: function(xhr) {
             let csrfToken = Cookies.get('csrfToken');
             xhr.setRequestHeader('x-csrf-token', csrfToken);

+ 1 - 1
app/public/js/ledger.js

@@ -34,7 +34,7 @@ $(document).ready(function() {
     }
     treeSetting.calcFun = function (node) {
         if (checkZero(node.dgn_qty1)) {
-            node.dgn_price = _.round(node.total_price/node.dgn_qty1, 2);
+            node.dgn_price = _.round(node.total_price/node.dgn_qty1, 6);
         } else {
             node.dgn_price = null;
         }

+ 1 - 1
app/public/js/path_tree.js

@@ -880,7 +880,7 @@ const treeCalc = {
                 const result = {};
                 const fieldCalc = function (field) {
                     if (rst[field]) {
-                        result[field] = x[field] ? rst[field] + x[field] : rst[field];
+                        result[field] = x[field] ? _.round(rst[field] + x[field], 6) : rst[field];
                     } else {
                         result[field] = x[field] ? x[field] : undefined;
                     }

+ 0 - 21
app/public/js/spreadjs_rela/import_excel.js

@@ -1,21 +0,0 @@
-/**
- * 导入Excel相关js
- *
- * @author Mai
- * @date 2019/01/04
- * @version
- */
-'use strict';
-
-class ImportExcel {
-    constructor (setting) {
-        this.setting = setting;
-    }
-
-    analysisExcel(file) {
-        const excelIo = new GC.Spread.Excel.IO();
-        excelIo.open(file, function () {
-
-        });
-    }
-}

+ 2 - 2
app/public/js/spreadjs_rela/spreadjs_zh.js

@@ -225,7 +225,7 @@ const SpreadJsObj = {
             });
             // 设置列单元格格式
             sheet.zh_setting.cols.forEach(function (col, j) {
-                if (!col.cellType) { return; }
+                //if (!col.cellType) { return; }
 
                 if (col.cellType === 'tree') {
                     if (!sheet.extendCellType.tree) {
@@ -239,7 +239,7 @@ const SpreadJsObj = {
                     sheet.getRange(-1, j, -1, 1).cellType(sheet.extendCellType.tip);
                 }
                 if (col.formatter) {
-                    sheet.getRange(-1, j, -1, 1).format(col.formatter);
+                    sheet.getRange(-1, j, -1, 1).formatter(col.formatter);
                 }
             });
             this.endMassOperation(sheet);

+ 19 - 2
test/app/lib/analysis_excel.test.js

@@ -68,10 +68,9 @@ describe('test/app/lib/analysis_excel.test.js', () => {
         // 检查第203-1-a的数量
         const xmj = result.codeNodes['1-2-2-1-1'];
         const gcl = xmj.children[0];
-        console.log(gcl);
         assert(gcl.quantity === 92954.75);
     });
-    it('analysis Excel Test Data', function* () {
+    it('Analysis Excel Test Data And Import', function* () {
         const excelFile = app.baseDir  + '/app/public/files/template/ledger/导入分项清单Excel格式.xls';
         const wb = Xlsx.readFile(excelFile);
         const name = wb.SheetNames[0];
@@ -96,4 +95,22 @@ describe('test/app/lib/analysis_excel.test.js', () => {
         };
         yield ctx.service.ledger.importExcel(sheetData);
     });
+    it('analysis 渭武12标 Excel', function* () {
+        const excelFile = app.baseDir  + '/app/public/files/template/ledger/渭武12标.xls';
+        const wb = Xlsx.readFile(excelFile);
+        const name = wb.SheetNames[0];
+        const sheetData = {
+            rows: Xlsx.utils.sheet_to_json(wb.Sheets[name], {header: 1}),
+            merge: wb.Sheets[name]["!merges"],
+        };
+        const ctx = app.mockContext();
+        ctx.tender = { id: 2 };
+        // pos需要记录createUserId
+        ctx.session = {
+            sessionUser: {
+                accountId: 2,
+            },
+        };
+        yield ctx.service.ledger.importExcel(sheetData);
+    });
 });