浏览代码

feat: 费率递归计算父级费率值。

zhangweicheng 4 年之前
父节点
当前提交
60ebc637ea
共有 2 个文件被更改,包括 58 次插入23 次删除
  1. 32 2
      modules/fee_rates/facade/fee_rates_facade.js
  2. 26 21
      web/building_saas/main/js/views/fee_rate_view.js

+ 32 - 2
modules/fee_rates/facade/fee_rates_facade.js

@@ -297,7 +297,34 @@ async function getAllSubRatesMap(feeRateID){
 }
 
 function sumParentRate(IDMap,childrenMap,decimal){
-    for(let ParentID in  childrenMap){
+
+    for(let ID in IDMap){
+        if(childrenMap[ID]) continue;//找出最底层的叶子节点
+        sum(ID);
+    }
+    
+    function sum(subID){
+        let subRate = IDMap[subID];
+        if(subRate.name === '雨季施工增加费'){
+            console.log('a');
+        }
+        let parent = IDMap[subRate.ParentID];
+        if(parent &&parent.sum === true&& childrenMap[parent.ID]){
+            let childrenList = childrenMap[subRate.ParentID];
+            let total = 0;
+            for(let c of childrenList){
+                let tem = c.rate?c.rate:0;
+                tem = scMathUtil.roundForObj(tem,decimal);
+                total = scMathUtil.roundForObj(tem + total,6);
+            }
+            total = scMathUtil.roundForObj(total,decimal);
+            parent.rate = total;
+            sum(parent.ID);
+        }
+
+    }
+
+  /*   for(let ParentID in  childrenMap){
         if(IDMap[ParentID] && IDMap[ParentID].sum !== true) continue;
         let childrenList = childrenMap[ParentID];
         let total = 0;
@@ -308,7 +335,10 @@ function sumParentRate(IDMap,childrenMap,decimal){
         }
         total = scMathUtil.roundForObj(total,decimal);
         if(IDMap[ParentID])IDMap[ParentID].rate = total;
-    }
+    } */
+
+
+     
 }
 
 function setRatesByMap(newFeeRate,subMap,decimal){

+ 26 - 21
web/building_saas/main/js/views/fee_rate_view.js

@@ -498,30 +498,35 @@ var feeRateObject={
         }
         me.updateFeerateWhenCellsChange(changeCells);
     },
-    sumParentRate:function (rateID,value,updateDatas) {
+    sumParentRate:function (subRateID,subValue,updateDatas) {
         let feeRate = projectObj.project.FeeRate;
-        let rate = feeRate.getFeeRateByID(rateID);
-        let parent = feeRate.getFeeRateByID(rate.ParentID);
-        if(parent && parent.sum == true){
-            let suRates = feeRate.getChildrenByID(parent.ID);
-            let total = 0;
-            for(let r of suRates) {
-                let tem = r.rate ? r.rate:0;
-                tem = scMathUtil.roundForObj(tem,getDecimal("feeRate"));
-                if (rateID == r.ID){
-                    tem = value;
+        sum(subRateID,subValue);
+
+        function sum(rateID,value){
+            let rate = feeRate.getFeeRateByID(rateID);
+            let parent = feeRate.getFeeRateByID(rate.ParentID);
+            if(parent && parent.sum == true){
+                let suRates = feeRate.getChildrenByID(parent.ID);
+                let total = 0;
+                for(let r of suRates) {
+                    let tem = r.rate ? r.rate:0;
+                    tem = scMathUtil.roundForObj(tem,getDecimal("feeRate"));
+                    if (rateID == r.ID){
+                        tem = value;
+                    }else {
+                        let u = _.find(updateDatas,{"rateID":r.ID})//看是不是更新的过程中包含了汇总的数据
+                        if(u && gljUtil.isDef(u.doc.rate)) tem = u.doc.rate;
+                    }
+                    total = scMathUtil.roundForObj(tem + total,getDecimal('process'))
+                }
+                total = scMathUtil.roundForObj(total,getDecimal("feeRate"));
+                let tp =  _.find(updateDatas,{"rateID":parent.ID});//如果父节点也在更新列表中
+                if(tp){
+                    tp.doc.rate = total
                 }else {
-                    let u = _.find(updateDatas,{"rateID":r.ID})//看是不是更新的过程中包含了汇总的数据
-                    if(u && gljUtil.isDef(u.doc.rate)) tem = u.doc.rate;
+                    updateDatas.push({rateID:parent.ID,doc:{rate:total}});
                 }
-                total = scMathUtil.roundForObj(tem + total,getDecimal('process'))
-            }
-            total = scMathUtil.roundForObj(total,getDecimal("feeRate"));
-            let tp =  _.find(updateDatas,{"rateID":parent.ID});//如果父节点也在更新列表中
-            if(tp){
-                tp.doc.rate = total
-            }else {
-                updateDatas.push({rateID:parent.ID,doc:{rate:total}});
+                sum(parent.ID,total);
             }
         }