VoucherStyle.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.VoucherStyle', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. views: ['fa.VoucherStyle', 'core.form.Panel', 'core.grid.Panel2', 'core.grid.YnColumn', 'core.trigger.TextAreaTrigger',
  7. 'core.trigger.DbfindTrigger','core.button.Sync',
  8. 'core.button.Close', 'core.button.Save', 'core.button.Update'],
  9. init:function(){
  10. var me = this;
  11. this.control({
  12. 'erpGridPanel2': {
  13. itemclick: function(selModel, record) {
  14. me.GridUtil.onGridItemClick(selModel, record);
  15. var btn = Ext.getCmp('assdetail');
  16. var ass = record.data['ca_asstype'],
  17. check = record.data['vd_checkitem'];
  18. if(!Ext.isEmpty(ass) || check == -1){
  19. btn.setDisabled(false);
  20. } else {
  21. btn.setDisabled(true);
  22. }
  23. }
  24. },
  25. 'erpSaveButton': {
  26. click: function(btn){
  27. me._beforeSave();
  28. me.beforeSave();
  29. }
  30. },
  31. 'erpUpdateButton': {
  32. click: function(btn){
  33. me._beforeSave();
  34. me.beforeUpdate();
  35. }
  36. },
  37. 'button[id=assdetail]': {
  38. click: function(btn) {
  39. var grid = btn.ownerCt.ownerCt;
  40. var record = grid.selModel.lastSelected;
  41. if(record){
  42. var id = record.get('vd_id') || (-grid.store.indexOf(record));
  43. var win = Ext.getCmp('ass-' + id);
  44. if(win) {
  45. win.show();
  46. } else {
  47. var form = Ext.create('Ext.form.Panel', {
  48. height: 160,
  49. layout: 'column',
  50. defaults: {
  51. xtype: 'textfield',
  52. columnWidth: .5,
  53. margin: 3,
  54. allowBlank: false
  55. },
  56. bodyStyle: 'background:transparent',
  57. items: [{
  58. fieldLabel: '表名',
  59. name: 'vd_asstable'
  60. },{
  61. fieldLabel: '关联关系',
  62. name: 'vd_assrel',
  63. columnWidth: 1
  64. },{
  65. fieldLabel: '类型字段',
  66. name: 'vd_asstypef'
  67. },{
  68. fieldLabel: '编号字段',
  69. name: 'vd_asscodef'
  70. },{
  71. fieldLabel: '名称字段',
  72. name: 'vd_assnamef'
  73. }]
  74. });
  75. var grid = Ext.create('Ext.grid.Panel', {
  76. height: 200,
  77. columns: [{
  78. text: 'ID',
  79. hidden: true,
  80. dataIndex: 'vsa_id'
  81. },{
  82. text: 'VD_ID',
  83. hidden: true,
  84. dataIndex: 'vsa_vdid'
  85. },{
  86. text: '核算项',
  87. dataIndex: 'vsa_assname',
  88. flex: 1,
  89. editor: {
  90. xtype: 'dbfindtrigger'
  91. },
  92. dbfind: 'AssKind|ak_name'
  93. },{
  94. text: '编号表达式',
  95. dataIndex: 'vsa_codefield',
  96. flex: 1,
  97. editor: {
  98. xtype: 'textfield'
  99. }
  100. },{
  101. text: '名称表达式',
  102. dataIndex: 'vsa_namefield',
  103. flex: 1,
  104. editor: {
  105. xtype: 'textfield'
  106. }
  107. }],
  108. store: new Ext.data.Store({
  109. fields: [{name: 'vsa_id', type: 'number'}, {name: 'vsa_vdid', type: 'number'},
  110. {name: 'vsa_assname', type: 'string'}, {name: 'vsa_codefield', type: 'string'},
  111. {name: 'vsa_namefield', type: 'string'}]
  112. }),
  113. columnLines: true,
  114. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  115. clicksToEdit: 1
  116. })],
  117. dbfinds: [{
  118. field: 'vsa_assname',
  119. dbGridField: 'ak_name'
  120. }],
  121. listeners: {
  122. itemclick: function(selModel, record) {
  123. var grid = selModel.ownerCt,
  124. store = grid.store,
  125. idx = store.indexOf(record),
  126. len = store.getCount();
  127. if(idx == len - 1) {
  128. store.add({}, {}, {}, {}, {});
  129. }
  130. }
  131. }
  132. });
  133. win = Ext.create('Ext.Window', {
  134. width: 600,
  135. height: '80%',
  136. title: '辅助核算公式',
  137. bodyStyle: 'padding: 10px;',
  138. autoScroll: true,
  139. items: [{
  140. xtype: 'fieldset',
  141. collapsible: true,
  142. title: '常规核算',
  143. padding: 10,
  144. autoScroll: true,
  145. items: [grid]
  146. },{
  147. xtype: 'fieldset',
  148. collapsible: true,
  149. title: '第三方核算表',
  150. padding: 10,
  151. autoScroll: true,
  152. items: [form]
  153. }],
  154. buttonAlign: 'center',
  155. modal: true,
  156. buttons: [{
  157. text: $I18N.common.button.erpConfirmButton,
  158. cls: 'x-btn-blue',
  159. handler: function(btn) {
  160. var win = btn.ownerCt.ownerCt,
  161. grid = Ext.getCmp('grid'),
  162. record = grid.selModel.lastSelected,
  163. assgrid = win.down('gridpanel'), assform = win.down('form');
  164. if (assform.getForm().isValid()) {
  165. record.set('vd_asstable', assform.down('field[name=vd_asstable]').getValue());
  166. record.set('vd_assrel', assform.down('field[name=vd_assrel]').getValue());
  167. record.set('vd_asstypef', assform.down('field[name=vd_asstypef]').getValue());
  168. record.set('vd_asscodef', assform.down('field[name=vd_asscodef]').getValue());
  169. record.set('vd_assnamef', assform.down('field[name=vd_assnamef]').getValue());
  170. me.cacheStore[record.data[grid.keyField] || (-record.index)] = [];
  171. } else {
  172. record.set('vd_asstable', null);
  173. record.set('vd_assrel', null);
  174. record.set('vd_asstypef', null);
  175. record.set('vd_asscodef', null);
  176. record.set('vd_assnamef', null);
  177. var data = new Array();
  178. assgrid.store.each(function(item){
  179. data.push(item.data);
  180. });
  181. if(data.length > 0){
  182. me.cacheStore[record.data[grid.keyField] || (-record.index)] = data;
  183. }
  184. }
  185. win.hide();
  186. }
  187. },{
  188. text: $I18N.common.button.erpOffButton,
  189. cls: 'x-btn-blue',
  190. handler: function(btn) {
  191. btn.ownerCt.ownerCt.hide();
  192. }
  193. }]
  194. }).show();
  195. }
  196. me.getAss(win.down('form'), win.down('gridpanel'), id, record);
  197. }
  198. }
  199. },
  200. 'field[name=vd_catecode]': {
  201. aftertrigger: function(f, d) {
  202. var record = f.record,
  203. ass = d.get('ca_asstype');
  204. if(!Ext.isEmpty(ass)) {
  205. record.set('vd_checkitem', -1);
  206. } else {
  207. record.set('vd_checkitem', 0);
  208. }
  209. }
  210. }
  211. });
  212. },
  213. _beforeSave: function() {
  214. var grid = Ext.getCmp('grid'),
  215. code = Ext.getCmp('vs_code').value;
  216. grid.store.each(function(d){
  217. if(!Ext.isEmpty(d.get('vd_class'))) {
  218. d.set('vd_code', code);
  219. }
  220. });
  221. },
  222. cacheStore: new Array(),
  223. getAss: function(form, grid, id, record) {
  224. var me = this, ass = record.get('ca_assname').split('#');
  225. if(!Ext.isEmpty(record.get('vd_asstable'))) {
  226. form.getForm().setValues(record.data);
  227. }
  228. if(!me.cacheStore[id]){
  229. if(id == null || id <= 0){
  230. var data = new Array();
  231. for(var i = 0; i < ass.length; i++){
  232. var o = new Object();
  233. o.vsa_vdid = id;
  234. o.vsa_assname = ass[i];
  235. data.push(o);
  236. }
  237. grid.store.loadData(data);
  238. } else {
  239. var condition = "vsa_vdid=" + id;
  240. Ext.Ajax.request({
  241. url : basePath + 'common/getFieldsDatas.action',
  242. params: {
  243. caller: "VoucherStyleAss",
  244. fields: 'vsa_id,vsa_vdid,vsa_assname,vsa_codefield,vsa_namefield',
  245. condition: condition
  246. },
  247. method : 'post',
  248. callback : function(options,success,response){
  249. var res = new Ext.decode(response.responseText);
  250. if(res.exception || res.exceptionInfo){
  251. showError(res.exceptionInfo);
  252. return;
  253. }
  254. var data = Ext.decode(res.data);
  255. var dd = new Array();
  256. Ext.Array.each(data, function(d){
  257. var o = new Object();
  258. o.vsa_id = d.VSA_ID;
  259. o.vsa_vdid = d.VSA_VDID;
  260. o.vsa_assname = d.VSA_ASSNAME;
  261. o.vsa_codefield = d.VSA_CODEFIELD;
  262. o.vsa_namefield = d.VSA_NAMEFIELD;
  263. dd.push(o);
  264. });
  265. for(var i = 0; i < ass.length; i++){
  266. if(!Ext.isEmpty(ass[i])) {
  267. var bool = false;
  268. Ext.Array.each(data, function(d){
  269. if(d.VSA_ASSNAME == ass[i]) {
  270. bool = true;
  271. }
  272. });
  273. if(!bool) {
  274. var o = new Object();
  275. o.vsa_vdid = id;
  276. o.vsa_assname = ass[i];
  277. dd.push(o);
  278. }
  279. }
  280. }
  281. if(dd.length == 0) {
  282. dd = [{}, {}, {}, {}, {}];
  283. }
  284. grid.store.loadData(dd);
  285. }
  286. });
  287. }
  288. } else {
  289. grid.store.loadData(me.cacheStore[id]);
  290. }
  291. },
  292. beforeSave: function(){
  293. var me = this;
  294. var form = Ext.getCmp('form');
  295. if(! me.FormUtil.checkForm()){
  296. return;
  297. }
  298. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  299. me.FormUtil.getSeqId(form);
  300. }
  301. var detail = Ext.getCmp('grid');
  302. var param2 = new Array();
  303. Ext.each(Ext.Object.getKeys(me.cacheStore), function(key){
  304. Ext.each(me.cacheStore[key], function(d){
  305. d['vsa_vdid'] = key;
  306. param2.push(d);
  307. });
  308. });
  309. Ext.each(detail.store.data.items, function(item){
  310. if(item.data.vd_id == null || item.data.vd_id == 0){
  311. item.data.vd_id = -item.index;
  312. }
  313. });
  314. var param1 = me.GridUtil.getGridStore(detail);
  315. if(detail.necessaryField.length > 0 && (param1.length == 0)){
  316. showError($I18N.common.grid.emptyDetail);
  317. return;
  318. }
  319. me.onSave(form, param1, param2);
  320. },
  321. onSave: function(form, param1, param2) {
  322. var me = this;
  323. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  324. param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
  325. // param3 = param3 == null ? [] : param3.toString().replace(/\\/g,"%");
  326. if(form.getForm().isValid()){
  327. Ext.each(form.items.items, function(item){
  328. if(item.xtype == 'numberfield'){
  329. if(item.value == null || item.value == ''){
  330. item.setValue(0);
  331. }
  332. }
  333. });
  334. me.FormUtil.save(form.getValues(), param1, param2);
  335. }else{
  336. me.FormUtil.checkForm();
  337. }
  338. },
  339. beforeUpdate: function(){
  340. var me = this;
  341. var form = Ext.getCmp('form');
  342. if(! me.FormUtil.checkForm()){
  343. return;
  344. }
  345. var detail = Ext.getCmp('grid');
  346. Ext.each(detail.store.data.items, function(item){
  347. if(item.data.vd_id == null || item.data.vd_id == 0){
  348. item.data.vd_id = -item.index;
  349. }
  350. });
  351. var param1 = me.GridUtil.getGridStore(detail);
  352. var param2 = new Array();
  353. Ext.each(Ext.Object.getKeys(me.cacheStore), function(key){
  354. Ext.each(me.cacheStore[key], function(d){
  355. d['vsa_vdid'] = key;
  356. param2.push(d);
  357. });
  358. });
  359. if(me.FormUtil.checkFormDirty(form) == '' && detail.necessaryField.length > 0 && (param1.length == 0)
  360. && param2.length == 0){
  361. showError($I18N.common.grid.emptyDetail);
  362. return;
  363. } else {
  364. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  365. param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
  366. if(form.getForm().isValid()){
  367. Ext.each(form.items.items, function(item){
  368. if(item.xtype == 'numberfield'){
  369. if(item.value == null || item.value == ''){
  370. item.setValue(0);
  371. }
  372. }
  373. });
  374. me.FormUtil.update(form.getValues(), param1, param2);
  375. }else{
  376. me.FormUtil.checkForm();
  377. }
  378. }
  379. }
  380. });