Kaynağa Gözat

1、叶子清单挂定额、项目属性取费方式为清单单价时,清单取自己的计算程序ID读定额的计算程序计算。
2、定额计算后数据存储优化,减少数据传输,存储时机优化。
3、没有指定费用类别的计算规则的单价、合价,无需绑定到定额或清单入库存储。
4、计算程序结构调整。

Chenshilong 7 yıl önce
ebeveyn
işleme
f00f32742e

+ 35 - 25
public/calc_util.js

@@ -231,9 +231,17 @@ class Calculation {
     // 先编译公用的基础数据
     compilePublics(feeRates, labourCoes, feeTypes, calcBases){
         let me = this;
+        me.compiledFeeRates = {};
+        me.compiledLabourCoes = {};
+        me.compiledTemplates = {};
+        me.compiledFeeTypes = {};
+        me.compiledFeeTypeNames = [];
+        me.compiledCalcBases = {};
+        me.saveForReports = [];
+        me.changed = false;
+
         let private_compile_feeRateFile = function() {
             if (feeRates) {
-                me.compiledFeeRates = {};
                 for (let rate of feeRates) {
                     me.compiledFeeRates["feeRate_" + rate.ID] = rate;
                 }
@@ -241,7 +249,6 @@ class Calculation {
         };
         let private_compile_labourCoeFile = function() {
             if (labourCoes) {
-                me.compiledLabourCoes = {};
                 for (let coe of labourCoes) {
                     me.compiledLabourCoes["LabourCoe_" + coe.ID] = coe;
                 }
@@ -249,8 +256,6 @@ class Calculation {
         };
         let private_compile_feeType = function() {
             if (feeTypes) {
-                me.compiledFeeTypes = {};
-                me.compiledFeeTypeNames = [];
                 for (let ft of feeTypes) {
                     me.compiledFeeTypes[ft.type] = ft.name;
                     me.compiledFeeTypes[ft.name] = ft.type;    // 中文预编译,可靠性有待验证
@@ -260,7 +265,6 @@ class Calculation {
         };
         let private_compile_calcBase = function() {
             if (calcBases) {
-                me.compiledCalcBases = {};
                 for (let cb of calcBases) {
                     me.compiledCalcBases[cb.dispName] = cb;         // 中文预编译,可靠性有待验证
                 }
@@ -271,8 +275,6 @@ class Calculation {
         private_compile_labourCoeFile();
         private_compile_feeType();
         private_compile_calcBase();
-        me.compiledTemplates = {};
-        me.saveForReports = [];
     };
 
     compileTemplate(template){
@@ -382,8 +384,6 @@ class Calculation {
         };
     };
 
-
-
     calculate($treeNode){
         let me = this;
         let templateID = $treeNode.data.programID;
@@ -400,6 +400,7 @@ class Calculation {
             if (!$treeNode.data.fees) {
                 $treeNode.data.fees = [];
                 $treeNode.data.feesIndex = {};
+                me.changed = true;
             };
 
             for (let idx of template.compiledSeq) {
@@ -415,23 +416,32 @@ class Calculation {
 
                 // 费用同步到定额
                 // 引入小麦的字段检测后,快速切换定额出现计算卡顿现象,过多的循环造成。这里把她的代码拆出来,减少微循环。
-                if (!$treeNode.data.feesIndex[calcItem.fieldName]){
-                    let fee = {
-                        'fieldName': calcItem.fieldName,
-                        'unitFee': calcItem.unitFee,
-                        'totalFee': calcItem.totalFee,
-                        'tenderUnitFee': 0,
-                        'tenderTotalFee': 0
-                    };
-                    $treeNode.data.fees.push(fee);
-                    $treeNode.data.feesIndex[calcItem.fieldName] = fee;
-                }
-                else{
-                    $treeNode.data.feesIndex[calcItem.fieldName].unitFee = calcItem.unitFee;
-                    $treeNode.data.feesIndex[calcItem.fieldName].totalFee = calcItem.totalFee;
-                }
-            }
+                if (calcItem.fieldName != '') {
+                    if (!$treeNode.data.feesIndex[calcItem.fieldName]){
+                        let fee = {
+                            'fieldName': calcItem.fieldName,
+                            'unitFee': calcItem.unitFee,
+                            'totalFee': calcItem.totalFee,
+                            'tenderUnitFee': 0,
+                            'tenderTotalFee': 0
+                        };
+                        $treeNode.data.fees.push(fee);
+                        $treeNode.data.feesIndex[calcItem.fieldName] = fee;
+                        me.changed = true;
+                    }
+                    else{
+                        if ($treeNode.data.feesIndex[calcItem.fieldName].unitFee != calcItem.unitFee){
+                            $treeNode.data.feesIndex[calcItem.fieldName].unitFee = calcItem.unitFee;
+                            me.changed = true;
+                        };
 
+                        if ($treeNode.data.feesIndex[calcItem.fieldName].totalFee != calcItem.totalFee){
+                            $treeNode.data.feesIndex[calcItem.fieldName].totalFee = calcItem.totalFee;
+                            me.changed = true;
+                        };
+                    }
+                };
+            };
         }
     }
 };

+ 16 - 1
web/building_saas/main/js/models/calc_program.js

@@ -59,6 +59,21 @@ class CalcProgram {
         };
 
         this.calc.calculate(treeNode);
-        projectObj.mainController.refreshTreeNode([treeNode]);
+
+        // 存储、刷新本结点、所有父结点
+        if (this.calc.changed){
+            let data = {ID: treeNode.data.ID, projectID: projectObj.project.ID(), fees: treeNode.data.fees};
+            let newDta = {'updateType': 'ut_update', 'updateData': data};
+            let newDataArr = [];
+            newDataArr.push(newDta);
+            projectObj.project.pushNow('', treeNode.sourceType, newDataArr);
+            projectObj.mainController.refreshTreeNode([treeNode]);
+
+            if (treeNode.parent) {
+                projectObj.converseCalculateBills(treeNode.parent);
+            }
+
+            this.calc.changed = false;
+        };
     }
 }

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

@@ -236,9 +236,6 @@ let calcProgramObj = {
 
         if (isRation || (isLeafBill && isBillPriceCalc)) {
             projectObj.project.calcProgram.calculate(treeNode);
-            if (treeNode.parent) {
-                projectObj.converseCalculateBills(treeNode.parent);
-            }
             me.datas = me.treeNode.data.calcTemplate.calcItems;
             sheetCommonObj.initSheet(me.sheet, me.setting, me.datas.length);
             sheetCommonObj.showData(me.sheet, me.setting, me.datas);