AccountRegisterTree.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. Ext.define('erp.view.fa.gs.AccountRegisterTree',{
  2. extend: 'Ext.tree.Panel',
  3. alias: 'widget.accountregistertree',
  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 url = this.getUrl();
  39. Ext.Ajax.request({//拿到tree数据
  40. url : basePath + url,
  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. Ext.getCmp('tree-panel').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. getUrl: function(){
  61. var url = 'fa/gs/getCategoryBankTree.action';
  62. return url;
  63. },
  64. openCloseFun: function(){
  65. var o = Ext.getCmp("open");
  66. var c = Ext.getCmp("close");
  67. var tree = Ext.getCmp('tree-panel');
  68. if(o.hidden==false&&c.hidden==true){
  69. tree.expandAll();
  70. o.hide();
  71. c.show();
  72. }else{
  73. tree.collapseAll();
  74. o.show();
  75. c.hide();
  76. }
  77. },
  78. listeners: {//滚动条有时候没反应,添加此监听器
  79. scrollershow: function(scroller) {
  80. if (scroller && scroller.scrollEl) {
  81. scroller.clearManagedListeners();
  82. scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
  83. }
  84. }
  85. },
  86. /**
  87. * 找到所有已展开的节点,包括当前被选中的节点
  88. * @param record 当前被选中的节点
  89. */
  90. getExpandedItems: function(record){
  91. var me = this;
  92. me.getRecordParents(record);
  93. if(record.isLeaf()){
  94. me.expandedNodes.push(record);
  95. }
  96. },
  97. getRecordParents: function(record, parent){
  98. var me = this;
  99. if(!parent){
  100. parent = me.store.tree.root;
  101. me.expandedNodes = [];
  102. }
  103. if(parent.childNodes.length > 0){
  104. Ext.each(parent.childNodes, function(){
  105. if(this.isExpanded()){
  106. me.expandedNodes.push(this);
  107. if(this.childNodes.length > 0){
  108. me.getRecordParents(record, this);
  109. }
  110. }
  111. });
  112. }
  113. },
  114. getExpandItem: function(root){
  115. var me = this;
  116. if(!root){
  117. root = this.store.tree.root;
  118. }
  119. var node = null;
  120. if(root.childNodes.length > 0){
  121. Ext.each(root.childNodes, function(){
  122. if(this.isExpanded()){
  123. node = this;
  124. if(this.childNodes.length > 0){
  125. var n = me.getExpandItem(this);
  126. node = n == null ? node : n;
  127. }
  128. }
  129. });
  130. }
  131. return node;
  132. }
  133. });