EmployeeGrid.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. Ext.define('erp.view.sys.hr.EmployeeGrid',{
  2. extend: 'Ext.grid.Panel',
  3. //store:Ext.data.StoreMgr.lookup('employeeStore'),
  4. alias: 'widget.employeegrid',
  5. id:'employeegrid',
  6. selModel: new Ext.selection.CheckboxModel(),
  7. //title:'人事资料<span style="color:gray">(所有)</span>',
  8. columnLines: true,
  9. viewConfig: {
  10. stripeRows: true,
  11. enableTextSelection: true
  12. },
  13. forceFit:true,
  14. dockedItems: [{
  15. xtype: 'toolbar',
  16. ui: 'footer',
  17. items: [{
  18. xtype:'tbtext',
  19. text:'<span style="font-weight:bold;" >人事资料</span>'
  20. },{ xtype: 'tbseparator' },{
  21. text:'添加',
  22. itemId: 'addemployee',
  23. tooltip:'添加新记录',
  24. iconCls:'btn-add'
  25. },'-',{
  26. text:'保存',
  27. itemId:'saveemployee',
  28. tooltip:'保存',
  29. iconCls:'btn-save'
  30. },'-',{
  31. text:'删除',
  32. itemId:'deleteemployee',
  33. tooltip:'删除',
  34. iconCls:'btn-delete'
  35. },'-',{
  36. text:'帮助',
  37. iconCls:'btn-help',
  38. tooltip:'帮助简介'
  39. },{
  40. xtype:'tbtext',
  41. text:'<div style="color:gray;">带'+required+'为必填项</div>'
  42. }]
  43. }],
  44. columns:[{
  45. dataIndex:'em_id',
  46. width:0,
  47. text:'ID'
  48. },{
  49. dataIndex:'em_code',
  50. width:100,
  51. text:'员工编号',
  52. renderer:columnRequired,
  53. editor: {
  54. xtype: 'textfield',
  55. selectOnFocus: true,
  56. allowOnlyWhitespace: false,
  57. allowBlank:false
  58. }
  59. },{
  60. dataIndex:'em_name',
  61. width:120,
  62. text:'员工名称',
  63. renderer:columnRequired,
  64. editor: {
  65. xtype: 'textfield',
  66. selectOnFocus: true,
  67. allowOnlyWhitespace: false,
  68. allowBlank:false
  69. }
  70. },{
  71. dataIndex:'em_sex',
  72. width:50,
  73. text:'性别',
  74. editor: {
  75. xtype: 'combo',
  76. selectOnFocus: true,
  77. allowOnlyWhitespace: false,
  78. allowBlank:false,
  79. store: Ext.create('Ext.data.Store', {
  80. fields: ['display', 'value'],
  81. data : [
  82. {"display":"男", "value":"男"},
  83. {"display":"女", "value":"女"}
  84. ]
  85. }),
  86. queryMode: 'local',
  87. displayField: 'display',
  88. valueField: 'value',
  89. listConfig :{
  90. minWidth:40
  91. }
  92. }
  93. },{
  94. dataIndex:'em_mobile',
  95. width:120,
  96. text:'手机号',
  97. renderer:columnRequired,
  98. editor:{
  99. xtype:'numberfield',
  100. regex:new RegExp('^[1][358][0-9]{9}'),
  101. regexText:'请填写11位有效手机号码'
  102. }
  103. },{
  104. dataIndex:'em_email',
  105. width:200,
  106. text:'邮箱',
  107. renderer:columnRequired,
  108. editor: {
  109. allowBlank: false,
  110. vtype: 'email'
  111. }
  112. },{
  113. dataIndex:'em_position',
  114. width:120,
  115. text:'岗位',
  116. renderer:columnRequired,
  117. editor:{
  118. allowBlank:false,
  119. xtype:'dbfindtrigger',
  120. dbfind:'Job|jo_name'
  121. }
  122. },{
  123. dataIndex:'em_defaulthsid',
  124. width:0,
  125. text:'岗位ID'
  126. },{
  127. dataIndex:'em_defaulthsname',
  128. width:0,
  129. text:'岗位名称'
  130. },{
  131. dataIndex:'em_defaultorname',
  132. width:150,
  133. text:'所属组织'
  134. },{
  135. dataIndex:'em_defaultorid',
  136. width:0,
  137. text:'所属组织ID'
  138. },{
  139. dataIndex:'em_depart',
  140. width:120,
  141. text:'财务核算部门',
  142. flex:1
  143. }/*,{
  144. xtype:'actioncolumn',
  145. width:45,
  146. text :'操作',
  147. items:[{
  148. iconCls:'btn-delete',
  149. tooltip:'删除',
  150. width:75,
  151. handler:function(grid, rowIndex, colIndex) {
  152. Ext.Msg.confirm('删除数据?', '确定要删除当前选中行(行号:'+(rowIndex+1)+')?',
  153. function(choice) {
  154. if(choice === 'yes') {
  155. var record = grid.getStore().getAt(rowIndex),gridpanel=grid.ownerCt;
  156. gridpanel.removeDetail(gridpanel,record);
  157. }
  158. });
  159. }
  160. }]
  161. }*/],
  162. dbfinds:[{dbGridField:'jo_id',field:'em_defaulthsid'},
  163. {dbGridField:'jo_name',field:'em_position'},
  164. {dbGridField:'jo_name',field:'em_defaulthsname'},
  165. {dbGridField:'jo_orgid',field:'em_defaultorid'},
  166. {dbGridField:'jo_orgname',field:'em_defaultorname'},
  167. {dbGridField:'or_department',field:'em_depart'}],
  168. store:Ext.create('Ext.data.Store',{
  169. fields:[{name:'em_id',type:'number'},
  170. {name:'em_code',type:'string'},
  171. {name:'em_name',type:'string'},
  172. {name:'em_sex',type:'string'},
  173. {name:'em_mobile',type:'string'},
  174. {name:'em_email',type:'string'},
  175. {name:'em_position',type:'string'},
  176. {name:'em_defaulthsid',type:'int'},
  177. {name:'em_defaulthsname',type:'string'},
  178. {name:'em_defaultorname',type:'string'},
  179. {name:'em_defaultorid',type:'int'},
  180. {name:'em_depart',type:'string'}],
  181. proxy: {
  182. type: 'ajax',
  183. url: basePath+'/hr/employee/getEmployees.action',
  184. api: {
  185. create: basePath+'hr/employee/saveEmployees.action',
  186. update: basePath+'hr/employee/updateEmployees.action',
  187. },
  188. writer : {
  189. type : 'json',
  190. root : 'jsonData',
  191. encode : true,
  192. nameProperty:'data',
  193. allowSingle : false
  194. },
  195. reader: {
  196. type: 'json',
  197. root: 'employees'
  198. }
  199. },
  200. autoLoad: true
  201. }),
  202. initComponent : function(){
  203. var me=this;
  204. me.plugins = [me.cellEditingPlugin = Ext.create('Ext.grid.plugin.CellEditing')];
  205. this.callParent(arguments);
  206. },
  207. loadNewStore: function(grid, param){
  208. var me = this;
  209. param=param||grid.params;
  210. grid.setLoading(true);//loading...
  211. Ext.Ajax.request({//拿到grid的columns
  212. url : basePath + "common/loadNewGridStore.action",
  213. params: param,
  214. method : 'post',
  215. callback : function(options,success,response){
  216. grid.setLoading(false);
  217. var res = new Ext.decode(response.responseText);
  218. if(res.exceptionInfo){
  219. showError(res.exceptionInfo);return;
  220. }
  221. var data = res.data;
  222. if(!data || data.length == 0){
  223. grid.store.removeAll();
  224. me.add10EmptyItems(grid);
  225. } else {
  226. grid.store.loadData(data);
  227. }
  228. //自定义event
  229. grid.addEvents({
  230. storeloaded: true
  231. });
  232. grid.fireEvent('storeloaded', grid, data);
  233. }
  234. });
  235. },
  236. removeDetail:function(grid,record){
  237. grid.setLoading(true);
  238. Ext.Ajax.request({
  239. url : basePath + 'hr/employee/deleteJob.action',
  240. params: {
  241. id: record.get('jo_id')
  242. },
  243. method : 'post',
  244. callback : function(options,success,response){
  245. grid.setLoading(false);
  246. var localJson = new Ext.decode(response.responseText);
  247. if(localJson.exceptionInfo){
  248. showError(localJson.exceptionInfo);return;
  249. }
  250. if(localJson.success){
  251. showResult('提示','删除成功!');
  252. var orgTree = Ext.getCmp('orgtree'),
  253. selectionModel=orgTree.getSelectionModel(),
  254. selectedList = selectionModel.getSelection()[0];
  255. grid.getStore().load({params:{
  256. orgid:selectedList.get('or_id')
  257. }});
  258. }
  259. }
  260. });
  261. },
  262. setColumns:function(columns){
  263. Ext.Array.each(columns,function(column){
  264. if(column.xtype=='yncolumn'){
  265. column.xtype='checkcolumn';
  266. column.editor= {
  267. xtype: 'checkbox',
  268. cls: 'x-grid-checkheader-editor'
  269. };
  270. }
  271. });
  272. return columns;
  273. },
  274. DetailUpdateSuccess:function(btn,type){
  275. var tabP=Ext.getCmp('saletabpanel'),_activeTab=tabP.activeTab;
  276. _activeTab.loadNewStore(_activeTab,_activeTab.params);
  277. var win=btn.up('window');
  278. if(win) win.close();
  279. }
  280. })