Browse Source

代码优化。

Chenshilong 7 years ago
parent
commit
633447ecef

+ 22 - 44
web/building_saas/main/js/models/calc_program.js

@@ -119,61 +119,37 @@ class CalcProgram {
         };
     };
 
-    gatherRationFeeTypes(treeNode){
+    gatherFeeTypes(treeNode, gatherType){
         let me = this;
         let rst = [];
+
         if (treeNode.sourceType === this.project.Bills.getSourceType()) {
             me.initFees(treeNode);
 
-            let rations = this.project.Ration.getRationsByNode(treeNode);
-            for (let ft of feeType) {
-                let ftObj = {};
-                ftObj.type = ft.type;
-                ftObj.name = ft.name;
-                let uf = 0, tf = 0, tuf = 0, ttf = 0;
-                for (let ration of rations) {
-                    if (ration.feesIndex && ration.feesIndex[ft.type]) {
-                        uf = (uf + parseFloat(ration.feesIndex[ft.type].unitFee)).toDecimal(me.digitDefault);
-                        tf = (tf + parseFloat(ration.feesIndex[ft.type].totalFee)).toDecimal(me.digitDefault);
-                        tuf = (tuf + parseFloat(ration.feesIndex[ft.type].tenderUnitFee)).toDecimal(me.digitDefault);
-                        ttf = (ttf + parseFloat(ration.feesIndex[ft.type].tenderTotalFee)).toDecimal(me.digitDefault);
-                    };
-                };
-                ftObj.unitFee = uf.toDecimal(me.digit);
-                ftObj.totalFee = tf.toDecimal(me.digit);
-                ftObj.tenderUnitFee = tuf.toDecimal(me.digit);
-                ftObj.tenderTotalFee = ttf.toDecimal(me.digit);
-
-                me.checkFee(treeNode, ftObj);
-
-                rst.push(ftObj);
+            let objsArr = [];
+            if (gatherType == CP_GatherType.rations){
+                objsArr = this.project.Ration.getRationsByNode(treeNode);
+            }else if (gatherType == CP_GatherType.bills){
+                objsArr = treeNode.children;
             };
 
-            if (treeNode.changed) {
-                me.saveAndCalcParents(treeNode);
-                delete treeNode.changed;
-            };
-        };
-        return rst;
-    };
-
-    gatherBillFeeTypes(treeNode){
-        let me = this;
-        let rst = [];
-        if (treeNode.sourceType === this.project.Bills.getSourceType()) {
-            me.initFees(treeNode);
-
             for (let ft of feeType) {
                 let ftObj = {};
                 ftObj.type = ft.type;
                 ftObj.name = ft.name;
                 let uf = 0, tf = 0, tuf = 0, ttf = 0;
-                for (let node of treeNode.children) {
-                    if (node.data.feesIndex && node.data.feesIndex[ft.type]) {
-                        uf = (uf + parseFloat(node.data.feesIndex[ft.type].unitFee)).toDecimal(me.digitDefault);
-                        tf = (tf + parseFloat(node.data.feesIndex[ft.type].totalFee)).toDecimal(me.digitDefault);
-                        tuf = (tuf + parseFloat(node.data.feesIndex[ft.type].tenderUnitFee)).toDecimal(me.digitDefault);
-                        ttf = (ttf + parseFloat(node.data.feesIndex[ft.type].tenderTotalFee)).toDecimal(me.digitDefault);
+                for (let item of objsArr) {
+                    let data = {};
+                    if (gatherType == CP_GatherType.rations){
+                        data = item;
+                    }else if (gatherType == CP_GatherType.bills){
+                        data = item.data;
+                    };
+                    if (data.feesIndex && data.feesIndex[ft.type]) {
+                        uf = (uf + parseFloat(data.feesIndex[ft.type].unitFee)).toDecimal(me.digitDefault);
+                        tf = (tf + parseFloat(data.feesIndex[ft.type].totalFee)).toDecimal(me.digitDefault);
+                        tuf = (tuf + parseFloat(data.feesIndex[ft.type].tenderUnitFee)).toDecimal(me.digitDefault);
+                        ttf = (ttf + parseFloat(data.feesIndex[ft.type].tenderTotalFee)).toDecimal(me.digitDefault);
                     };
                 };
                 ftObj.unitFee = uf.toDecimal(me.digit);
@@ -182,6 +158,7 @@ class CalcProgram {
                 ftObj.tenderTotalFee = ttf.toDecimal(me.digit);
 
                 me.checkFee(treeNode, ftObj);
+
                 rst.push(ftObj);
             };
 
@@ -190,6 +167,7 @@ class CalcProgram {
                 delete treeNode.changed;
             };
         };
+
         return rst;
-    }
+    };
 }

+ 5 - 0
web/building_saas/main/js/models/main_consts.js

@@ -33,4 +33,9 @@ const CP_Col_Width = {          // 多处计算程序界面的列宽统一设置
     memo: 110,
     unitFee: 90,
     totalFee: 90
+};
+
+const CP_GatherType = {
+    rations: 'rations',
+    bills: 'bills'
 };

+ 2 - 2
web/building_saas/main/js/views/calc_program_view.js

@@ -255,7 +255,7 @@ let calcProgramObj = {
                     projectObj.project.calcProgram.calculate(treeNode);
                     me.datas = me.treeNode.data.calcTemplate.calcItems;
                 }else{                  // 前三种计算模式下的叶子清单:汇总定额的计算程序的费用类别
-                    me.datas = projectObj.project.calcProgram.gatherRationFeeTypes(treeNode);
+                    me.datas = projectObj.project.calcProgram.gatherFeeTypes(treeNode, CP_GatherType.rations);
                 };
             }else if (childrenType == 'volumePrice'){
                 me.datas = [];
@@ -264,7 +264,7 @@ let calcProgramObj = {
             };
         }
         else if (isBill){    // 父清单:汇总子清单的费用类别
-            me.datas = projectObj.project.calcProgram.gatherBillFeeTypes(treeNode);
+            me.datas = projectObj.project.calcProgram.gatherFeeTypes(treeNode, CP_GatherType.bills);
         };
 
         sheetCommonObj.initSheet(me.sheet, me.setting, me.datas.length);