AddrBookTree.js 3.1 KB

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