ProductKindTree.js 3.5 KB

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