ProductKindTree.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. case 'FeePlease!YZSYSQ':
  72. url = 'oa/fee/getContractTypeTree.action';break;
  73. }
  74. return url;
  75. },
  76. openCloseFun: function(){
  77. var o = Ext.getCmp("open");
  78. var c = Ext.getCmp("close");
  79. var tree = Ext.getCmp('tree-panel');
  80. if(o.hidden==false&&c.hidden==true){
  81. tree.expandAll();
  82. o.hide();
  83. c.show();
  84. }else{
  85. tree.collapseAll();
  86. o.show();
  87. c.hide();
  88. }
  89. },
  90. listeners: {//滚动条有时候没反应,添加此监听器
  91. scrollershow: function(scroller) {
  92. if (scroller && scroller.scrollEl) {
  93. scroller.clearManagedListeners();
  94. scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
  95. }
  96. }
  97. },
  98. /**
  99. * 找到所有已展开的节点,包括当前被选中的节点
  100. * @param record 当前被选中的节点
  101. */
  102. getExpandedItems: function(record){
  103. var me = this;
  104. me.getRecordParents(record);
  105. if(record.isLeaf()){
  106. me.expandedNodes.push(record);
  107. }
  108. },
  109. getRecordParents: function(record, parent){
  110. var me = this;
  111. if(!parent){
  112. parent = me.store.tree.root;
  113. me.expandedNodes = [];
  114. }
  115. if(parent.childNodes.length > 0){
  116. Ext.each(parent.childNodes, function(){
  117. if(this.isExpanded()){
  118. me.expandedNodes.push(this);
  119. if(this.childNodes.length > 0){
  120. me.getRecordParents(record, this);
  121. }
  122. }
  123. });
  124. }
  125. },
  126. getExpandItem: function(root){
  127. var me = this;
  128. if(!root){
  129. root = this.store.tree.root;
  130. }
  131. var node = null;
  132. if(root.childNodes.length > 0){
  133. Ext.each(root.childNodes, function(){
  134. if(this.isExpanded()){
  135. node = this;
  136. if(this.childNodes.length > 0){
  137. var n = me.getExpandItem(this);
  138. node = n == null ? node : n;
  139. }
  140. }
  141. });
  142. }
  143. return node;
  144. }
  145. });