Chenshilong 7 роки тому
батько
коміт
431f1814ff

+ 48 - 36
public/calc_util.js

@@ -1,6 +1,7 @@
 /**
  * Created by Tony on 2017/6/21.
  * Modified by CSL, 2017-08-01
+ * 引入多套计算程序、费率同步、人工系数同步、改进基数计算、费字段映射等。
  */
 
 let executeObj = {
@@ -40,14 +41,40 @@ let executeObj = {
 };
 
 class Calculation {
-/*    init(template, feeRates){
+    // 先编译公用的基础数据
+    compilePublics(feeRates, labourCoes, feeTypes){
         let me = this;
-        me.template = template;
-        me.feeRates = feeRates;
-        me.hasCompiled = false;
-    };*/
+        let private_compile_feeFile = function() {
+            if (feeRates) {
+                me.compiledFeeRates = {};
+                for (let rate of feeRates) {
+                    me.compiledFeeRates["feeRate_" + rate.ID] = rate;
+                }
+            }
+        };
+        let private_compile_labourCoeFile = function() {
+            if (labourCoes) {
+                me.compiledLabourCoes = {};
+                for (let coe of labourCoes) {
+                    me.compiledLabourCoes["LabourCoe_" + coe.ID] = coe;
+                }
+            }
+        };
+        let private_compile_feeType = function() {
+            if (feeTypes) {
+                me.compiledFeeTypes = {};
+                for (let ft of feeTypes) {
+                    me.compiledFeeTypes[ft.type] = ft.name;
+                }
+            }
+        };
 
-    compile(template, feeRates, labourCoes){
+        private_compile_feeFile();
+        private_compile_labourCoeFile();
+        private_compile_feeType();
+    };
+
+    compileTemplate(template){
         let me = this;
         template.hasCompiled = false;
         template.errs = [];
@@ -109,44 +136,32 @@ class Calculation {
                 let item = template.calcItems[idx];
                 item.compiledExpr = item.expression.split('@(').join('$CE.at(');
                 item.compiledExpr = item.compiledExpr.split('base(').join('$CE.base(');
-                //item.compiledExpr = item.compiledExpr.split('rate(').join('$CE.rate(');
-                //item.compiledExpr = item.compiledExpr.split('factor(').join('$CE.factor(');
+
                 if (item.labourCoeID){
                     let lc = me.compiledLabourCoes["LabourCoe_" + item.labourCoeID].coe;
                     item.dispExpr = item.dispExpr.replace(/L/gi, lc.toString());
                     item.compiledExpr = item.compiledExpr.replace(/L/gi, lc.toString());
-                }
-            }
-        };
-        let private_compile_feeFile = function() {
-            if (feeRates) {
-                me.compiledFeeRate = {};
-                for (let rate of feeRates) {
-                    me.compiledFeeRate["feeRate_" + rate.ID] = rate;
-                }
-            }
-        };
-        let private_compile_labourCoeFile = function() {
-            if (labourCoes) {
-                me.compiledLabourCoes = {};
-                for (let coe of labourCoes) {
-                    me.compiledLabourCoes["LabourCoe_" + coe.ID] = coe;
-                }
+                };
+
+                if (item.feeRateID) {
+                    item.feeRate = me.compiledFeeRates["feeRate_" + item.feeRateID].rate;
+                };
+
+                // 字段名映射
+                item.displayFieldName = me.compiledFeeTypes[item.fieldName];
             }
         };
 
         if (template && template.calcItems && template.calcItems.length > 0) {
             template.compiledSeq = [];
             template.compiledTemplate = {};
-            //1. first round -> prepare
-            private_compile_feeFile();
-            private_compile_labourCoeFile();
+
             for (let i = 0; i < template.calcItems.length; i++) {
                 let item = template.calcItems[i];
                 template.compiledTemplate[item.ID] = item;
                 template.compiledTemplate[item.ID + "_idx"] = i;
             }
-            //2. second round -> go!
+
             for (let i = 0; i < template.calcItems.length; i++) {
                 private_setup_seq(template.calcItems[i], i);
             }
@@ -156,7 +171,7 @@ class Calculation {
             } else {
                 console.log('errors: ' + template.errs.toString());
             }
-        }
+        };
     };
 
     calculate($treeNode){
@@ -175,13 +190,10 @@ class Calculation {
             for (let idx of template.compiledSeq) {
                 let calcItem = template.calcItems[idx];
 
-                let feeRate = 100;    // 100%
-                // 下面三项用于界面显示。
-                if (calcItem.feeRateID) {
-                    feeRate = me.compiledFeeRate["feeRate_" + calcItem.feeRateID].rate;
-                    calcItem.feeRate = feeRate;
-                };
+                let feeRate = calcItem.feeRate;
+                if (!feeRate) feeRate = 100;    // 100%
                 calcItem.unitFee = eval(calcItem.compiledExpr) * feeRate * 0.01;   // 如果eval()对清单树有影响,就换成小麦的Expression对象再试
+
                 let quantity = $treeNode.data.quantity;
                 if (!quantity) quantity = 0;
                 calcItem.totalFee = calcItem.unitFee * quantity;

+ 19 - 2
web/building_saas/main/js/calc/calc_fees.js

@@ -4,11 +4,11 @@
 
 let feeType = [
     {type: 'common', name: '工程造价'},
-    {type: 'labour', name: '人工费'},
+    {type: 'baseLabour', name: '基价人工费'},
     {type: 'material', name: '材料费'},
     {type: 'machine', name: '机械费'},
     {type: 'rationDirect', name: '定额直接费'},
-    {type: 'management', name: '企业管理'},
+    {type: 'manageFee', name: '企业管理费'},
     {type: 'profit', name: '利润'},
     {type: 'risk', name: '风险费'},
     // 模拟用户新增
@@ -89,5 +89,22 @@ let calcFees = {
                 };
             }
         }
+    },
+    // CSL,2017.08.28
+    feeTypeToName: function (type) {
+        for (let ft of feeType) {
+            if (ft.type === type) {
+                return ft.name;
+            };
+        };
+    },
+
+    feeNameToType: function (name) {
+        for (let ft of feeType) {
+            if (ft.name === name) {
+                return ft.type;
+            };
+        };
+        return '';
     }
 }

