CustomGrid.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. Ext.define('erp.view.oa.custom.CustomGrid',{
  2. extend: 'Ext.grid.Panel',
  3. alias: 'widget.customgrid',
  4. layout : 'fit',
  5. id: 'grid',
  6. emptyText : $I18N.common.grid.emptyText,
  7. columnLines : true,
  8. autoScroll : true,
  9. store: [],
  10. columns: [],
  11. multiselected: new Array(),
  12. plugins: Ext.create('Ext.grid.plugin.CellEditing', {
  13. clicksToEdit: 1
  14. }),
  15. orderby: ' order by fd_detno',
  16. GridUtil: Ext.create('erp.util.GridUtil'),
  17. bbar: {xtype: 'erpToolbar'},
  18. initComponent : function(){
  19. gridCondition = getUrlParam('gridCondition');//从url解析参数
  20. gridCondition = (gridCondition == null) ? "" : gridCondition.replace(/IS/g,"=");
  21. if(gridCondition==null||gridCondition==""){
  22. gridCondition="fd_foid=0";
  23. }
  24. this.getGridColumnsAndStore();
  25. this.callParent(arguments);
  26. },
  27. getGridColumnsAndStore: function(){
  28. var grid = this;
  29. var main = parent.Ext.getCmp("content-panel");
  30. if(!main)
  31. main = parent.parent.Ext.getCmp("content-panel");
  32. if(main){
  33. main.getActiveTab().setLoading(true);//loading...
  34. }
  35. Ext.Ajax.request({//拿到grid的columns
  36. url : basePath + 'common/singleGridPanel.action',
  37. async: false,
  38. params: {
  39. caller: 'Form!Custom',
  40. condition: gridCondition + grid.orderby
  41. },
  42. method : 'post',
  43. callback : function(options,success,response){
  44. if(main){
  45. main.getActiveTab().setLoading(false);
  46. }
  47. var res = new Ext.decode(response.responseText);
  48. if(res.exceptionInfo){
  49. showError(res.exceptionInfo);return;
  50. }
  51. if(res.columns){
  52. grid.columns = res.columns;
  53. grid.fields = res.fields;
  54. grid.columns.push({
  55. xtype: 'checkcolumn',
  56. text: '配置',
  57. width: 60,
  58. dataIndex: 'deploy',
  59. cls: "x-grid-header-1",
  60. locked: true,
  61. editor: {
  62. xtype: 'checkbox',
  63. cls: "x-grid-checkheader-editor"
  64. }
  65. });
  66. grid.fields.push({name: 'deploy', type: 'bool'});
  67. //renderer
  68. grid.getRenderer();
  69. var data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  70. Ext.each(data, function(d){
  71. d.deploy = true;
  72. d.fd_readonly = d.fd_readonly == 'T';
  73. d.fd_allowblank = d.fd_allowblank == 'T';
  74. });
  75. grid.data = data;
  76. if(res.dbfinds.length > 0){
  77. grid.dbfinds = res.dbfinds;
  78. }
  79. //取数据字典配置
  80. grid.getDataDictionaryData('CUSTOMTABLE');
  81. }
  82. }
  83. });
  84. },
  85. getRenderer: function(){
  86. var grid = this;
  87. Ext.each(grid.columns, function(column, y){
  88. //logictype
  89. var logic = column.logic;
  90. if(logic != null){
  91. if(logic == 'detno'){
  92. grid.detno = column.dataIndex;
  93. } else if(logic == 'keyField'){
  94. grid.keyField = column.dataIndex;
  95. } else if(logic == 'mainField'){
  96. grid.mainField = column.dataIndex;
  97. } else if(logic == 'necessaryField'){
  98. grid.necessaryField = column.dataIndex;
  99. if(!grid.necessaryFields){
  100. grid.necessaryFields = new Array();
  101. }
  102. grid.necessaryFields.push(column.dataIndex);
  103. if(!column.haveRendered){
  104. column.renderer = function(val, meta, item){
  105. if(item.data['fd_id'] != null && item.data['fd_id'] != '' && item.data['fd_id'] != '0'
  106. && item.data['fd_id'] != 0) {
  107. return '<img src="' + basePath + 'resource/images/renderer/finishrecord.png">' +
  108. '<span style="color:blue;" title="已配置">' + val + '</span>';
  109. } else {
  110. return '<img src="' + basePath + 'resource/images/renderer/important.png">' +
  111. '<span style="color:red;" title="未配置">' + val + '</span>';
  112. }
  113. };
  114. }
  115. } else if(logic == 'groupField'){
  116. grid.groupField = column.dataIndex;
  117. }
  118. }
  119. });
  120. },
  121. reconfigureGrid: function(){
  122. var grid = this;
  123. grid.store = Ext.create('Ext.data.Store', {
  124. storeId: 'gridStore',
  125. fields: grid.fields,
  126. data: grid.data,
  127. groupField: grid.groupField
  128. });
  129. },
  130. getDataDictionaryData: function(tablename){
  131. var me = this,data = this.data;
  132. Ext.Ajax.request({
  133. url : basePath + 'ma/getDataDictionary.action',
  134. async: false,
  135. params: {
  136. table: tablename
  137. },
  138. method : 'post',
  139. callback : function(options,success,response){
  140. var res = new Ext.decode(response.responseText);
  141. if(res.exceptionInfo){
  142. showError(res.exceptionInfo);return;
  143. } else if(res.success) {
  144. if(data.length==0){
  145. var v_detno=0;
  146. Ext.each(res.datadictionary, function(d, index){
  147. var arrayfix = ['ct_id','ct_code','ct_recorder','ct_recorddate','ct_status','ct_statuscode',
  148. 'ct_caller','ct_sourcekind','ct_auditman','ct_auditdate'];
  149. if(Ext.Array.indexOf(arrayfix,d.column_name,0)>-1){
  150. o = new Object();
  151. o.fd_table = d.table_name;
  152. o.fd_field = d.column_name;
  153. o.fd_caption = d.comments;
  154. o.fd_captionfan = d.comments;
  155. o.fd_captionen = d.comments;
  156. o.fd_readonly = true;
  157. o.fd_allowblank = true;
  158. o.fd_columnwidth = 1;
  159. o.fd_dbfind = 'F';
  160. o.deploy = true;
  161. if(contains(d.data_type, 'VARCHAR2', true)){
  162. o.fd_type = 'S';
  163. } else if(contains(d.data_type, 'NUMBER', true)){
  164. o.fd_type = 'N';
  165. } else if(contains(d.data_type,'TIMESTAMP',true)){
  166. o.fd_type = 'DT';
  167. } else if(d.data_type == 'DATE'){
  168. o.fd_type = 'D';
  169. } else if(d.data_type == 'NUMBER'){
  170. o.fd_type = 'N';
  171. } else if(d.data_type == 'FLOAT'){
  172. o.fd_type = 'N';
  173. } else {
  174. o.fd_type = 'S';
  175. }
  176. if(contains(d.column_name,'VARCHAR',true)){
  177. o.fd_fieldlength =Number(d.column_name.substring(d.column_name.indexOf('VARCHAR')+7,d.column_name.lastIndexOf('_')));
  178. }else o.fd_fieldlength=100;
  179. o.fd_detno = ++v_detno;
  180. if(d.column_name=='ct_id'||d.column_name=='ct_caller'){
  181. o.fd_field =d.column_name.toUpperCase();
  182. o.fd_type = 'H';
  183. }
  184. if(d.column_name=='ct_sourcekind'){//单据类型
  185. o.fd_type = 'H';
  186. }
  187. if(d.column_name=='ct_statuscode'){//状态码
  188. o.fd_field ='CT_STATUSCODE';
  189. o.fd_defaultvalue='ENTERING';
  190. o.fd_type = 'H';
  191. }
  192. if(d.column_name=='ct_status'){//状态
  193. o.fd_field ='CT_STATUS';
  194. o.fd_defaultvalue='getLocal(ENTERING)';
  195. }
  196. if(d.column_name=='ct_recorder'){//录入人
  197. o.fd_defaultvalue='session:em_name';
  198. }
  199. if(d.column_name=='ct_recorddate'){
  200. o.fd_defaultvalue='getCurrentDate()';
  201. }
  202. if(d.column_name=='ct_code'){
  203. o.fd_field = d.column_name.toUpperCase();
  204. o.fd_readonly = false;
  205. }
  206. data.push(o);
  207. }
  208. });
  209. }
  210. //取Max(序号)
  211. var dets = Ext.Array.pluck(data, 'fd_detno');
  212. Ext.Array.sort(dets, function(a, b){
  213. return b - a;
  214. });
  215. var det = dets[0];
  216. //data里面包含的字段
  217. var sel = Ext.Array.pluck(data, 'fd_field');
  218. var o = null;
  219. Ext.each(res.datadictionary, function(d, index){
  220. //将DataDictionary的数据转化成FormDetail数据
  221. if(!Ext.Array.contains(sel, d.ddd_fieldname)){
  222. o = new Object();
  223. o.fd_table = d.table_name;
  224. o.fd_field = d.column_name;
  225. o.fd_caption = d.comments;
  226. o.fd_captionfan = d.comments;
  227. o.fd_captionen = d.comments;
  228. o.fd_readonly = false;
  229. o.fd_allowblank = true;
  230. o.fd_columnwidth = 1;
  231. o.fd_dbfind = 'F';
  232. o.deploy = false;
  233. if(contains(d.data_type, 'VARCHAR2', true)){
  234. o.fd_type = 'S';
  235. } else if(contains(d.data_type, 'NUMBER', true)){
  236. o.fd_type = 'N';
  237. } else if(contains(d.data_type,'TIMESTAMP',true)){
  238. o.fd_type = 'DT';
  239. } else if(d.data_type == 'DATE'){
  240. o.fd_type = 'D';
  241. } else if(d.data_type == 'NUMBER'){
  242. o.fd_type = 'N';
  243. } else if(d.data_type == 'FLOAT'){
  244. o.fd_type = 'N';
  245. } else {
  246. o.fd_type = 'S';
  247. }
  248. if(contains(d.column_name,'varchar',true)){
  249. o.fd_fieldlength =Number(d.column_name.substring(d.column_name.indexOf('varchar')+7,d.column_name.lastIndexOf('_')));
  250. }else o.fd_fieldlength=100;
  251. o.fd_detno = ++det;
  252. data.push(o);
  253. }
  254. });
  255. me.reconfigureGrid();
  256. }
  257. }
  258. });
  259. },
  260. getDeleted: function(){
  261. var grid = this,items = grid.store.data.items,key = grid.keyField,deleted = new Array(),d = null;
  262. Ext.each(items, function(item){
  263. d = item.data;
  264. if(item.dirty && !Ext.isEmpty(d[key]) && d['deploy'] == false) {
  265. deleted.push(grid.removeKey(d, 'deploy'));
  266. }
  267. });
  268. return deleted;
  269. },
  270. getAdded: function(){
  271. var grid = this,items = grid.store.data.items,key = grid.keyField,added = new Array(),d = null;
  272. Ext.each(items, function(item){
  273. d = item.data;
  274. if(!d['fd_detno']){
  275. d.fd_detno=0;
  276. }
  277. if(item.dirty && d[key] == 0 && d['deploy'] == true) {
  278. added.push(grid.removeKey(d, 'deploy'));
  279. }
  280. });
  281. return added;
  282. },
  283. getUpdated: function(){
  284. var grid = this,items = grid.store.data.items,key = grid.keyField,updated = new Array(),d = null;
  285. Ext.each(items, function(item){
  286. d = item.data;
  287. if(item.dirty && !Ext.isEmpty(d[key]) && d[key] != 0 && d['deploy'] == true) {
  288. updated.push(grid.removeKey(d, 'deploy'));
  289. }
  290. });
  291. return updated;
  292. },
  293. removeKey: function(d, key){
  294. var a = new Object(),keys = Ext.Object.getKeys(d);
  295. Ext.each(keys, function(k){
  296. if(k != key) {
  297. a[k] = d[k];
  298. if(k == 'fd_readonly' || k == 'fd_allowblank') {
  299. a[k] = a[k] ? 'T' : 'F';
  300. }
  301. }
  302. });
  303. return a;
  304. },
  305. getChange: function(){
  306. var grid = this,items = grid.store.data.items,key = grid.keyField,
  307. added = new Array(),updated = new Array(),deleted = new Array(),d = null,e = null;
  308. Ext.each(items, function(item){
  309. d = item.data;
  310. if (item.dirty) {
  311. e = grid.removeKey(d, 'deploy');
  312. if(d[key] == 0 && d['deploy'] == true) {
  313. added.push(e);
  314. }
  315. if(!Ext.isEmpty(d[key]) && d[key] != 0 && d['deploy'] == true) {
  316. updated.push(e);
  317. }
  318. if(!Ext.isEmpty(d[key]) && d['deploy'] == false) {
  319. deleted.push(e);
  320. }
  321. }
  322. });
  323. return {
  324. added: added,
  325. updated: updated,
  326. deleted: deleted
  327. };
  328. }
  329. });