CustomGrid.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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_dbfind = d.fd_dbfind == 'T';
  74. d.fd_allowblank = d.fd_allowblank == 'T';
  75. });
  76. grid.data = data;
  77. if(res.dbfinds.length > 0){
  78. grid.dbfinds = res.dbfinds;
  79. }
  80. //取数据字典配置
  81. grid.getDataDictionaryData('CUSTOMTABLE');
  82. }
  83. }
  84. });
  85. },
  86. getRenderer: function(){
  87. var grid = this;
  88. Ext.each(grid.columns, function(column, y){
  89. //logictype
  90. var logic = column.logic;
  91. if(logic != null){
  92. if(logic == 'detno'){
  93. grid.detno = column.dataIndex;
  94. } else if(logic == 'keyField'){
  95. grid.keyField = column.dataIndex;
  96. } else if(logic == 'mainField'){
  97. grid.mainField = column.dataIndex;
  98. } else if(logic == 'necessaryField'){
  99. grid.necessaryField = column.dataIndex;
  100. if(!grid.necessaryFields){
  101. grid.necessaryFields = new Array();
  102. }
  103. grid.necessaryFields.push(column.dataIndex);
  104. if(!column.haveRendered){
  105. column.renderer = function(val, meta, item){
  106. if(item.data['fd_id'] != null && item.data['fd_id'] != '' && item.data['fd_id'] != '0'
  107. && item.data['fd_id'] != 0) {
  108. return '<img src="' + basePath + 'resource/images/renderer/finishrecord.png">' +
  109. '<span style="color:blue;" title="已配置">' + val + '</span>';
  110. } else {
  111. return '<img src="' + basePath + 'resource/images/renderer/important.png">' +
  112. '<span style="color:red;" title="未配置">' + val + '</span>';
  113. }
  114. };
  115. }
  116. } else if(logic == 'groupField'){
  117. grid.groupField = column.dataIndex;
  118. }
  119. }
  120. });
  121. },
  122. reconfigureGrid: function(){
  123. var grid = this;
  124. grid.store = Ext.create('Ext.data.Store', {
  125. storeId: 'gridStore',
  126. fields: grid.fields,
  127. data: grid.data,
  128. groupField: grid.groupField
  129. });
  130. },
  131. getDataDictionaryData: function(tablename){
  132. var me = this,data = this.data;
  133. Ext.Ajax.request({
  134. url : basePath + 'ma/getDataDictionary.action',
  135. async: false,
  136. params: {
  137. table: tablename
  138. },
  139. method : 'post',
  140. callback : function(options,success,response){
  141. var res = new Ext.decode(response.responseText);
  142. if(res.exceptionInfo){
  143. showError(res.exceptionInfo);return;
  144. } else if(res.success) {
  145. //取Max(序号)
  146. var dets = Ext.Array.pluck(data, 'fd_detno');
  147. Ext.Array.sort(dets, function(a, b){
  148. return b - a;
  149. });
  150. var det = dets[0];
  151. //data里面包含的字段
  152. var sel = Ext.Array.pluck(data, 'fd_field');
  153. var o = null;
  154. Ext.each(res.datadictionary, function(d, index){
  155. //将DataDictionary的数据转化成FormDetail数据
  156. if(!Ext.Array.contains(sel, d.ddd_fieldname)){
  157. o = new Object();
  158. o.fd_table = d.ddd_tablename;
  159. o.fd_field = d.ddd_fieldname;
  160. o.fd_captionfan = d.ddd_description;
  161. o.fd_captionen = d.ddd_description;
  162. o.fd_readonly = false;
  163. o.fd_allowblank = true;
  164. o.fd_columnwidth = 1;
  165. o.fd_dbfind = false;
  166. o.deploy = false;
  167. if(contains(d.ddd_fieldtype, 'varchar2', true)){
  168. o.fd_type = 'S';
  169. } else if(contains(d.ddd_fieldtype, 'number', true)){
  170. o.fd_type = 'N';
  171. } else if(d.ddd_fieldtype == 'timestamp'){
  172. o.fd_type = 'DT';
  173. } else if(d.ddd_fieldtype == 'Date'){
  174. o.fd_type = 'D';
  175. } else if(d.ddd_fieldtype == 'int'){
  176. o.fd_type = 'N';
  177. } else if(d.ddd_fieldtype == 'float'){
  178. o.fd_type = 'N';
  179. } else {
  180. o.fd_type = 'S';
  181. }
  182. if(contains(d.ddd_fieldname,'VARCHAR',true)){
  183. o.fd_fieldlength =Number(d.ddd_fieldname.substring(d.ddd_fieldname.indexOf('VARCHAR')+7,d.ddd_fieldname.lastIndexOf('_')));
  184. }else o.fd_fieldlength=100;
  185. o.fd_detno = ++det;
  186. data.push(o);
  187. }
  188. });
  189. me.reconfigureGrid();
  190. }
  191. }
  192. });
  193. },
  194. getDeleted: function(){
  195. var grid = this,items = grid.store.data.items,key = grid.keyField,deleted = new Array(),d = null;
  196. Ext.each(items, function(item){
  197. d = item.data;
  198. if(item.dirty && !Ext.isEmpty(d[key]) && d['deploy'] == false) {
  199. deleted.push(grid.removeKey(d, 'deploy'));
  200. }
  201. });
  202. return deleted;
  203. },
  204. getAdded: function(){
  205. var grid = this,items = grid.store.data.items,key = grid.keyField,added = new Array(),d = null;
  206. Ext.each(items, function(item){
  207. d = item.data;
  208. if(!d['fd_detno']){
  209. d.fd_detno=0;
  210. }
  211. if(item.dirty && d[key] == 0 && d['deploy'] == true) {
  212. added.push(grid.removeKey(d, 'deploy'));
  213. }
  214. });
  215. return added;
  216. },
  217. getUpdated: function(){
  218. var grid = this,items = grid.store.data.items,key = grid.keyField,updated = new Array(),d = null;
  219. Ext.each(items, function(item){
  220. d = item.data;
  221. if(item.dirty && !Ext.isEmpty(d[key]) && d[key] != 0 && d['deploy'] == true) {
  222. updated.push(grid.removeKey(d, 'deploy'));
  223. }
  224. });
  225. return updated;
  226. },
  227. removeKey: function(d, key){
  228. var a = new Object(),keys = Ext.Object.getKeys(d);
  229. Ext.each(keys, function(k){
  230. if(k != key) {
  231. a[k] = d[k];
  232. if(k == 'fd_readonly' || k == 'fd_dbfind' || k == 'fd_allowblank') {
  233. a[k] = a[k] ? 'T' : 'F';
  234. }
  235. }
  236. });
  237. return a;
  238. },
  239. getChange: function(){
  240. var grid = this,items = grid.store.data.items,key = grid.keyField,
  241. added = new Array(),updated = new Array(),deleted = new Array(),d = null,e = null;
  242. Ext.each(items, function(item){
  243. d = item.data;
  244. if (item.dirty) {
  245. e = grid.removeKey(d, 'deploy');
  246. if(d[key] == 0 && d['deploy'] == true) {
  247. added.push(e);
  248. }
  249. if(!Ext.isEmpty(d[key]) && d[key] != 0 && d['deploy'] == true) {
  250. updated.push(e);
  251. }
  252. if(!Ext.isEmpty(d[key]) && d['deploy'] == false) {
  253. deleted.push(e);
  254. }
  255. }
  256. });
  257. return {
  258. added: added,
  259. updated: updated,
  260. deleted: deleted
  261. };
  262. }
  263. });