HrOrgStrTree.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. Ext.define('erp.view.hr.emplmana.HrOrgStrTree',{
  2. extend: 'Ext.tree.Panel',
  3. alias: 'widget.hrOrgStrTree',
  4. id: 'tree-panel',
  5. border : false,
  6. enableDD : false,
  7. split: true,
  8. width : '100%',
  9. height: '100%',
  10. expandedNodes: [],
  11. title: "<font color=#a1a1a1; size=2>员工组织架构</font>",
  12. toggleCollapse: function() {
  13. if (this.collapsed) {
  14. this.expand(this.animCollapse);
  15. } else {
  16. this.title = '员工组织架构';
  17. this.collapse(this.collapseDirection, this.animCollapse);
  18. }
  19. return this;
  20. },
  21. rootVisible: false,
  22. singleExpand: true,
  23. containerScroll : true,
  24. collapsible : true,
  25. autoScroll: true,
  26. store: Ext.create('Ext.data.TreeStore', {
  27. root : {
  28. text: 'root',
  29. id: 'root',
  30. expanded: true
  31. }
  32. }),
  33. tools: [{
  34. id: 'refresh',
  35. type: 'refresh',
  36. tooltip: '刷新',
  37. handler: function(){
  38. }
  39. },{
  40. id: 'search',
  41. type: 'search',
  42. tooltip: '查找',
  43. handler: function(){
  44. }
  45. }],
  46. bodyStyle:'background-color:#f1f1f1;',
  47. initComponent : function(){
  48. this.getTreeRootNode(0);
  49. this.callParent(arguments);
  50. },
  51. getTreeRootNode: function(parentId){
  52. Ext.Ajax.request({//拿到tree数据
  53. url : basePath + 'hr/employee/getAllHrOrgsTree.action',
  54. params: {
  55. parentId: parentId
  56. },
  57. callback : function(options,success,response){
  58. var res = new Ext.decode(response.responseText);
  59. if(res.tree){
  60. var tree = res.tree;
  61. Ext.getCmp('tree-panel').store.setRootNode({
  62. text: 'root',
  63. id: 'root',
  64. expanded: true,
  65. children: tree
  66. });
  67. } else if(res.exceptionInfo){
  68. showError(res.exceptionInfo);
  69. }
  70. }
  71. });
  72. },
  73. openCloseFun: function(){
  74. var o = Ext.getCmp("open");
  75. var c = Ext.getCmp("close");
  76. var tree = Ext.getCmp('tree-panel');
  77. if(o.hidden==false&&c.hidden==true){
  78. tree.expandAll();
  79. o.hide();
  80. c.show();
  81. }else{
  82. tree.collapseAll();
  83. o.show();
  84. c.hide();
  85. }
  86. },
  87. listeners: {//滚动条有时候没反应,添加此监听器
  88. scrollershow: function(scroller) {
  89. if (scroller && scroller.scrollEl) {
  90. scroller.clearManagedListeners();
  91. scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
  92. }
  93. },
  94. },
  95. /**
  96. * 找到所有已展开的节点,包括当前被选中的节点
  97. * @param record 当前被选中的节点
  98. */
  99. getExpandedItems: function(record){
  100. var me = this;
  101. me.getRecordParents(record);
  102. if(record.isLeaf()){
  103. me.expandedNodes.push(record);
  104. }
  105. },
  106. getRecordParents: function(record, parent){
  107. var me = this;
  108. if(!parent){
  109. parent = me.store.tree.root;
  110. me.expandedNodes = [];
  111. }
  112. if(parent.childNodes.length > 0){
  113. Ext.each(parent.childNodes, function(){
  114. if(this.isExpanded()){
  115. me.expandedNodes.push(this);
  116. if(this.childNodes.length > 0){
  117. me.getRecordParents(record, this);
  118. }
  119. }
  120. });
  121. }
  122. },
  123. getExpandItem: function(root){
  124. var me = this;
  125. if(!root){
  126. root = this.store.tree.root;
  127. }
  128. var node = null;
  129. if(root.childNodes.length > 0){
  130. Ext.each(root.childNodes, function(){
  131. if(this.isExpanded()){
  132. node = this;
  133. if(this.childNodes.length > 0){
  134. var n = me.getExpandItem(this);
  135. node = n == null ? node : n;
  136. }
  137. }
  138. });
  139. }
  140. return node;
  141. }
  142. });