ProductB2CKindTree.js 3.3 KB

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