MyDetail.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. Ext.define('erp.view.ma.MyDetail',{
  2. extend: 'Ext.grid.Panel',
  3. alias: 'widget.mydetail',
  4. layout : 'fit',
  5. emptyText : $I18N.common.grid.emptyText,
  6. columnLines : true,
  7. autoScroll : true,
  8. store: [],
  9. columns: [],
  10. plugins: Ext.create('Ext.grid.plugin.CellEditing', {
  11. clicksToEdit: 1
  12. }),
  13. GridUtil: Ext.create('erp.util.GridUtil'),
  14. bbar: {
  15. xtype: 'erpToolbar',
  16. allowExtraButtons: false
  17. },
  18. initComponent : function(){
  19. this.whoami = this.whoami || getUrlParam('whoami');
  20. this.getGridColumnsAndStore();
  21. this.callParent(arguments);
  22. },
  23. detno: 'dg_sequence',
  24. caller: 'DetailGrid',
  25. getGridColumnsAndStore: function(){
  26. var grid = this;
  27. var main = parent.Ext.getCmp("content-panel");
  28. if(!main)
  29. main = parent.parent.Ext.getCmp("content-panel");
  30. if(main){
  31. main.getActiveTab().setLoading(true);//loading...
  32. }
  33. Ext.Ajax.request({//拿到grid的columns
  34. url : basePath + 'common/singleGridPanel.action',
  35. async: false,
  36. params: {
  37. caller: grid.caller,
  38. condition: "dg_caller='" + grid.whoami + "'",
  39. _m: 0
  40. },
  41. method : 'post',
  42. callback : function(options,success,response){
  43. if(main){
  44. main.getActiveTab().setLoading(false);
  45. }
  46. var res = new Ext.decode(response.responseText);
  47. if(res.exceptionInfo){
  48. showError(res.exceptionInfo);return;
  49. }
  50. if(res.columns){
  51. grid.columns = res.columns;
  52. grid.fields = res.fields;
  53. grid.columns.push({
  54. xtype: 'checkcolumn',
  55. text: '配置',
  56. width: 60,
  57. dataIndex: 'deploy',
  58. cls: "x-grid-header-1",
  59. locked: true,
  60. editor: {
  61. xtype: 'checkbox',
  62. cls: "x-grid-checkheader-editor"
  63. }
  64. });
  65. grid.fields.push({name: 'deploy', type: 'bool'});
  66. //renderer
  67. grid.getRenderer();
  68. var data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  69. Ext.each(data, function(d){
  70. d.deploy = true;
  71. d.dg_modify = d.dg_modify == 'T';
  72. });
  73. grid.data = data;
  74. if(res.dbfinds.length > 0){
  75. grid.dbfinds = res.dbfinds;
  76. }
  77. //取数据字典配置
  78. if(data && data.length > 0) {
  79. var tab = data[0].dg_table;
  80. if(tab) {
  81. grid.getDataDictionaryData(tab.split(' ')[0]);
  82. }
  83. }
  84. grid.reconfigureGrid();
  85. }
  86. }
  87. });
  88. },
  89. getRenderer: function(){
  90. var grid = this;
  91. Ext.each(grid.columns, function(column, y){
  92. //logictype
  93. var logic = column.logic;
  94. if(logic != null){
  95. if(logic == 'detno'){
  96. grid.detno = column.dataIndex;
  97. } else if(logic == 'keyField'){
  98. grid.keyField = column.dataIndex;
  99. } else if(logic == 'mainField'){
  100. grid.mainField = column.dataIndex;
  101. } else if(logic == 'necessaryField'){
  102. grid.necessaryField = column.dataIndex;
  103. if(!grid.necessaryFields){
  104. grid.necessaryFields = new Array();
  105. }
  106. grid.necessaryFields.push(column.dataIndex);
  107. if(!column.haveRendered){
  108. column.renderer = function(val, meta, item){
  109. if(item.data['dg_id'] != null && item.data['dg_id'] != '' && item.data['dg_id'] != '0'
  110. && item.data['dg_id'] != 0) {
  111. return '<img src="' + basePath + 'resource/images/renderer/finishrecord.png">' +
  112. '<span style="color:blue;" title="已配置">' + val + '</span>';
  113. } else {
  114. return '<img src="' + basePath + 'resource/images/renderer/important.png">' +
  115. '<span style="color:red;" title="未配置">' + val + '</span>';
  116. }
  117. };
  118. }
  119. } else if(logic == 'groupField'){
  120. grid.groupField = column.dataIndex;
  121. }
  122. }
  123. });
  124. },
  125. reconfigureGrid: function(){
  126. var grid = this;
  127. grid.store = Ext.create('Ext.data.Store', {
  128. fields: grid.fields,
  129. data: grid.data,
  130. sorters: [{
  131. property: 'dg_sequence'
  132. }]
  133. });
  134. },
  135. getDataDictionaryData: function(tablename){
  136. var me = this, mGrid = Ext.getCmp('grid');
  137. if(mGrid && mGrid.dictionary && mGrid.dictionary[tablename]) {
  138. me.parseDictionary(mGrid.dictionary[tablename]);
  139. } else {
  140. Ext.Ajax.request({
  141. url : basePath + 'ma/getDataDictionary.action',
  142. async: false,
  143. params: {
  144. table: tablename
  145. },
  146. method : 'post',
  147. callback : function(options,success,response){
  148. var res = new Ext.decode(response.responseText);
  149. if(res.exceptionInfo){
  150. showError(res.exceptionInfo);return;
  151. } else if(res.success) {
  152. me.parseDictionary(res.datadictionary);
  153. }
  154. }
  155. });
  156. }
  157. },
  158. parseDictionary: function(dictionary) {
  159. var me = this, data = this.data;
  160. //取Max(序号)
  161. var det = Ext.Array.max(Ext.Array.pluck(data, me.detno));
  162. //data里面包含的字段
  163. var sel = [];
  164. Ext.Array.each(data, function(d){
  165. sel.push(d.dg_field.toLowerCase());
  166. });
  167. var o = null;
  168. Ext.each(dictionary, function(d, index){
  169. //将DataDictionary的数据转化成FormDetail数据
  170. if(sel.indexOf(d.column_name) == -1){
  171. o = new Object();
  172. o.dg_table = d.table_name;
  173. o.dg_field = d.column_name;
  174. o.dg_caption = d.comments;
  175. o.dg_captionfan = d.comments;
  176. o.dg_captionen = d.comments;
  177. o.dg_editable = false;
  178. o.dg_width = 80;
  179. o.dg_dbbutton = '0';
  180. o.dg_visible = true;
  181. o.deploy = false;
  182. o.dg_caller = me.whoami;
  183. if(contains(d.data_type, 'VARCHAR2', true)){
  184. o.dg_type = 'text';
  185. o.dg_maxlength=d.data_length;
  186. } else if(contains(d.data_type, 'TIMESTAMP', true)){
  187. o.dg_type = 'datetimecolumn';
  188. } else if(d.data_type == 'DATE'){
  189. o.dg_type = 'datecolumn';
  190. } else if(d.data_type == 'NUMBER'){
  191. o.dg_type = 'numbercolumn';
  192. } else if(d.data_type == 'FLOAT'){
  193. o.dg_type = 'floatcolumn';
  194. } else {
  195. o.dg_type = 'text';
  196. o.dg_maxlength=d.data_length||100;
  197. }
  198. o.dg_sequence = ++det;
  199. data.push(o);
  200. }
  201. });
  202. },
  203. getDeleted: function(){
  204. var grid = this,items = grid.store.data.items,key = grid.keyField,deleted = new Array(),d = null;
  205. Ext.each(items, function(item){
  206. d = item.data;
  207. if(item.dirty && !Ext.isEmpty(d[key]) && d['deploy'] == false) {
  208. deleted.push(grid.removeKey(d, 'deploy'));
  209. }
  210. });
  211. return deleted;
  212. },
  213. getAdded: function(){
  214. var grid = this,items = grid.store.data.items,key = grid.keyField,added = new Array(),d = null;
  215. Ext.each(items, function(item){
  216. d = item.data;
  217. if(item.dirty && d[key] == 0 && d['deploy'] == true) {
  218. added.push(grid.removeKey(d, 'deploy'));
  219. }
  220. });
  221. return added;
  222. },
  223. getUpdated: function(){
  224. var grid = this,items = grid.store.data.items,key = grid.keyField,updated = new Array(),d = null;
  225. Ext.each(items, function(item){
  226. d = item.data;
  227. if(item.dirty && !Ext.isEmpty(d[key]) && d[key] != 0 && d['deploy'] == true) {
  228. updated.push(grid.removeKey(d, 'deploy'));
  229. }
  230. });
  231. return updated;
  232. },
  233. removeKey: function(d, key){
  234. var a = new Object(),keys = Ext.Object.getKeys(d);
  235. Ext.each(keys, function(k){
  236. if(k != key) {
  237. a[k] = d[k];
  238. if(k == 'dg_modify') {
  239. a[k] = a[k] ? 'T' : 'F';
  240. }
  241. if(k == 'dg_editable' || k == 'dg_visible') {
  242. a[k] = a[k] ? -1 : 0;
  243. }
  244. if(k == 'dg_check')
  245. a[k] = a[k] ? 1 : 0;
  246. }
  247. });
  248. return a;
  249. },
  250. getChange: function(){
  251. var grid = this,items = grid.store.data.items,key = grid.keyField,
  252. added = new Array(),updated = new Array(),deleted = new Array(),d = null,e = null;
  253. Ext.each(items, function(item){
  254. d = item.data;
  255. if (item.dirty) {
  256. e = grid.removeKey(d, 'deploy');
  257. if(d[key] == 0 && d['deploy'] == true) {
  258. added.push(e);
  259. }
  260. if(!Ext.isEmpty(d[key]) && d[key] != 0 && d['deploy'] == true) {
  261. updated.push(e);
  262. }
  263. if(!Ext.isEmpty(d[key]) && d[key] != 0 && d['deploy'] == false) {
  264. deleted.push(e);
  265. }
  266. }
  267. });
  268. return {
  269. added: added,
  270. updated: updated,
  271. deleted: deleted
  272. };
  273. }
  274. });