DetailAssGrid.js 6.3 KB

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