Pārlūkot izejas kodu

清单,增量计算

MaiXinRong 7 gadi atpakaļ
vecāks
revīzija
d13876d59a

+ 32 - 14
web/building_saas/main/js/calc/bills_calc.js

@@ -237,9 +237,8 @@ let baseCalcField = [
 class BillsCalcHelper {
     constructor (project, calcFlag) {
         this.project = project;
-        this.InitFields(this.project.calcFields);
+        this.InitFields(project.calcFields);
     };
-
     getBillsGLjs (node) {
         let rations = this.project.Ration.getBillsSortRation(node.source.getID());
         let gljs = this.project.ration_glj.getGatherGljArrByRations(rations);
@@ -248,7 +247,7 @@ class BillsCalcHelper {
         }
         return gljs;
     };
-    calcRationLeaf (node, fields) {
+    calcRationLeaf (node, fields, isIncre) {
         nodeCalcObj.node = node;
         nodeCalcObj.digit = this.project.Decimal.unitFee;
         calcFees.checkFields(node.data, fields);
@@ -277,47 +276,50 @@ class BillsCalcHelper {
                 default:
                     node.data.feesIndex[field.type].unitFee = 0;
             }
+            let value = 0;
             switch (field.totalFeeFlag) {
                 case sumTotalFeeFlag:
-                    node.data.feesIndex[field.type].totalFee = nodeCalcObj.sumTotalFee().toDecimal(this.project.Decimal.common.totalFee);
+                    value = nodeCalcObj.sumTotalFee().toDecimal(this.project.Decimal.common.totalFee);
                     break;
                 case totalFeeFlag:
-                    node.data.feesIndex[field.type].totalFee = nodeCalcObj.totalFee().toDecimal(this.project.Decimal.common.totalFee);
+                    value = nodeCalcObj.totalFee().toDecimal(this.project.Decimal.common.totalFee);
                     break;
                 default:
-                    node.data.feesIndex[field.type].totalFee = 0;
+                    value = 0;
             }
+            this.setTotalFee(node, field, value, isIncre);
         }
     };
-    calcVolumePriceLeaf (node, fields) {
+    calcVolumePriceLeaf (node, fields, isIncre) {
         let total = 0;
         for (let child of this.node.children) {
             total += this.getFee(child.data, 'feesIndex.common.totalFee');
         }
     };
-    calcParent (node, fields) {
+    calcParent (node, fields, isIncre) {
         nodeCalcObj.node = node;
         calcFees.checkFields(node.data, fields);
         for (let field of fields) {
             nodeCalcObj.field = field;
-            node.data.feesIndex[field.type].totalFee = nodeCalcObj.sumTotalFee().toDecimal(this.project.Decimal.common.totalFee);
+            let value = nodeCalcObj.sumTotalFee().toDecimal(this.project.Decimal.common.totalFee);
+            this.setTotalFee(node, field, value, isIncre);
         }
     };
-    calcNode(node) {
+    calcNode(node, isIncre) {
         if (node.source.children.length > 0) {
-            this.calcParent(node, this.project.calcFields);
+            this.calcParent(node, this.project.calcFields, isIncre);
         } else {
             if (node.children.length > 0) {
                 if (node.firstChild().sourceType === this.project.Ration.getSourceType()) {
-                    this.calcRationLeaf(node, this.project.calcFields);
+                    this.calcRationLeaf(node, this.project.calcFields, isIncre);
                 } else {
-                    this.calcVolumePriceLeaf(node, this.project.calcFields);
+                    this.calcVolumePriceLeaf(node, this.project.calcFields, isIncre);
                 }
             } else {
 
             }
         }
-    }
+    };
     calcNodes (nodes) {
         for (let node of nodes) {
             if (node.sourceType !== this.project.Bills.getSourceType()) {
@@ -329,6 +331,22 @@ class BillsCalcHelper {
             this.calcNode(node);
         }
     };
+    updateParent (parent, field, Incre) {
+        if (parent && parent.sourceType === this.project.Bills.getSourceType()) {
+            calcFees.checkFields(parent.data, [field]);
+            parent.data.feesIndex[field.type].totalFee = (parent.data.feesIndex[field.type].totalFee + Incre).toDecimal(this.project.Decimal.common.totalFee);
+            this.updateParent(parent.parent, field, Incre);
+        }
+    };
+    setTotalFee (node, field, value, isIncre) {
+        if (isIncre) {
+            let incre = value - node.data.feesIndex[field.type].totalFee;
+            node.data.feesIndex[field.type].totalFee = value;
+            this.updateParent(node.parent, field, incre);
+        } else {
+            node.data.feesIndex[field.type].totalFee = value;
+        }
+    };
     converseCalc (node) {
         if (node && node.sourceType === this.project.Bills.getSourceType()) {
             this.calcNode(node);

+ 24 - 2
web/building_saas/main/js/models/bills.js

@@ -32,6 +32,20 @@ var Bills = {
                     updateDatas.push(updateData);
                 });
                 return updateDatas;
+            },
+            formatBillsUpdateData: function (data) {
+                let uData = JSON.parse(JSON.stringify(data));
+                delete uData.feesIndex;
+                delete uData.flagsIndex;
+                if (uData.fees) {
+                    for (let fee of uData.fees) {
+                        fee.unitFee = fee.unitFee.toFixed(2);
+                        fee.totalFee = fee.totalFee.toFixed(2);
+                        fee.tenderUnitFee = fee.tenderUnitFee.toFixed(2);
+                        fee.tenderTotalFee = fee.tenderTotalFee.toFixed(2);
+                    }
+                }
+                return uData;
             }
         };
 
@@ -254,10 +268,18 @@ var Bills = {
                         fee.tenderTotalFee = fee.tenderTotalFee.toFixed(2);
                     }
                 }
-                updateData.push({'updateType': 'ut_update', 'updateData': data});
+                updateData.push({'updateType': 'ut_update', 'updateData': uData});
             }
             this.project.pushNow('updateAllBills', this.getSourceType(), updateData);
-        }
+        };
+
+        bills.prototype.updateNodes = function (nodes) {
+            let updateData = [];
+            for (let node of nodes) {
+                updateData.push({'updateType': 'ut_update', 'updateData': tools.formatBillsUpdateData(node.data)});
+            }
+            this.project.pushNow('updateBills', this.getSourceType(), updateData);
+        };
 
         return new bills(project);
     }

+ 5 - 2
web/building_saas/main/js/views/project_view.js

@@ -306,7 +306,9 @@ var projectObj = {
                 "spr2":'--------',
                 "calculateAll_RationContent": {
                     name: '造价计算',
-                    callback: projectObj.calculateAll
+                    callback: function () {
+                        projectObj.calculateAll();
+                    }
                 }
             }
         });
@@ -314,13 +316,14 @@ var projectObj = {
     // 计算node及node的所有父项
     converseCalculateBills: function (node) {
         let calc = new BillsCalcHelper(this.project);
-        calc.converseCalc(node, this.project.calcFields);
+        calc.calcNode(node, true);
         let cur = node, nodes = [];
         while (cur) {
             nodes.push(cur);
             cur = cur.parent;
         }
         this.mainController.refreshTreeNode(nodes, false);
+        this.project.Bills.updateNodes(nodes);
         calc = null;
     },
     // 计算全部清单