+ 8 - 6
web/building_saas/main/js/models/calc_program.js

@@ -207,7 +207,7 @@ let calcTemplates = [
             {
                 ID: "1",
                 code: "1",
-                name: "基价直接工程费2",
+                name: "基价直接工程费",
                 fieldName: "baseDirect",
                 dispExpr: "F2+F5+F6+F10",
                 expression: "@('2') + @('5') + @('6') + @('10')",
@@ -401,7 +401,7 @@ let calcTemplates = [
             {
                 ID: "1",
                 code: "1",
-                name: "基价直接工程费3",
+                name: "基价直接工程费",
                 fieldName: "baseDirect",
                 dispExpr: "F2+F5+F6+F10",
                 expression: "@('2') + @('5') + @('6') + @('10')",
@@ -3599,13 +3599,15 @@ class CalcProgram {
     };
 
     compileAllTemps(){
-       for (let calcTemplate of calcTemplates){
-           this.calc.compile(calcTemplate, calcFeeRates, calcLabourCoes);
-       };
+        this.calc.compilePublics(calcFeeRates, calcLabourCoes, feeType);
+        for (let calcTemplate of calcTemplates){
+            this.calc.compileTemplate(calcTemplate);
+        };
     };
 
     compile(calcTemplate){
-       this.calc.compile(calcTemplate, calcFeeRates, calcLabourCoes);
+        this.calc.compilePublics(calcFeeRates, calcLabourCoes, feeType);
+        this.calc.compileTemplate(calcTemplate);
     };
 
     calculate(treeNode){

+ 3 - 3
web/building_saas/main/js/views/calc_program_manage.js

@@ -26,7 +26,7 @@ let rationPM = {
             {headerName:"计算基数",headerWidth:180,dataCode:"dispExpr", dataType: "String"},
             {headerName:"基数说明",headerWidth:300,dataCode:"statement", dataType: "String"},
             {headerName:"费率",headerWidth:80,dataCode:"feeRate", dataType: "Number"},
-            {headerName:"字段名称",headerWidth:180,dataCode:"fieldName", dataType: "String"},
+            {headerName:"字段名称",headerWidth:100,dataCode:"displayFieldName", dataType: "String", hAlign: "center"},
             {headerName:"备注",headerWidth:100,dataCode:"memo", dataType: "String"}
         ],
         view:{
@@ -38,8 +38,8 @@ let rationPM = {
     buildSheet: function (){
         let me = this;
         me.datas = calcTemplates;
-        me.mainSpread = sheetCommonObj.buildSheet($('#mainSpread')[0], me.mainSetting, 16);
-        me.detailSpread = sheetCommonObj.buildSheet($('#detailSpread')[0], me.detailSetting, 18);
+        me.mainSpread = sheetCommonObj.buildSheet($('#mainSpread')[0], me.mainSetting, me.datas.length);
+        me.detailSpread = sheetCommonObj.buildSheet($('#detailSpread')[0], me.detailSetting, me.datas[0].calcItems.length);
 
         //var coeType = new GC.Spread.Sheets.CellTypes.ComboBox();
         //coeType.items(["单个","定额","人工","材料","机械"]);

+ 0 - 1
web/building_saas/main/js/views/calc_program_view.js

@@ -238,7 +238,6 @@ let calcProgramObj = {
         if (treeNode.sourceType === projectObj.project.Ration.getSourceType()) {
             projectObj.project.calcProgram.calculate(treeNode);
             me.datas = me.treeNode.data.calcTemplate.calcItems;
-            //me.sheet.setRowCount(me.datas.length);
             sheetCommonObj.initSheet(me.sheet, me.setting, me.datas.length);
             sheetCommonObj.showData(me.sheet, me.setting, me.datas);
         }