EmpgridLeft.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. Ext.define('erp.view.ma.update.EmpgridLeft',{
  2. extend: 'Ext.grid.Panel',
  3. alias: 'widget.empgridleft',
  4. layout:'column',
  5. id: 'dbfindGridPanel',
  6. emptyText : $I18N.common.grid.emptyText,
  7. columnLines : true,
  8. autoScroll : true,
  9. multiselected: [],
  10. store:[],
  11. columns:[],
  12. defaultcolumns: [{align: "left",cls: "x-grid-header-1",dataIndex: "em_code",flex: 1,header: "员工编号",text: "员工编号",filter:{autoDim: true,dataIndex: 'em_code',
  13. displayField: "display",exactSearch: false,ignoreCase: false,queryMode: 'local',store: null,valueField: 'value',xtype:'textfield'}
  14. },{align: "left",cls: "x-grid-header-1",dataIndex: "em_name",flex: 1,header: "员工姓名",text: "员工姓名",filter:{autoDim: true,dataIndex: 'em_name',
  15. displayField: "display",exactSearch: false,ignoreCase: false,queryMode: 'local',store: null,valueField: 'value',xtype:'textfield'}
  16. },{align: "left",cls: "x-grid-header-1",dataIndex: "em_defaulthsname",flex: 1,header: "岗位",text: "岗位",filter:{autoDim: true,dataIndex: 'em_defalthsname',
  17. displayField: "display",exactSearch: false,ignoreCase: false,queryMode: 'local',store: null,valueField: 'value',xtype:'textfield'}
  18. },{align: "left",cls: "x-grid-header-1",dataIndex: "em_defaultorname",flex: 1,header: "组织",text: "组织",filter:{autoDim: true,dataIndex: 'em_defaultorname',
  19. displayField: "display",exactSearch: false,ignoreCase: false,queryMode: 'local',store: null,valueField: 'value',xtype:'textfield'}}],
  20. multiselected: new Array(),
  21. selModel: Ext.create('Ext.selection.CheckboxModel',{
  22. ignoreRightMouseSelection : false,
  23. checkOnly: true
  24. }),
  25. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  26. clicksToEdit: 1
  27. }), Ext.create('Ext.ux.grid.GridHeaderFilters')],
  28. initComponent : function(){
  29. this.callParent(arguments);
  30. this.getCount();
  31. },
  32. RenderUtil: Ext.create('erp.util.RenderUtil'),
  33. getColumnsAndStore: function(c, d, g, s, callback){
  34. var me = this;
  35. c = c || caller;
  36. d = d || condition;
  37. g = g || page;
  38. s = s || pageSize;
  39. var f = d;
  40. if(me.filterCondition){
  41. if(d == null || d == ''){
  42. f = me.filterCondition;
  43. } else {
  44. f += ' AND ' + me.filterCondition;
  45. }
  46. }
  47. me.setLoading(true);
  48. Ext.Ajax.request({//拿到grid的columns
  49. url : basePath + 'ma/update/getEmpdbfindData.action',
  50. method : 'post',
  51. params : {
  52. fields:'em_code,em_name,em_defaulthsname,em_defaultorname',
  53. condition: f,
  54. page: g,
  55. pagesize: s
  56. },
  57. callback : function(options, success, response){
  58. me.setLoading(false);
  59. var res = new Ext.decode(response.responseText);
  60. if(res.exceptionInfo){
  61. showError(res.exceptionInfo);return;
  62. }
  63. var data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  64. if(callback)
  65. callback.call(me, data);
  66. else {
  67. if(me.columns && me.columns.length > 2){
  68. me.store.loadData(data);
  69. if(me.store.data.items.length != data.length){
  70. me.store.removeAll();
  71. me.store.add(data);
  72. }
  73. }else{
  74. var grid = this;
  75. me.reconfigure(Ext.create('Ext.data.Store', {
  76. fields:[{name: 'em_code',type: 'string'},{name: 'em_name',type: 'string'},
  77. {name: 'em_defaulthsname',type: 'string'},{name: 'em_defaultorname',type: 'string'}],
  78. data: data
  79. }),me.defaultcolumns);
  80. if(me.store.data.items.length != data.length){
  81. me.store.removeAll();
  82. me.store.add(data);
  83. }
  84. }
  85. Ext.getCmp('pagingtoolbar').afterOnLoad();
  86. }
  87. }
  88. });
  89. },
  90. getCount: function(c, d, callback){
  91. var me = this;
  92. c = 'UpdateScheme';
  93. d = d|| condition;
  94. var f = d;
  95. if(me.filterCondition){
  96. if(d == null || d == ''){
  97. f = me.filterCondition;
  98. } else {
  99. f += ' AND ' + me.filterCondition;
  100. }
  101. }
  102. Ext.Ajax.request({//拿到grid的数据总数count
  103. url : basePath + 'common/getCountByTable.action',
  104. params : {
  105. tablename: 'employee',
  106. condition: f
  107. },
  108. method : 'post',
  109. callback : function(options,success,response){
  110. var res = new Ext.decode(response.responseText);
  111. dataCount = res.count;
  112. if(callback)
  113. callback.call(me, dataCount, c, d);
  114. else
  115. me.getColumnsAndStore(c, d);
  116. }
  117. });
  118. },
  119. selectDefault: function(){
  120. var grid = this;
  121. },
  122. addToRight:function(){
  123. var gridL=Ext.getCmp('dbfindGridPanel'),gridR=Ext.getCmp('selectgrid');
  124. var o1=new Object(),o2=new Object(),a1=new Array(),a2=new Array();
  125. Ext.each(gridL.selModel.getSelection(),function(ss){
  126. o1[ss.data.em_code]=ss.data;
  127. });
  128. Ext.each(gridR.store.data.items,function(ss){
  129. if(ss.data.em_code!=''){
  130. o1[ss.data.em_code]=ss.data;
  131. }
  132. });
  133. var keys=Ext.Object.getKeys(o1);
  134. Ext.each(keys, function(k){
  135. a1.push(o1[k]);
  136. });
  137. gridR.getStore().loadData(a1);
  138. gridL.getSelectionModel().select([]);
  139. },
  140. listeners: {
  141. 'headerfiltersapply': function(grid, filters) {
  142. if(this.allowFilter){
  143. var condition = null;
  144. for(var fn in filters){
  145. var value = filters[fn],f = grid.getHeaderFilterField(fn);
  146. if(!Ext.isEmpty(value)){
  147. if(f.filtertype) {
  148. if (f.filtertype == 'numberfield') {
  149. value = fn + "=" + value + " ";
  150. }
  151. } else {
  152. if(Ext.isDate(value)){
  153. value = Ext.Date.toString(value);
  154. value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value + "' ";
  155. } else {
  156. var exp_t = /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/,
  157. exp_d = /^(\d{4})\-(\d{2})\-(\d{2})$/;
  158. if(exp_d.test(value)){
  159. value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value + "' ";
  160. } else if(exp_t.test(value)){
  161. value = "to_char(" + fn + ",'yyyy-MM-dd')='" + value.substr(0, 10) + "' ";
  162. } else{
  163. if(!f.autoDim) {
  164. value = fn + " LIKE '" + value + "%' ";
  165. } else {
  166. value = fn + " LIKE '%" + value + "%' ";
  167. }
  168. }
  169. }
  170. }
  171. if(condition == null){
  172. condition = value;
  173. } else {
  174. condition = condition + " AND " + value;
  175. }
  176. }
  177. }
  178. this.filterCondition = condition;
  179. page = 1;
  180. this.getCount();
  181. } else {
  182. this.allowFilter = true;
  183. }
  184. return false;
  185. }
  186. }
  187. });