DetailAssGrid.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 = this.grid,
  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. var record = e.record;
  93. var set = grid.getDbfindSet(record.get('ars_asstype'));
  94. grid.dbfinds = set.dbfinds;
  95. column.dbfind = set.dbfind;
  96. }
  97. }
  98. }
  99. }
  100. }
  101. })],
  102. GridUtil: Ext.create('erp.util.GridUtil'),
  103. detno: 'ars_detno',
  104. keyField: 'ars_id',
  105. necessaryField: 'ars_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. cal = cal || caller;
  116. if(!me.cacheStore[id]){
  117. me.cacheAss[id] = Ext.Array.concate(me.asstype, '#');
  118. if(id == null || id <= 0){
  119. var data = new Array();
  120. for(var i=0;i<me.asstype.length;i++){
  121. var o = new Object();
  122. o[me.detno] = i + 1;
  123. o.ars_type = caller;
  124. data.push(o);
  125. }
  126. me.store.loadData(data);
  127. if(me.asstype.length > 0){
  128. me.getAssData(id);
  129. }
  130. } else {
  131. var condition = "ars_type='" + cal + "' AND ars_ardid=" + id;
  132. Ext.Ajax.request({
  133. url : basePath + 'common/singleGridPanel.action',
  134. params: {
  135. caller: "AccountRegister!DetailAss",
  136. condition: condition
  137. },
  138. method : 'post',
  139. callback : function(options,success,response){
  140. var res = new Ext.decode(response.responseText);
  141. if(res.exception || res.exceptionInfo){
  142. showError(res.exceptionInfo);
  143. return;
  144. }
  145. if(res.detno){
  146. me.detno = res.detno;
  147. }
  148. if(res.keyField){
  149. me.keyField = res.keyField;
  150. }
  151. if(res.necessaryField){
  152. me.necessaryField = res.necessaryField;
  153. }
  154. var data = res.data ? Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']')) : [];
  155. var _d = new Array(), as = Ext.getCmp('grid').selModel.lastSelected.get('ca_assname').split('#');
  156. for(var i in as) {
  157. var a = as[i], k = null;
  158. for(var j in data) {
  159. if(a == data[j].ars_asstype) {
  160. k = data[j];
  161. }
  162. }
  163. if(k == null) {
  164. k = new Object();
  165. k[me.detno] = i + 1;
  166. k.ars_type = caller;
  167. }
  168. _d.push(k);
  169. }
  170. me.store.loadData(_d);
  171. if(res.dbfinds.length > 0){
  172. me.dbfinds = res.dbfinds;
  173. }
  174. me.getAssData(id);
  175. }
  176. });
  177. }
  178. } else {
  179. me.store.loadData(me.cacheStore[id]);
  180. }
  181. },
  182. getEffectData: function(){
  183. var grid = this;
  184. var data = new Array();
  185. Ext.each(Ext.Object.getKeys(grid.cacheStore), function(key){
  186. Ext.each(grid.cacheStore[key], function(d){
  187. if(d[grid.necessaryField] != null && d[grid.necessaryField].toString().trim() != ''){
  188. d['ars_ardid'] = key;
  189. d['ars_type'] = caller;
  190. data.push(d);
  191. }
  192. });
  193. });
  194. return data;
  195. },
  196. getAssData: function(id){
  197. var me = this;
  198. Ext.each(this.store.data.items, function(item, index){
  199. var type = me.asstype[index];
  200. if(me.asskind[type]){
  201. item.set('ars_asstype', me.asskind[type].ak_name);
  202. } else {
  203. Ext.Ajax.request({
  204. url : basePath + 'common/getFieldsData.action',
  205. async: false,
  206. params: {
  207. caller: 'AssKind',
  208. fields: 'ak_name,ak_table,ak_dbfind,ak_asscode,ak_assname,ak_addkind',
  209. condition: "ak_code='" + type + "'"
  210. },
  211. method : 'post',
  212. callback : function(options,success,response){
  213. var localJson = new Ext.decode(response.responseText);
  214. if(localJson.exceptionInfo){
  215. showError(localJson.exceptionInfo);return;
  216. }
  217. if(localJson.success){
  218. var d = localJson.data;
  219. if(Ext.isEmpty(item.get('ars_asstype')))
  220. item.set('ars_asstype', d.ak_name);
  221. me.asskind[type] = d;
  222. }
  223. }
  224. });
  225. }
  226. });
  227. var data = new Array();
  228. Ext.each(me.store.data.items, function(){
  229. data.push(this.data);
  230. });
  231. if(data.length > 0){
  232. me.cacheStore[id] = data;
  233. }
  234. },
  235. getDbfindSet: function(type) {
  236. var sets = {
  237. '供应商往来': {
  238. dbfind: 'Vendor|ve_code',
  239. dbfinds: [{dbGridField:'ve_code',field:'ars_asscode'},{dbGridField:'ve_name',field:'ars_assname'}]
  240. },
  241. '部门': {
  242. dbfind: 'Department|dp_code',
  243. dbfinds: [{dbGridField:'dp_code',field:'ars_asscode'},{dbGridField:'dp_name',field:'ars_assname'}]
  244. },
  245. '员工': {
  246. dbfind: 'Employee|em_code',
  247. dbfinds: [{dbGridField:'em_code',field:'ars_asscode'},{dbGridField:'em_name',field:'ars_assname'}]
  248. },
  249. '仓库': {
  250. dbfind: 'WareHouse|wh_code',
  251. dbfinds: [{dbGridField:'wh_code',field:'ars_asscode'},{dbGridField:'wh_description',field:'ars_assname'}]
  252. },
  253. '客户往来': {
  254. dbfind: 'Customer|cu_code',
  255. dbfinds: [{dbGridField:'cu_code',field:'ars_asscode'},{dbGridField:'cu_name',field:'ars_assname'}]
  256. }
  257. };
  258. return sets[type] || {
  259. dbfind: 'AssKindDetail|akd_asscode',
  260. dbfinds: [{dbGridField:'akd_asscode',field:'ars_asscode'},{dbGridField:'akd_assname',field:'ars_assname'}]
  261. };
  262. }
  263. });