Ver código fonte

台账,前端子节点也应计算

MaiXinRong 6 anos atrás
pai
commit
d345f9468e
1 arquivos alterados com 26 adições e 8 exclusões
  1. 26 8
      app/public/js/path_tree.js

+ 26 - 8
app/public/js/path_tree.js

@@ -790,6 +790,24 @@ const createNewPathTree = function (type, setting) {
             }
         }
 
+        _getReCalcNodes(reCalcNodes, nodes) {
+            for (const node of nodes) {
+                const parent = this.getParent(node);
+                if (parent) {
+                    const paths = this.getFullPathNodes(parent.full_path);
+                    for (const p of paths) {
+                        if (reCalcNodes.indexOf(p) === -1) {
+                            reCalcNodes.push(p);
+                        }
+                    }
+                }
+                // 最底层项目节,也需要计算
+                //if (this.getItems(node.ledger_id) && node.children.length > 0) {
+                    reCalcNodes.push(node);
+                //}
+            }
+        }
+
         /**
          * 因为提交其他数据,引起的树结构数据更新,调用该方法
          *
@@ -797,26 +815,26 @@ const createNewPathTree = function (type, setting) {
          * @param {function} callback - 界面刷新
          */
         loadPostData(data, callback) {
-            const result = {}, parents = [];
+            const result = {}, reCalcNodes = [];
             if (data.update) {
                 result.update = this._updateData(data.update);
-                this._getNodesParents(parents, result.update);
+                this._getReCalcNodes(reCalcNodes, result.update);
             }
             if (data.create) {
                 result.create = this._loadData(data.create);
-                this._getNodesParents(parents, result.create);
+                this._getReCalcNodes(reCalcNodes, result.create);
             }
             if (data.delete) {
                 result.delete = this._freeData(data.delete);
-                this._getNodesParents(parents, result.delete);
+                this._getReCalcNodes(reCalcNodes, result.delete);
             }
-            parents.sort((a, b) => {
+            reCalcNodes.sort((a, b) => {
                 return b.level - a.level;
             });
-            for (const parent of parents) {
-                treeCalc.calculateNode(this, parent, this.setting.calcFields, this.setting.calcFun);
+            for (const node of reCalcNodes) {
+                treeCalc.calculateNode(this, node, this.setting.calcFields, this.setting.calcFun);
             }
-            result.update = result.update ? result.update.concat(parents) : parents;
+            result.update = result.update ? result.update.concat(reCalcNodes) : reCalcNodes;
             callback(result);
         }