Ext.define('erp.view.hr.emplmana.HrOrgStrTree',{ extend: 'Ext.tree.Panel', alias: 'widget.hrOrgStrTree', id: 'tree-panel', border : false, enableDD : false, split: true, width : '100%', height: '100%', expandedNodes: [], title: "员工组织架构", toggleCollapse: function() { if (this.collapsed) { this.expand(this.animCollapse); } else { this.title = '员工组织架构'; this.collapse(this.collapseDirection, this.animCollapse); } return this; }, rootVisible: false, singleExpand: true, containerScroll : true, collapsible : true, autoScroll: true, store: Ext.create('Ext.data.TreeStore', { root : { text: 'root', id: 'root', expanded: true } }), tools: [{ id: 'refresh', type: 'refresh', tooltip: '刷新', handler: function(){ } },{ id: 'search', type: 'search', tooltip: '查找', handler: function(){ } }], bodyStyle:'background-color:#f1f1f1;', initComponent : function(){ this.getTreeRootNode(0); this.callParent(arguments); }, getTreeRootNode: function(parentId){ Ext.Ajax.request({//拿到tree数据 url : basePath + 'hr/employee/getAllHrOrgsTree.action', params: { parentId: parentId }, callback : function(options,success,response){ var res = new Ext.decode(response.responseText); if(res.tree){ var tree = res.tree; Ext.getCmp('tree-panel').store.setRootNode({ text: 'root', id: 'root', expanded: true, children: tree }); } else if(res.exceptionInfo){ showError(res.exceptionInfo); } } }); }, openCloseFun: function(){ var o = Ext.getCmp("open"); var c = Ext.getCmp("close"); var tree = Ext.getCmp('tree-panel'); if(o.hidden==false&&c.hidden==true){ tree.expandAll(); o.hide(); c.show(); }else{ tree.collapseAll(); o.show(); c.hide(); } }, listeners: {//滚动条有时候没反应,添加此监听器 scrollershow: function(scroller) { if (scroller && scroller.scrollEl) { scroller.clearManagedListeners(); scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller); } }, }, /** * 找到所有已展开的节点,包括当前被选中的节点 * @param record 当前被选中的节点 */ getExpandedItems: function(record){ var me = this; me.getRecordParents(record); if(record.isLeaf()){ me.expandedNodes.push(record); } }, getRecordParents: function(record, parent){ var me = this; if(!parent){ parent = me.store.tree.root; me.expandedNodes = []; } if(parent.childNodes.length > 0){ Ext.each(parent.childNodes, function(){ if(this.isExpanded()){ me.expandedNodes.push(this); if(this.childNodes.length > 0){ me.getRecordParents(record, this); } } }); } }, getExpandItem: function(root){ var me = this; if(!root){ root = this.store.tree.root; } var node = null; if(root.childNodes.length > 0){ Ext.each(root.childNodes, function(){ if(this.isExpanded()){ node = this; if(this.childNodes.length > 0){ var n = me.getExpandItem(this); node = n == null ? node : n; } } }); } return node; } });