MyDataList.js 7.8 KB

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