浏览代码

项目管理页面,默认收起至建设项目层

zeweizhong 6 年之前
父节点
当前提交
96d01adeec

+ 1 - 1
public/common_util.js

@@ -12,7 +12,7 @@
     if (typeof module !== 'undefined') {
         module.exports = factory();
     } else {
-        window._commonUtil = factory();
+        window.commonUtil = factory();
     }
 })(() => {
     function isDef(val) {

+ 1 - 1
web/building_saas/main/js/views/zmhs_view.js

@@ -611,7 +611,7 @@ let zmhs_obj = {
         zmhs_obj.changeStableValue(changeData);
     },
     changeStableValue: function (data) {
-        const isValid = data.every(cell => _commonUtil.isDef(cell.value) && sheetCommonObj.checkData(cell.col, this.stableSetting, cell.value));
+        const isValid = data.every(cell => commonUtil.isDef(cell.value) && sheetCommonObj.checkData(cell.col, this.stableSetting, cell.value));
         if (!isValid) {
             this.showDatas();
             alert('输入的数据类型不对,请重新输入!');

+ 52 - 18
web/building_saas/pm/js/pm_newMain.js

@@ -1096,6 +1096,9 @@ const projTreeObj = {
                     me.setFileSelectButton(i,j,nodes[i],sheet,setting);
                 }
                 sheet.getCell(i, 1,GC.Spread.Sheets.SheetArea.viewport).locked(true);
+                if (typeof nodes[i].visible !== 'undefined') {
+                    sheet.setRowVisible(nodes[i].serialNo(), nodes[i].visible);
+                }
             }
         };
         me.renderSheetFuc(sheet, fuc);
@@ -1426,30 +1429,41 @@ const projTreeObj = {
         let refreshNodes = [];
         me.tree.removeNode(select);//删除旧节点
         let newNode  = addNewNodes(select, parent, next);
+        // todo refreshNodeVisible
+        /*if (parent && parent.data && !parent.expanded) {
+        }*/
         if(oldProject){
             refreshNodes = refreshNodes.concat(me.calEngineeringCost(oldProject));
             refreshNodes = refreshNodes.concat(me.calEngineeringCost(parent));
         }
-        // projTreeObj.remove(sheet, fromRow, rCout);
-
-       // me.renderSheetFuc(sheet, function () {
+        me.renderSheetFuc(sheet, function () {
             sheet.deleteRows(fromRow, rCout);
             sheet.addRows(newNode.serialNo(),rCout);
             let oldSelection = sheet.getSelections()[0];
             me.initSelection({row: newNode.serialNo(), rowCount: oldSelection.rowCount}, oldSelection,sheet);
             sheet.setSelection(newNode.serialNo(),oldSelection.col,oldSelection.rowCount,oldSelection.colCount);
-            let children = newNode.getAllChildren();
-            children.push(newNode);
-            for(let c of children){
-                sheet.getCell(c.serialNo(), 0).cellType(me.getTreeNodeCell(me.tree));
-                // me.refreshNodeData(c);
-            }
-            refreshNodes = refreshNodes.concat(children);
+            const newNodes = [newNode];
+            const children = newNode.getAllChildren();
+            newNodes.push(...children);
+            for(let node of newNodes){
+                const row = node.serialNo();
+                sheet.getCell(row, 0).cellType(me.getTreeNodeCell(me.tree));
+                const visible = node.visible;
+                sheet.setRowVisible(row, visible);
+            }
+            refreshNodes = refreshNodes.concat(newNodes);
             me.refreshNodeData(refreshNodes);
-       // });
+        });
 
         function addNewNodes(node,parent,next) {
-            let newNode = me.tree.addNodeData(node.data, parent, next);
+            const nodeState = {};
+            if (typeof node.expanded !== 'undefined') {
+                nodeState.expanded = node.expanded;
+            }
+            if (typeof node.visible !== 'undefined') {
+                nodeState.visible = node.visible;
+            }
+            let newNode = me.tree.addNodeData(node.data, parent, next, nodeState);
             for(let c of node.children){
                 addNewNodes(c,newNode,null);
             }
@@ -2069,6 +2083,25 @@ function prepareInitialTimer() {
     return {outer, inner};
 }
 
+// 初始化节点可见性,默认收起至建设项目层
+function initNodesVisibility(sheet, nodes, visible) {
+    function recurSetVisible(nodes, visible) {
+        nodes.forEach(node => {
+            node.visible = visible;
+            if (node.children) {
+                recurSetVisible(node.children, visible);
+            }
+        });
+    }
+    nodes.forEach(node => {
+        const isProject = node.data.projType === projectType.project;
+        if (isProject) {
+            node.expanded = visible;
+            recurSetVisible(node.children, visible);
+        }
+    });
+}
+
 function initProjects(callback) {
     GetAllProjectData(function (datas) {
         //设置项目类别
@@ -2082,15 +2115,16 @@ function initProjects(callback) {
             projTreeObj.tree = pmTree.createNew(projTreeObj.setting, datas);
             projTreeObj.tree.selected = projTreeObj.tree.items[0];
             projTreeObj.workBook = projTreeObj.buildSheet(projTreeObj.workBook,'projSpread',projTreeObj.setting);
-            projTreeObj.workBook.getSheet(0).frozenColumnCount(2);
-            projTreeObj.workBook.getSheet(0).name('projectSheet');
+            const sheet = projTreeObj.workBook.getSheet(0);
+            sheet.frozenColumnCount(2);
+            sheet.name('projectSheet');
             sheetCommonObj.spreadDefaultStyle(projTreeObj.workBook);
             projTreeObj.sumEngineeringCost();
-            projTreeObj.showTreeData(projTreeObj.tree.items, projTreeObj.setting, projTreeObj.workBook.getActiveSheet());
+            initNodesVisibility(sheet, projTreeObj.tree.items, false);
+            projTreeObj.showTreeData(projTreeObj.tree.items, projTreeObj.setting, sheet);
             //初始选择
-            let initSel = projTreeObj.workBook.getSheet(0).getSelections()[0] ? projTreeObj.workBook.getSheet(0).getSelections()[0] : {row: 0, rowCount: 1};
-            projTreeObj.initSelection(initSel,null,projTreeObj.workBook.getActiveSheet());
-           // $.bootstrapLoading.end();
+            const initSel = sheet.getSelections()[0] ? sheet.getSelections()[0] : {row: 0, rowCount: 1};
+            projTreeObj.initSelection(initSel, null, sheet);
             autoFlashHeight();
             projTreeObj.workBook.refresh();
             if (callback) {

+ 8 - 3
web/building_saas/pm/js/pm_tree.js

@@ -16,7 +16,7 @@ const pmTree = {
         }
 
         var Node = (function () {
-            function Node(tree, data) {
+            function Node(tree, data, nodeState = null) {
                 this.parent = null;
                 this.nextSibling = null;
                 this.children = [];
@@ -29,6 +29,11 @@ const pmTree = {
 
                 this.row = null;
                 this.expandBtn = null;
+                if (nodeState) {
+                    for (const attr in nodeState) {
+                        this[attr] = nodeState[attr];
+                    }
+                }
             }
 
             Node.prototype.firstChild = function() {
@@ -313,11 +318,11 @@ const pmTree = {
                 sortTreeItems(this);
             };
 
-            Tree.prototype.addNodeData = function (data, parent, nextSibling) {
+            Tree.prototype.addNodeData = function (data, parent, nextSibling, nodeState = null) {
                 var node = null;
                 var pNode = parent ? parent : this._root;
                 if (!nextSibling || (nextSibling.parent === pNode && pNode.childIndex(nextSibling) > -1)) {
-                    node = new Node(this, data);
+                    node = new Node(this, data, nodeState);
                     this.maxNodeId(data[this.setting.tree.id]);
                     this.move(node, pNode, nextSibling);
                 }