BOMStepTree.js 3.5 KB

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