MyDataList.js 7.3 KB

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