DetailAssGrid.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /**
  2. *
  3. */
  4. Ext.define('erp.view.fa.gs.DetailAssGrid',{
  5. extend: 'Ext.grid.Panel',
  6. alias: 'widget.detailassgrid',
  7. layout : 'fit',
  8. id: 'assgrid',
  9. emptyText : $I18N.common.grid.emptyText,
  10. columnLines : true,
  11. autoScroll : true,
  12. store: Ext.create('Ext.data.Store', {
  13. fields:[{
  14. name: 'ars_id',
  15. type: 'number'
  16. },{
  17. name: 'ars_detno',
  18. type: 'number',
  19. format: '0'
  20. },{
  21. name: 'ars_ardid',
  22. type: 'number'
  23. },{
  24. name: 'ars_asstype',
  25. type: 'string'
  26. },{
  27. name: 'ars_assid',
  28. type: 'number'
  29. },{
  30. name: 'ars_asscode',
  31. type: 'string'
  32. },{
  33. name: 'ars_assname',
  34. type: 'string'
  35. }],
  36. data: [],
  37. sorters: [{
  38. property : 'ars_detno',
  39. direction: 'ASC'
  40. }]
  41. }),
  42. columns: [{
  43. xtype: 'numbercolumn',
  44. hidden: true,
  45. dataIndex: 'ars_id'
  46. },{
  47. text: '序号',
  48. dataIndex: 'ars_detno',
  49. flex: 0.4,
  50. xtype: 'numbercolumn',
  51. format: '0'
  52. },{
  53. dataIndex: 'ars_ardid',
  54. hidden: true,
  55. xtype: 'numbercolumn'
  56. },{
  57. dataIndex: 'ars_asstype',
  58. text: '辅助核算类型',
  59. flex: 1.2
  60. },{
  61. dataIndex: 'ars_assid',
  62. text: '辅助核算id',
  63. hidden: true
  64. },{
  65. dataIndex: 'ars_asscode',
  66. text: '辅助核算编号',
  67. flex: 1.2,
  68. editor: {
  69. xtype: 'textfield'
  70. }
  71. },{
  72. dataIndex: 'ars_assname',
  73. text: '辅助核算名称',
  74. flex: 3
  75. }],
  76. bodyStyle:'background-color:#f1f1f1;',
  77. plugins: Ext.create('Ext.grid.plugin.CellEditing', {
  78. clicksToEdit: 1,
  79. listeners: {
  80. beforeedit: function(e){
  81. if(e.field == 'ars_asscode'){
  82. var column = e.column,
  83. grid = Ext.getCmp('assgrid'),
  84. type = grid.asstype[e.rowIdx],
  85. kind;
  86. if(type){
  87. kind = grid.asskind[type];
  88. if(kind){
  89. column.setEditor(new erp.view.core.trigger.DbfindTrigger({
  90. findConfig: kind.ak_addkind == null ? '' : ('ak_addkind=\'' + kind.ak_addkind + '\'')
  91. }));
  92. column.dbfind = kind.ak_dbfind + '|' + kind.ak_asscode;
  93. grid.dbfinds = [{
  94. field: 'ars_asscode',
  95. dbGridField: kind.ak_asscode
  96. },{
  97. field: 'ars_assname',
  98. dbGridField: kind.ak_assname
  99. }];
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }),
  106. GridUtil: Ext.create('erp.util.GridUtil'),
  107. detno: 'ars_detno',
  108. keyField: 'ars_id',
  109. necessaryField: 'ars_asstype',
  110. initComponent : function(){
  111. this.callParent(arguments);
  112. },
  113. cacheStore: new Object(),//所有数据
  114. cacheAss: new Object(),//asstype改变时,cacheStore改变
  115. asstype: new Array(),//核算类型编号
  116. asskind: new Array(),//核算相关code、name、dbfind、table...
  117. getMyData: function(id, cal){
  118. var me = this;
  119. cal = cal || caller;
  120. if(!me.cacheStore[id]){
  121. me.cacheAss[id] = Ext.Array.concate(me.asstype, '#');
  122. if(id == null || id <= 0){
  123. var data = new Array();
  124. for(var i=0;i<me.asstype.length;i++){
  125. var o = new Object();
  126. o[me.detno] = i + 1;
  127. o.ars_type = caller;
  128. data.push(o);
  129. }
  130. me.store.loadData(data);
  131. if(me.asstype.length > 0){
  132. me.getAssData(id);
  133. }
  134. } else {
  135. var condition = "ars_type='" + cal + "' AND ars_ardid=" + id;
  136. Ext.Ajax.request({
  137. url : basePath + 'common/singleGridPanel.action',
  138. params: {
  139. caller: "AccountRegister!DetailAss",
  140. condition: condition
  141. },
  142. method : 'post',
  143. callback : function(options,success,response){
  144. var res = new Ext.decode(response.responseText);
  145. if(res.exception || res.exceptionInfo){
  146. showError(res.exceptionInfo);
  147. return;
  148. }
  149. if(res.detno){
  150. me.detno = res.detno;
  151. }
  152. if(res.keyField){
  153. me.keyField = res.keyField;
  154. }
  155. if(res.necessaryField){
  156. me.necessaryField = res.necessaryField;
  157. }
  158. var data = res.data ? Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']')) : [];
  159. var _d = new Array(), as = Ext.getCmp('grid').selModel.lastSelected.get('ca_assname').split('#');
  160. for(var i in as) {
  161. var a = as[i], k = null;
  162. for(var j in data) {
  163. if(a == data[j].ars_asstype) {
  164. k = data[j];
  165. }
  166. }
  167. if(k == null) {
  168. k = new Object();
  169. k[me.detno] = i + 1;
  170. k.ars_type = caller;
  171. }
  172. _d.push(k);
  173. }
  174. me.store.loadData(_d);
  175. if(res.dbfinds && res.dbfinds.length > 0){
  176. me.dbfinds = res.dbfinds;
  177. }
  178. me.getAssData(id);
  179. }
  180. });
  181. }
  182. } else {
  183. me.store.loadData(me.cacheStore[id]);
  184. }
  185. },
  186. getEffectData: function(){
  187. var grid = this;
  188. var data = new Array();
  189. Ext.each(Ext.Object.getKeys(grid.cacheStore), function(key){
  190. Ext.each(grid.cacheStore[key], function(d){
  191. if(d[grid.necessaryField] != null && d[grid.necessaryField].toString().trim() != ''){
  192. d['ars_ardid'] = key;
  193. d['ars_type'] = caller;
  194. data.push(d);
  195. }
  196. });
  197. });
  198. return data;
  199. },
  200. getAssData: function(id){
  201. var me = this;
  202. Ext.each(this.store.data.items, function(item, index){
  203. var type = me.asstype[index];
  204. if(me.asskind[type]){
  205. item.set('ars_asstype', me.asskind[type].ak_name);
  206. } else {
  207. Ext.Ajax.request({
  208. url : basePath + 'common/getFieldsData.action',
  209. async: false,
  210. params: {
  211. caller: 'AssKind',
  212. fields: 'ak_name,ak_table,ak_dbfind,ak_asscode,ak_assname,ak_addkind',
  213. condition: "ak_code='" + type + "'"
  214. },
  215. method : 'post',
  216. callback : function(options,success,response){
  217. var localJson = new Ext.decode(response.responseText);
  218. if(localJson.exceptionInfo){
  219. showError(localJson.exceptionInfo);return;
  220. }
  221. if(localJson.success){
  222. var d = localJson.data;
  223. if(Ext.isEmpty(item.get('ars_asstype')))
  224. item.set('ars_asstype', d.ak_name);
  225. me.asskind[type] = d;
  226. }
  227. }
  228. });
  229. }
  230. });
  231. var data = new Array();
  232. Ext.each(me.store.data.items, function(){
  233. data.push(this.data);
  234. });
  235. if(data.length > 0){
  236. me.cacheStore[id] = data;
  237. }
  238. }
  239. });