فهرست منبع

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

zeweizhong 6 سال پیش
والد
کامیت
20cf185259
3فایلهای تغییر یافته به همراه95 افزوده شده و 18 حذف شده
  1. 41 0
      public/common_util.js
  2. 46 15
      web/building_saas/pm/js/pm_newMain.js
  3. 8 3
      web/building_saas/pm/js/pm_tree.js

+ 41 - 0
public/common_util.js

@@ -0,0 +1,41 @@
+/**
+ * Created by CSL on 2017-06-06.
+ * public functions.
+ */
+
+function deleteEmptyObject(arr) {
+    function isEmptyObject(e) {
+        var t;
+        for (t in e)
+            return !1;
+        return !0
+    };
+
+    for (var i = 0; i < arr.length; i++) {
+        if (isEmptyObject(arr[i])) {
+            arr.splice(i, 1);
+            i = i - 1;
+        };
+    };
+};
+
+((factory) => {
+    if (typeof module !== 'undefined') {
+        module.exports = factory();
+    } else {
+        window.commonUtil = factory();
+    }
+})(() => {
+    function isDef(val) {
+        return typeof val !== 'undefined' && val !== null;
+    }
+
+    function isEmptyVal(val) {
+        return val === null || val === undefined || val === '';
+    }
+
+    return {
+        isDef,
+        isEmptyVal
+    };
+});

+ 46 - 15
web/building_saas/pm/js/pm_newMain.js

@@ -1153,6 +1153,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);
@@ -1490,25 +1493,34 @@ const projTreeObj = {
             refreshNodes = refreshNodes.concat(me.calEngineeringCost(oldProject));
             refreshNodes = refreshNodes.concat(me.calEngineeringCost(parent));
         }
-        // projTreeObj.remove(sheet, fromRow, rCout);
-
         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));
-            }
-            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);
             }
@@ -2719,6 +2731,24 @@ function getWorkBookWidth(){
     return workBookWidth = $(window).width() - $('.pm-side').width() - 90;
 }
 
+// 初始化节点可见性,默认收起至建设项目层
+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) {
         //设置工程专业
@@ -2732,15 +2762,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);
                 }