OrgTreePanel.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. Ext.define('erp.view.oa.doc.OrgTreePanel', {
  2. extend: 'Ext.tree.Panel',
  3. xtype: 'erpOrgTreePanel',
  4. id:'orgtree',
  5. lines:true,
  6. rootVisible: false,
  7. containerScroll : true,
  8. autoScroll: false,
  9. useArrows: true,
  10. split:true,
  11. closeAction:'destroy',
  12. border : false,
  13. enableDD : false,
  14. FormUtil:Ext.create('erp.util.FormUtil'),
  15. store: Ext.create('Ext.data.TreeStore', {
  16. root : {
  17. text: 'root',
  18. id: 'root',
  19. expanded: true
  20. }
  21. }),
  22. initComponent : function(){
  23. this.callParent(arguments);
  24. this.getTreeRootNode(0);
  25. },
  26. listeners:{
  27. itemmousedown: function(selModel, record){
  28. var tree=selModel.ownerCt;
  29. if(! tree.itemselector) tree.itemselector=Ext.getCmp('itemselector-field');
  30. var data=new Array();
  31. data.push({
  32. text:'<font color="#D52B2B">[组织]</font>'+record.data.text,
  33. value:'org#'+record.data.id
  34. });
  35. Ext.Array.each(record.data.otherInfo,function(item){
  36. data.push({
  37. text:'<font color="#C4C43C">[岗位]</font>'+item.jo_name,
  38. value:'job#'+item.jo_id
  39. });
  40. });
  41. Ext.Array.each(record.data.data,function(item){
  42. data.push({
  43. text:/*'<font color="#4DB34D">[个人]</font>'+*/item.em_name,
  44. value:'employee#'+item.em_id
  45. });
  46. });
  47. tree.itemselector.fromField.store.loadData(data);
  48. var parentId=record.data.id;
  49. if (record.isExpanded() && record.childNodes.length > 0) { //是根节点,且已展开
  50. record.collapse(true, true); //收拢
  51. } else { //未展开
  52. //看是否加载了其children
  53. if (record.childNodes.length == 0) {
  54. //从后台加载
  55. tree.setLoading(true, tree.body);
  56. Ext.Ajax.request({ //拿到tree数据
  57. url: basePath + 'hr/employee/getHrOrgsTreeAndEmployees.action',
  58. params: {
  59. parentId: parentId
  60. },
  61. callback: function(options, success, response) {
  62. tree.setLoading(false);
  63. var res = new Ext.decode(response.responseText);
  64. if (res.tree) {
  65. record.appendChild(res.tree);
  66. record.expand(false, true); //展开
  67. } else if (res.exceptionInfo) {
  68. showError(res.exceptionInfo);
  69. }
  70. }
  71. });
  72. } else {
  73. record.expand(false, true); //展开
  74. }
  75. }
  76. }
  77. },
  78. getTreeRootNode: function(parentId){
  79. treepanel=this;
  80. treepanel.setLoading(true);
  81. treepanel.store.removeAll(true);
  82. Ext.Ajax.request({//拿到tree数据
  83. url : basePath + 'hr/employee/getHrOrgsTreeAndEmployees.action',
  84. params: {
  85. parentId: parentId
  86. },
  87. callback : function(options,success,response){
  88. var res = new Ext.decode(response.responseText);
  89. treepanel.setLoading(false);
  90. if(res.tree){
  91. var tree = res.tree;
  92. treepanel.store.setRootNode({
  93. text: 'root',
  94. id: 'root',
  95. expanded: true,
  96. children: tree
  97. });
  98. } else if(res.exceptionInfo){
  99. showError(res.exceptionInfo);
  100. }
  101. }
  102. });
  103. },
  104. });