VendorKindTree.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. Ext.define('erp.view.scm.purchase.VendorKindTree',{
  2. extend: 'Ext.tree.Panel',
  3. alias: 'widget.vendkindtree',
  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. Ext.Ajax.request({//拿到tree数据
  39. url : basePath + 'scm/purchase/getVendorKindTree.action',
  40. params: {
  41. parentid: parentid
  42. },
  43. callback : function(options,success,response){
  44. var res = new Ext.decode(response.responseText);
  45. if(res.tree){
  46. var tree = res.tree;
  47. Ext.getCmp('tree-panel').store.setRootNode({
  48. text: 'root',
  49. id: 'root',
  50. expanded: true,
  51. children: tree
  52. });
  53. } else if(res.exceptionInfo){
  54. showError(res.exceptionInfo);
  55. }
  56. }
  57. });
  58. },
  59. openCloseFun: function(){
  60. var o = Ext.getCmp("open");
  61. var c = Ext.getCmp("close");
  62. var tree = Ext.getCmp('tree-panel');
  63. if(o.hidden==false&&c.hidden==true){
  64. tree.expandAll();
  65. o.hide();
  66. c.show();
  67. }else{
  68. tree.collapseAll();
  69. o.show();
  70. c.hide();
  71. }
  72. },
  73. listeners: {//滚动条有时候没反应,添加此监听器
  74. scrollershow: function(scroller) {
  75. if (scroller && scroller.scrollEl) {
  76. scroller.clearManagedListeners();
  77. scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
  78. }
  79. }
  80. },
  81. /**
  82. * 找到所有已展开的节点,包括当前被选中的节点
  83. * @param record 当前被选中的节点
  84. */
  85. getExpandedItems: function(record){
  86. var me = this;
  87. me.getRecordParents(record);
  88. if(record.isLeaf()){
  89. me.expandedNodes.push(record);
  90. }
  91. },
  92. getRecordParents: function(record, parent){
  93. var me = this;
  94. if(!parent){
  95. parent = me.store.tree.root;
  96. me.expandedNodes = [];
  97. }
  98. if(parent.childNodes.length > 0){
  99. Ext.each(parent.childNodes, function(){
  100. if(this.isExpanded()){
  101. me.expandedNodes.push(this);
  102. if(this.childNodes.length > 0){
  103. me.getRecordParents(record, this);
  104. }
  105. }
  106. });
  107. }
  108. },
  109. getExpandItem: function(root){
  110. var me = this;
  111. if(!root){
  112. root = this.store.tree.root;
  113. }
  114. var node = null;
  115. if(root.childNodes.length > 0){
  116. Ext.each(root.childNodes, function(){
  117. if(this.isExpanded()){
  118. node = this;
  119. if(this.childNodes.length > 0){
  120. var n = me.getExpandItem(this);
  121. node = n == null ? node : n;
  122. }
  123. }
  124. });
  125. }
  126. return node;
  127. }
  128. });