HrOrgStrTree.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. Ext.define('erp.view.hr.employee.HrOrgStrTree',{
  2. extend: 'Ext.tree.Panel',
  3. alias: 'widget.hrOrgStrTree',
  4. id: 'tree-panel',
  5. border : false,
  6. enableDD : false,
  7. split: true,
  8. width : '100%',
  9. height: '100%',
  10. expandedNodes: [],
  11. title: "<font color=#a1a1a1; size=2>员工组织架构</font>",
  12. toggleCollapse: function() {
  13. if (this.collapsed) {
  14. this.expand(this.animCollapse);
  15. } else {
  16. this.title = '员工组织架构';
  17. this.collapse(this.collapseDirection, this.animCollapse);
  18. }
  19. return this;
  20. },
  21. rootVisible: false,
  22. singleExpand: true,
  23. containerScroll : true,
  24. collapsible : true,
  25. autoScroll: true,
  26. store: Ext.create('Ext.data.TreeStore', {
  27. root : {
  28. text: 'root',
  29. id: 'root',
  30. expanded: true
  31. }
  32. }),
  33. dockedItems: [{
  34. xtype: 'toolbar',
  35. items: [{
  36. text: '新增',
  37. handler: function(){
  38. win = Ext.create('Ext.Window', {
  39. id: 'vendoruu-win',
  40. title: '组织新增人员',
  41. height: 200,
  42. width: 400,
  43. defaults: {
  44. anchor: '100%'
  45. },
  46. items: [{
  47. xtype: 'textfield',
  48. fieldLabel: '员工编号',
  49. name:'em_code',
  50. value: ''
  51. },{
  52. xtype: 'textfield',
  53. fieldLabel: '员工姓名',
  54. name:'em_name',
  55. value: ''
  56. },{
  57. xtype: 'dbfindtrigger',
  58. fieldLabel: '组织名称',
  59. name:'em_defaultorname',
  60. value: ''
  61. },{
  62. xtype: 'textfield',
  63. fieldLabel: '组织ID',
  64. name:'em_defaultorid',
  65. value: ''
  66. }],
  67. closeAction: 'hide',
  68. buttonAlign: 'center',
  69. layout: {
  70. type: 'vbox',
  71. align: 'center'
  72. },
  73. buttons: [{
  74. text:'保存',
  75. cls: 'x-btn-blue',
  76. handler: function(btn) {
  77. var em_id = Ext.getCmp('em_id').value;
  78. if(em_id==null){
  79. showError("员工ID不能为空!");
  80. return;
  81. }
  82. var em_defaultorid = Ext.getCmp('em_defaultorid').value;
  83. var em_defaultorname = Ext.getCmp('em_defaultorname').value;
  84. if(em_defaultorname==null){
  85. showError("组织名称不能为空!");
  86. return;
  87. }
  88. Ext.Ajax.request({
  89. url : basePath + 'hr/HrOrgStrTree/updateEmployee.action',
  90. params: {
  91. em_id:em_id,
  92. hrOrgid:em_defaultorid,
  93. hrOrgName:em_defaultorname
  94. },
  95. callback : function(options,success,response){
  96. var res = new Ext.decode(response.responseText);
  97. if(res.success){
  98. alert("该人员已成功被组织添加!");
  99. } else if(res.exceptionInfo){
  100. showError(res.exceptionInfo);
  101. }
  102. }
  103. });
  104. }
  105. }, {
  106. text: $I18N.common.button.erpCloseButton,
  107. cls: 'x-btn-blue',
  108. handler: function(btn) {
  109. btn.ownerCt.ownerCt.hide();
  110. }
  111. }]
  112. });
  113. win.show();
  114. }
  115. }, {
  116. text: '更新',
  117. handler: function(){
  118. var check = Ext.getCmp('tree-panel').getSelectionModel();
  119. var emid = check.lastSelected.data.id;
  120. win = Ext.create('Ext.Window', {
  121. id: 'vendoruu-win',
  122. title: '更新人员组织',
  123. height: 200,
  124. width: 400,
  125. defaults: {
  126. anchor: '100%'
  127. },
  128. items: [{
  129. xtype: 'textfield',
  130. fieldLabel: '员工ID',
  131. name:'em_id',
  132. value: check.lastSelected.data.id
  133. },{
  134. xtype: 'textfield',
  135. fieldLabel: '员工姓名',
  136. name:'em_name',
  137. value: check.lastSelected.data.text
  138. },{
  139. xtype: 'dbfindtrigger',
  140. fieldLabel: '组织名称',
  141. name:'em_defaultorname',
  142. value: ''
  143. },{
  144. xtype: 'textfield',
  145. fieldLabel: '组织ID',
  146. name:'em_defaultorid',
  147. value: ''
  148. }],
  149. closeAction: 'hide',
  150. buttonAlign: 'center',
  151. layout: {
  152. type: 'vbox',
  153. align: 'center'
  154. },
  155. buttons: [{
  156. text:'更新',
  157. cls: 'x-btn-blue',
  158. handler: function(btn) {
  159. var em_id = Ext.getCmp('em_id').value;
  160. if(em_id==null){
  161. showError("员工ID不能为空!");
  162. return;
  163. }
  164. var em_defaultorid = Ext.getCmp('em_defaultorid').value;
  165. var em_defaultorname = Ext.getCmp('em_defaultorname').value;
  166. if(em_defaultorname==null){
  167. showError("组织名称不能为空!");
  168. return;
  169. }
  170. Ext.Ajax.request({
  171. url : basePath + 'hr/HrOrgStrTree/updateEmployee.action',
  172. params: {
  173. em_id:em_id,
  174. hrOrgid:em_defaultorid,
  175. hrOrgName:em_defaultorname
  176. },
  177. callback : function(options,success,response){
  178. var res = new Ext.decode(response.responseText);
  179. if(res.success){
  180. alert("人员组织更新成功!");
  181. } else if(res.exceptionInfo){
  182. showError(res.exceptionInfo);
  183. }
  184. }
  185. });
  186. }
  187. }, {
  188. text: $I18N.common.button.erpCloseButton,
  189. cls: 'x-btn-blue',
  190. handler: function(btn) {
  191. btn.ownerCt.ownerCt.hide();
  192. }
  193. }]
  194. });
  195. /*var formCondition = "em_id="+emid;
  196. var win = new Ext.window.Window({
  197. id : 'win',
  198. title: '更新人员组织',
  199. height: "90%",
  200. width: "70%",
  201. maximizable : true,
  202. buttonAlign : 'center',
  203. layout : 'anchor',
  204. items: [{
  205. tag : 'iframe',
  206. frame : true,
  207. anchor : '100% 100%',
  208. layout : 'fit',
  209. html : '<iframe id="iframe_' + emid+ '" src="' + basePath +
  210. 'jsps/hr/employee/updateHrorg.jsp?formCondition='+formCondition+'" height="100%" width="100%" frameborder="0" scrolling="yes"></iframe>'
  211. }]
  212. });*/
  213. win.show();
  214. }},{
  215. text: '删除',
  216. handler: function(){
  217. warnMsg("确定要从组织中删除该人员吗?", function(btn){
  218. if(btn == 'yes'){
  219. var check = Ext.getCmp('tree-panel').getSelectionModel();
  220. var emid = check.lastSelected.data.id;
  221. Ext.Ajax.request({
  222. url : basePath + 'hr/HrOrgStrTree/deleteEmployee.action',
  223. params: {
  224. id: emid
  225. },
  226. method : 'post',
  227. callback : function(options,success,response){
  228. me.FormUtil.getActiveTab().setLoading(false);
  229. var localJson = new Ext.decode(response.responseText);
  230. if(localJson.exceptionInfo){
  231. showError(localJson.exceptionInfo);
  232. }
  233. if(localJson.success){
  234. alert("该人员已经成功从组织中删除!");
  235. }
  236. }
  237. });
  238. }
  239. });
  240. }
  241. }]
  242. }],
  243. tools: [{
  244. id: 'refresh',
  245. type: 'refresh',
  246. tooltip: '刷新',
  247. handler: function(){
  248. }
  249. },{
  250. id: 'search',
  251. type: 'search',
  252. tooltip: '查找',
  253. handler: function(){
  254. }
  255. }],
  256. bodyStyle:'background-color:#f1f1f1;',
  257. initComponent : function(){
  258. this.getTreeRootNode(0);
  259. this.callParent(arguments);
  260. },
  261. getTreeRootNode: function(parentid){
  262. Ext.Ajax.request({//拿到tree数据
  263. url : basePath + 'hr/employee/getAllHrOrgsTree.action',
  264. params: {
  265. //parentid: parentid
  266. },
  267. callback : function(options,success,response){
  268. var res = new Ext.decode(response.responseText);
  269. if(res.tree){
  270. var tree = res.tree;
  271. // console.log(Ext.getCmp('tree-panel'));
  272. Ext.getCmp('tree-panel').store.setRootNode({
  273. text: 'root',
  274. id: 'root',
  275. expanded: true,
  276. children: tree
  277. });
  278. } else if(res.exceptionInfo){
  279. showError(res.exceptionInfo);
  280. }
  281. Ext.getCmp('tree-panel').listenerNode();
  282. }
  283. });
  284. },
  285. listenerNode: function(node){
  286. var me = this;
  287. var Node = node || Ext.getCmp('tree-panel').store.tree.root;
  288. Ext.each(Node,function(e){
  289. e.on('beforecollapse',function(p,o){
  290. });
  291. if(e.data['leaf'] == false){
  292. me.listenerNode(e);
  293. }
  294. });
  295. },
  296. openCloseFun: function(){
  297. var o = Ext.getCmp("open");
  298. var c = Ext.getCmp("close");
  299. var tree = Ext.getCmp('tree-panel');
  300. if(o.hidden==false&&c.hidden==true){
  301. tree.expandAll();
  302. o.hide();
  303. c.show();
  304. }else{
  305. tree.collapseAll();
  306. o.show();
  307. c.hide();
  308. }
  309. },
  310. listeners: {//滚动条有时候没反应,添加此监听器
  311. scrollershow: function(scroller) {
  312. if (scroller && scroller.scrollEl) {
  313. scroller.clearManagedListeners();
  314. scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
  315. }
  316. },
  317. },
  318. /**
  319. * 找到所有已展开的节点,包括当前被选中的节点
  320. * @param record 当前被选中的节点
  321. */
  322. getExpandedItems: function(record){
  323. var me = this;
  324. me.getRecordParents(record);
  325. if(record.isLeaf()){
  326. me.expandedNodes.push(record);
  327. }
  328. },
  329. getRecordParents: function(record, parent){
  330. var me = this;
  331. if(!parent){
  332. parent = me.store.tree.root;
  333. me.expandedNodes = [];
  334. }
  335. if(parent.childNodes.length > 0){
  336. Ext.each(parent.childNodes, function(){
  337. if(this.isExpanded()){
  338. me.expandedNodes.push(this);
  339. if(this.childNodes.length > 0){
  340. me.getRecordParents(record, this);
  341. }
  342. }
  343. });
  344. }
  345. },
  346. getExpandItem: function(root){
  347. var me = this;
  348. if(!root){
  349. root = this.store.tree.root;
  350. }
  351. var node = null;
  352. if(root.childNodes.length > 0){
  353. Ext.each(root.childNodes, function(){
  354. if(this.isExpanded()){
  355. node = this;
  356. if(this.childNodes.length > 0){
  357. var n = me.getExpandItem(this);
  358. node = n == null ? node : n;
  359. }
  360. }
  361. });
  362. }
  363. return node;
  364. }
  365. });