MyDetail.js 8.2 KB

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