MyDetail.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. Ext.define('erp.view.ma.MyDetail',{
  2. extend: 'Ext.grid.Panel',
  3. alias: 'widget.mydetail',
  4. layout : 'fit',
  5. id: 'detail',
  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: {
  16. xtype: 'erpToolbar',
  17. allowExtraButtons: false
  18. },
  19. initComponent : function(){
  20. whoami = getUrlParam('whoami');
  21. this.getGridColumnsAndStore();
  22. this.callParent(arguments);
  23. },
  24. detno: 'dg_sequence',
  25. caller: 'DetailGrid',
  26. getGridColumnsAndStore: function(){
  27. var grid = this;
  28. var main = parent.Ext.getCmp("content-panel");
  29. if(!main)
  30. main = parent.parent.Ext.getCmp("content-panel");
  31. if(main){
  32. main.getActiveTab().setLoading(true);//loading...
  33. }
  34. Ext.Ajax.request({//拿到grid的columns
  35. url : basePath + 'common/singleGridPanel.action',
  36. async: false,
  37. params: {
  38. caller: grid.caller,
  39. condition: "dg_caller='" + whoami + "'",
  40. _m: 0
  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. });
  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. } else if(logic == 'groupField'){
  108. grid.groupField = column.dataIndex;
  109. }
  110. }
  111. });
  112. },
  113. reconfigureGrid: function(){
  114. var grid = this;
  115. grid.store = Ext.create('Ext.data.Store', {
  116. storeId: 'gridStore',
  117. fields: grid.fields,
  118. data: grid.data,
  119. groupField: grid.groupField
  120. });
  121. },
  122. getDataDictionaryData: function(tablename){
  123. var me = this, mGrid = Ext.getCmp('grid');
  124. if(mGrid && mGrid.dictionary && mGrid.dictionary[tablename]) {
  125. me.parseDictionary(mGrid.dictionary[tablename]);
  126. } else {
  127. Ext.Ajax.request({
  128. url : basePath + 'ma/getDataDictionary.action',
  129. async: false,
  130. params: {
  131. table: tablename
  132. },
  133. method : 'post',
  134. callback : function(options,success,response){
  135. var res = new Ext.decode(response.responseText);
  136. if(res.exceptionInfo){
  137. showError(res.exceptionInfo);return;
  138. } else if(res.success) {
  139. me.parseDictionary(res.datadictionary);
  140. }
  141. }
  142. });
  143. }
  144. },
  145. parseDictionary: function(dictionary) {
  146. var me = this, data = this.data;
  147. //取Max(序号)
  148. var dets = Ext.Array.pluck(data, me.detno);
  149. Ext.Array.sort(dets, function(a, b){
  150. return b - a;
  151. });
  152. var det = dets[0];
  153. //data里面包含的字段
  154. var sel = Ext.Array.pluck(data, 'dg_field');
  155. var o = null;
  156. Ext.each(dictionary, function(d, index){
  157. //将DataDictionary的数据转化成FormDetail数据
  158. if(!Ext.Array.contains(sel, d.ddd_fieldname)){
  159. o = new Object();
  160. o.dg_table = d.ddd_tablename;
  161. o.dg_field = d.ddd_fieldname;
  162. o.dg_caption = d.ddd_description;
  163. o.dg_captionfan = d.ddd_description;
  164. o.dg_captionen = d.ddd_description;
  165. o.dg_editable = false;
  166. o.dg_width = 80;
  167. o.dg_dbbutton = false;
  168. o.dg_visible = true;
  169. o.deploy = false;
  170. o.dg_caller = whoami;
  171. if(contains(d.ddd_fieldtype, 'varchar2', true)){
  172. o.dg_type = 'text';
  173. } else if(contains(d.ddd_fieldtype, 'number', true)){
  174. o.dg_type = 'numbercolumn';
  175. } else if(d.ddd_fieldtype == 'timestamp'){
  176. o.dg_type = 'datetimecolumn';
  177. } else if(d.ddd_fieldtype == 'date'){
  178. o.dg_type = 'datecolumn';
  179. } else if(d.ddd_fieldtype == 'int'){
  180. o.dg_type = 'numbercolumn';
  181. } else if(d.ddd_fieldtype == 'float'){
  182. o.dg_type = 'floatcolumn';
  183. } else {
  184. o.dg_type = 'text';
  185. }
  186. o.dg_sequence = ++det;
  187. data.push(o);
  188. }
  189. });
  190. },
  191. getDeleted: function(){
  192. var grid = this,items = grid.store.data.items,key = grid.keyField,deleted = new Array(),d = null;
  193. Ext.each(items, function(item){
  194. d = item.data;
  195. if(item.dirty && !Ext.isEmpty(d[key]) && d['deploy'] == false) {
  196. deleted.push(grid.removeKey(d, 'deploy'));
  197. }
  198. });
  199. return deleted;
  200. },
  201. getAdded: function(){
  202. var grid = this,items = grid.store.data.items,key = grid.keyField,added = new Array(),d = null;
  203. Ext.each(items, function(item){
  204. d = item.data;
  205. if(item.dirty && d[key] == 0 && d['deploy'] == true) {
  206. added.push(grid.removeKey(d, 'deploy'));
  207. }
  208. });
  209. return added;
  210. },
  211. getUpdated: function(){
  212. var grid = this,items = grid.store.data.items,key = grid.keyField,updated = new Array(),d = null;
  213. Ext.each(items, function(item){
  214. d = item.data;
  215. if(item.dirty && !Ext.isEmpty(d[key]) && d[key] != 0 && d['deploy'] == true) {
  216. updated.push(grid.removeKey(d, 'deploy'));
  217. }
  218. });
  219. return updated;
  220. },
  221. removeKey: function(d, key){
  222. var a = new Object(),keys = Ext.Object.getKeys(d);
  223. Ext.each(keys, function(k){
  224. if(k != key) {
  225. a[k] = d[k];
  226. if(k == 'dg_editable' || k == 'dg_dbbutton' || k == 'dg_visible') {
  227. a[k] = a[k] ? -1 : 0;
  228. }
  229. }
  230. });
  231. return a;
  232. },
  233. getChange: function(){
  234. var grid = this,items = grid.store.data.items,key = grid.keyField,
  235. added = new Array(),updated = new Array(),deleted = new Array(),d = null,e = null;
  236. Ext.each(items, function(item){
  237. d = item.data;
  238. if (item.dirty) {
  239. e = grid.removeKey(d, 'deploy');
  240. if(d[key] == 0 && d['deploy'] == true) {
  241. added.push(e);
  242. }
  243. if(!Ext.isEmpty(d[key]) && d[key] != 0 && d['deploy'] == true) {
  244. updated.push(e);
  245. }
  246. if(!Ext.isEmpty(d[key]) && d['deploy'] == false) {
  247. deleted.push(e);
  248. }
  249. }
  250. });
  251. return {
  252. added: added,
  253. updated: updated,
  254. deleted: deleted
  255. };
  256. }
  257. });