PayPlease.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.arp.PayPlease', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. BaseUtil: Ext.create('erp.util.BaseUtil'),
  7. ppdid:0,
  8. views:[
  9. 'core.form.Panel','fa.arp.PayPlease','fa.arp.payplease.PayPleaseDetailDetGrid','fa.arp.payplease.PayPleaseDetailGrid','core.button.Save','core.button.Add','core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail',
  10. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.button.ResAccounted','core.button.AssMain','core.button.Accounted','core.form.FileField',
  11. 'core.button.StrikeBalance','core.grid.AssPanel','core.window.AssWindow','core.trigger.CateTreeDbfindTrigger','core.trigger.HrOrgTreeDbfindTrigger',
  12. 'core.button.Post','core.button.ResPost','core.button.Print','core.button.Submit','core.button.ResAudit','core.button.Audit','core.button.ResSubmit',
  13. 'erp.view.core.button.AddDetail','erp.view.core.button.DeleteDetail','erp.view.core.button.Copy','erp.view.core.button.Paste','erp.view.core.button.Up',
  14. 'erp.view.core.button.Down','erp.view.core.button.UpExcel','core.button.TurnPayBalance','core.button.TurnBankRegister','core.button.TurnBillAP','core.button.TurnBillARChange',
  15. 'core.trigger.MultiDbfindTrigger', 'core.form.SeparNumber','core.form.MultiField','core.button.GetSumAmount','core.button.End','core.button.ResEnd'
  16. ],
  17. init:function(){
  18. var me = this;
  19. me.gridLastSelected = null;
  20. this.control({
  21. 'textfield[name=pp_thispayamount]':{
  22. beforerender: function(field){
  23. field.readOnly=false;
  24. }
  25. },
  26. 'erpGetSumAmountButton':{
  27. click: function(btn){
  28. var grid1 = Ext.getCmp("paypleasedetailGrid"),grid2 = Ext.getCmp("paypleasedetaildetGrid"),items1 = grid1.store.data.items,items2 = grid2.store.data.items;
  29. var detailamount1 = 0;
  30. var detailamount2 = 0;
  31. Ext.each(items2,function(item,index){
  32. if(!me.GridUtil.isBlank(grid2,item.data)) {
  33. detailamount2 = detailamount2 + Number(item.data['ppdd_thisapplyamount']);
  34. }
  35. });
  36. me.gridLastSelected.set('ppd_applyamount',detailamount2);
  37. }
  38. },
  39. //第一个从表
  40. 'paypleasedetailGrid':{
  41. itemclick:me.onGridItemClick1,
  42. afterrender:function(grid){
  43. grid.plugins[0].on('afteredit',function(e){
  44. setTimeout(function(){
  45. var amount = 0;
  46. Ext.each(grid.store.data.items,function(item,index){
  47. amount=amount+Number(item.data['ppd_applyamount']);
  48. });
  49. Ext.getCmp('pp_total').setValue(Ext.util.Format.number(amount,'0.00'));
  50. },200);
  51. });
  52. }
  53. },
  54. //第二个从表
  55. 'paypleasedetaildetGrid':{
  56. itemclick:me.onGridItemClick2
  57. },
  58. //转付款单
  59. 'erpTurnPayBalanceButton':{
  60. click:function(btn){
  61. me.turnPayBalance();
  62. },
  63. afterrender: function(btn){
  64. var status = Ext.getCmp(me.getForm(btn).statuscodeField);
  65. if(status && status.value != 'AUDITED'){
  66. btn.hide();
  67. }
  68. }
  69. },
  70. //转银行登记
  71. 'erpTurnBankRegisterButton':{
  72. click:function(btn){
  73. me.turnBankRegister();
  74. },
  75. afterrender: function(btn){
  76. var status = Ext.getCmp(me.getForm(btn).statuscodeField);
  77. if(status && status.value != 'AUDITED'){
  78. btn.hide();
  79. }
  80. }
  81. },
  82. //应付票据付款
  83. 'erpTurnBillAPButton':{
  84. click:function(btn){
  85. me.turnBillAP();
  86. },
  87. afterrender: function(btn){
  88. var status = Ext.getCmp(me.getForm(btn).statuscodeField);
  89. if(status && status.value != 'AUDITED'){
  90. btn.hide();
  91. }
  92. }
  93. },
  94. //应付票据付款
  95. 'erpTurnBillARChangeButton':{
  96. click:function(btn){
  97. me.turnBillARChange();
  98. },
  99. afterrender: function(btn){
  100. var status = Ext.getCmp(me.getForm(btn).statuscodeField);
  101. if(status && status.value != 'AUDITED'){
  102. btn.hide();
  103. }
  104. }
  105. },
  106. 'erpSaveButton': {
  107. click: function(btn){
  108. var form = me.getForm(btn);
  109. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  110. me.BaseUtil.getRandomNumber();
  111. }
  112. //保存之前的一些前台的逻辑判定
  113. this.beforeSavePayPlease();
  114. }
  115. },
  116. 'erpEndButton': {
  117. afterrender: function(btn){
  118. var status = Ext.getCmp('pp_statuscode');
  119. if(status && status.value == 'FINISH'){
  120. btn.hide();
  121. }
  122. },
  123. click: function(btn){
  124. me.FormUtil.onEnd(Ext.getCmp('pp_id').value);
  125. }
  126. },
  127. 'erpResEndButton': {
  128. afterrender: function(btn){
  129. var status = Ext.getCmp('pp_statuscode');
  130. if(status && status.value != 'FINISH'){
  131. btn.hide();
  132. }
  133. },
  134. click: function(btn){
  135. me.FormUtil.onResEnd(Ext.getCmp('pp_id').value);
  136. }
  137. },
  138. 'erpDeleteButton' : {
  139. click: function(btn){
  140. me.FormUtil.onDelete(Ext.getCmp('pp_id').value);
  141. }
  142. },
  143. 'erpUpdateButton': {
  144. click: function(btn){
  145. this.beforeUpdatePayPlease();
  146. }
  147. },
  148. 'erpAddButton': {
  149. click: function(){
  150. me.FormUtil.onAdd('addPayBalance', '新增付款申请单', 'jsps/fa/arp/payplease.jsp?whoami='+caller);
  151. }
  152. },
  153. 'erpCloseButton': {
  154. click: function(btn){
  155. me.FormUtil.beforeClose(me);
  156. }
  157. },
  158. 'erpSubmitButton': {
  159. afterrender: function(btn){
  160. var status = Ext.getCmp(me.getForm(btn).statuscodeField);
  161. if(status && status.value != 'ENTERING'){
  162. btn.hide();
  163. }
  164. },
  165. click: function(btn){
  166. me.beforeSubmit(btn);
  167. }
  168. },
  169. 'erpResSubmitButton': {
  170. afterrender: function(btn){
  171. var status = Ext.getCmp(me.getForm(btn).statuscodeField);
  172. if(status && status.value != 'COMMITED'){
  173. btn.hide();
  174. }
  175. },
  176. click: function(btn){
  177. me.FormUtil.onResSubmit(Ext.getCmp('pp_id').value);
  178. }
  179. },
  180. 'erpAuditButton': {
  181. afterrender: function(btn){
  182. var status = Ext.getCmp(me.getForm(btn).statuscodeField);
  183. if(status && status.value != 'COMMITED'){
  184. btn.hide();
  185. }
  186. },
  187. click: function(btn){
  188. me.FormUtil.onAudit(Ext.getCmp('pp_id').value);
  189. }
  190. },
  191. 'erpResAuditButton': {
  192. afterrender: function(btn){
  193. var status = Ext.getCmp(me.getForm(btn).statuscodeField);
  194. if(status && status.value != 'AUDITED'){
  195. btn.hide();
  196. }
  197. },
  198. click: function(btn){
  199. me.FormUtil.onResAudit(Ext.getCmp('pp_id').value);
  200. }
  201. },
  202. 'erpPrintButton': {
  203. click: function(btn){
  204. var reportName="APPay_app";
  205. var condition = '{PayPlease.pp_id}=' + Ext.getCmp('pp_id').value + '';
  206. var id = Ext.getCmp('pp_id').value;
  207. me.FormUtil.onwindowsPrint(id, reportName, condition);
  208. }
  209. },
  210. 'dbfindtrigger[name=ppdd_billcode]':{
  211. focus: function(t){
  212. t.setHideTrigger(false);
  213. t.setReadOnly(false);
  214. var record = Ext.getCmp('paypleasedetailGrid').selModel.selected.first();
  215. if(!record || !record.data['ppd_vendcode']) {
  216. showError("请先选择供应商!");
  217. t.setHideTrigger(true);
  218. t.setReadOnly(true);
  219. } else {
  220. var code = record.data['ppd_vendcode'];
  221. t.dbBaseCondition = " ab_vendcode = '" + code + "'";
  222. }
  223. }
  224. },
  225. 'dbfindtrigger[name=ppd_bankaccount]':{
  226. focus: function(t){
  227. var vecode = t.record.data['ppd_vendcode'];
  228. if(vecode != ''){
  229. t.dbBaseCondition = " vp_vecode='"+vecode+"' ";
  230. }
  231. }
  232. },
  233. 'multidbfindtrigger[name=ppdd_billcode]':{
  234. focus: function(t){
  235. t.setHideTrigger(false);
  236. t.setReadOnly(false);
  237. var record = Ext.getCmp('paypleasedetailGrid').selModel.selected.first();
  238. if(!record || !record.data['ppd_vendcode']) {
  239. showError("请先选择供应商!");
  240. t.setHideTrigger(true);
  241. t.setReadOnly(true);
  242. } else {
  243. var code = record.data['ppd_vendcode'];
  244. t.dbBaseCondition = " ab_vendcode = '" + code + "'";
  245. }
  246. }
  247. },
  248. //抓取发票信息
  249. 'button[name=catchab]':{
  250. click:function(btn){
  251. var grid2 = Ext.getCmp('paypleasedetaildetGrid');
  252. var form = Ext.getCmp('form');
  253. var lastselect = me.gridLastSelected;
  254. var params = new Object();
  255. console.log(btn.ownerCt.items);
  256. var startdate = btn.ownerCt.items.items[2].rawValue;
  257. var enddate = btn.ownerCt.items.items[4].rawValue;
  258. if(lastselect == null){
  259. //grid1 没有选择数据
  260. Ext.Msg.alert('警告','请先填写供应商信息!');
  261. }else{
  262. //grid1 选择了数据
  263. var array = new Array();
  264. Ext.each(grid2.store.data.items,function(item,index){
  265. var d = item.get('ppdd_id');
  266. if(d != null && Number(d) > 0){
  267. array.push(item);
  268. }
  269. });
  270. if(array.length>0){
  271. Ext.Msg.alert('警告','需要先清除明细行中的数据!');
  272. } else {
  273. params['ppd_id'] = lastselect.data['ppd_id'].toString();
  274. params['ppd_ppid'] = lastselect.data['ppd_ppid'].toString();
  275. params['startdate'] = startdate;
  276. params['enddate'] = enddate;
  277. //抓取
  278. Ext.Ajax.request({
  279. url : basePath + form.catchAPUrl,
  280. params : params,
  281. method : 'post',
  282. callback : function(options,success,response){
  283. me.FormUtil.getActiveTab().setLoading(false);
  284. var localJson = new Ext.decode(response.responseText);
  285. if(localJson.success){
  286. catchSuccess(function(){
  287. var condition = 'ppdd_ppdid='+lastselect.data['ppd_id'].toString();
  288. grid2.getMyData(condition);
  289. });
  290. } else if(localJson.exceptionInfo){
  291. showError(localJson.exceptionInfo);
  292. } else{
  293. catchFailure();//@i18n/i18n.js
  294. }
  295. }
  296. });
  297. }
  298. }
  299. }
  300. },
  301. //清除发票信息
  302. 'button[name=cleanab]':{
  303. click:function(btn){
  304. var grid2 = Ext.getCmp('paypleasedetaildetGrid');
  305. warnMsg('确定清除所有明细行么?',function(t){
  306. if(t=='yes'){
  307. var lastselect = me.gridLastSelected;
  308. var form = Ext.getCmp('form');
  309. var params = new Object();
  310. if(lastselect == null){
  311. //grid1 没有选择数据
  312. Ext.Msg.alert('警告','请先从第一明细表中选择一行明细行!');
  313. }else{
  314. params['ppd_id'] = lastselect.data['ppd_id'].toString();
  315. params['ppd_ppid'] = lastselect.data['ppd_ppid'].toString();
  316. Ext.Ajax.request({
  317. url : basePath + form.cleanAPUrl,
  318. params : params,
  319. method : 'post',
  320. callback : function(options,success,response){
  321. me.FormUtil.getActiveTab().setLoading(false);
  322. var localJson = new Ext.decode(response.responseText);
  323. if(localJson.success){
  324. cleanSuccess(function(){
  325. //add成功后刷新页面进入可编辑的页面
  326. var condition = 'ppdd_ppdid='+lastselect.data['ppd_id'].toString();
  327. grid2.getMyData(condition);
  328. });
  329. } else if(localJson.exceptionInfo){
  330. } else{
  331. cleanFailure();//@i18n/i18n.js
  332. }
  333. }
  334. });
  335. }
  336. }else{
  337. return;
  338. }
  339. });
  340. }
  341. },
  342. //发票明细
  343. 'button[name=detail]':{
  344. click:function(btn){
  345. var det = Ext.getCmp('paypleasedetaildetGrid');
  346. if(det.store.data.items.length == 0) {
  347. showError('请先选择申请单明细!');
  348. return;
  349. }
  350. var id = det.store.data.items[0].get('ppdd_ppdid');
  351. if(id == 0) {
  352. showError('请先选择申请单明细!');
  353. return;
  354. }
  355. var win = Ext.getCmp('bill-win');
  356. if(!win) {
  357. var url = basePath +'jsps/common/datalist.jsp?whoami=APBill!CWIM!Detail&_noc=1';
  358. url += '&urlcondition=ab_code in (select ppdd_billcode from paypleasedetaildet where ppdd_ppdid=' +
  359. id + ')';
  360. win = new Ext.window.Window({
  361. id : 'bill-win',
  362. title: '发票明细',
  363. height: '100%',
  364. width: '80%',
  365. maximizable : true,
  366. buttonAlign : 'center',
  367. closeAction: 'hide',
  368. layout : 'anchor',
  369. items: [{
  370. tag : 'iframe',
  371. frame : true,
  372. anchor : '100% 100%',
  373. layout : 'fit',
  374. html : '<iframe src="' + url + '" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  375. }],
  376. buttons : [{
  377. text : '关 闭',
  378. iconCls: 'x-button-icon-close',
  379. cls: 'x-btn-gray',
  380. handler : function(){
  381. Ext.getCmp('bill-win').hide();
  382. }
  383. }]
  384. });
  385. }
  386. win.show();
  387. }
  388. }
  389. });
  390. },
  391. turnPayBalance: function(){
  392. var grid = Ext.getCmp('paypleasedetailGrid');
  393. var items = grid.selModel.getSelection();
  394. if(items.length==0){
  395. Ext.Msg.alert('警告','请勾选需要转付款单的明细行!');
  396. return;
  397. }
  398. Ext.each(items, function(item, index){
  399. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  400. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  401. grid.multiselected.push(item);
  402. }
  403. });
  404. var form = Ext.getCmp('form');
  405. var records = Ext.Array.unique(grid.multiselected);
  406. var r = form.getValues();
  407. if(records.length > 0){
  408. var params = new Object();
  409. params.caller = caller;
  410. var data = new Array();
  411. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  412. var bool = false;
  413. Ext.each(records, function(record, index){
  414. var f = form.fo_detailMainKeyField;
  415. if(((grid.keyField && this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  416. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0)
  417. ||(f && this.data[f] != null && this.data[f] != ''
  418. && this.data[f] != '0' && this.data[f] != 0))&&(record.data['ppd_statuscode']!='TURNPB')){
  419. bool = true;
  420. var o = new Object();
  421. if(grid.keyField){
  422. o[grid.keyField] = record.data[grid.keyField];
  423. } else {
  424. params.id[index] = record.data[form.fo_detailMainKeyField];
  425. }
  426. if(grid.toField){
  427. Ext.each(grid.toField, function(f, index){
  428. var v = Ext.getCmp(f).value;
  429. if(v != null && v.toString().trim() != '' && v.toString().trim() != 'null'){
  430. o[f] = v;
  431. }
  432. });
  433. }
  434. if(grid.necessaryFields){
  435. Ext.each(grid.necessaryFields, function(f, index){
  436. var v = record.data[f];
  437. if(Ext.isDate(v)){
  438. v = Ext.Date.toString(v);
  439. }
  440. o[f] = v;
  441. });
  442. }
  443. data.push(o);
  444. }
  445. });
  446. if(bool){
  447. params.data = Ext.encode(data);
  448. var main = parent.Ext.getCmp("content-panel");
  449. main.getActiveTab().setLoading(true);//loading...
  450. Ext.Ajax.request({
  451. url : basePath + 'fa/PayPleaseController/turnPayBalance.action',
  452. params: params,
  453. method : 'post',
  454. callback : function(options,success,response){
  455. main.getActiveTab().setLoading(false);
  456. var localJson = new Ext.decode(response.responseText);
  457. if(localJson.exceptionInfo){
  458. showError(localJson.exceptionInfo);
  459. return "";
  460. }
  461. if(localJson.success){
  462. if(localJson.log){
  463. showMessage("提示", localJson.log);
  464. }
  465. Ext.Msg.alert("提示", "处理成功!", function(){
  466. var me = this;
  467. //add成功后刷新页面进入可编辑的页面
  468. var value = r[form.keyField];
  469. var formCondition = form.keyField + "IS" + value ;
  470. if(me.contains(window.location.href, '?', true)){
  471. window.location.href = window.location.href + '&formCondition=' +
  472. formCondition;
  473. } else {
  474. window.location.href = window.location.href + '?formCondition=' +
  475. formCondition;
  476. }
  477. });
  478. }
  479. }
  480. });
  481. } else {
  482. showError("没有需要处理的数据!");
  483. }
  484. }
  485. },
  486. turnBankRegister: function(){
  487. var grid = Ext.getCmp('paypleasedetailGrid'), catecode = Ext.getCmp('pp_paymentcode').value;
  488. var items = grid.selModel.getSelection();
  489. var thisamount = Ext.getCmp('pp_thispayamount').value, amount = 0;
  490. var ppamount = Ext.getCmp('pp_total').value;
  491. Ext.each(grid.store.data.items,function(item,index){
  492. amount=amount+Number(item.data['ppd_account']);
  493. });
  494. if(thisamount-(ppamount-amount)>0.01){
  495. Ext.getCmp('pp_thispayamount').setValue(ppamount-amount);
  496. }
  497. if(items.length==0){
  498. Ext.Msg.alert('警告','请勾选需要转银行登记的明细行!');
  499. return;
  500. }
  501. if(catecode == null || catecode == ''){
  502. Ext.Msg.alert('警告','请填写需要转银行登记的付款方信息!');
  503. return;
  504. }
  505. if(thisamount == null || thisamount=='' || thisamount==0){
  506. Ext.getCmp('pp_thispayamount').setValue(ppamount-amount);
  507. }
  508. Ext.each(items, function(item, index){
  509. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  510. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  511. grid.multiselected.push(item);
  512. }
  513. });
  514. var form = Ext.getCmp('form');
  515. var records = Ext.Array.unique(grid.multiselected);
  516. var r = form.getValues();
  517. if(records.length > 0){
  518. var params = new Object();
  519. params.caller = caller;
  520. var data = new Array();
  521. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  522. var bool = false;
  523. Ext.each(records, function(record, index){
  524. var f = form.fo_detailMainKeyField;
  525. if(((grid.keyField && this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  526. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0)
  527. ||(f && this.data[f] != null && this.data[f] != ''
  528. && this.data[f] != '0' && this.data[f] != 0))&&(record.data['ppd_statuscode']!='TURNPB')){
  529. bool = true;
  530. var o = new Object();
  531. if(grid.keyField){
  532. o[grid.keyField] = record.data[grid.keyField];
  533. } else {
  534. params.id[index] = record.data[form.fo_detailMainKeyField];
  535. }
  536. if(grid.toField){
  537. Ext.each(grid.toField, function(f, index){
  538. var v = Ext.getCmp(f).value;
  539. if(v != null && v.toString().trim() != '' && v.toString().trim() != 'null'){
  540. o[f] = v;
  541. }
  542. });
  543. }
  544. if(grid.necessaryFields){
  545. Ext.each(grid.necessaryFields, function(f, index){
  546. var v = record.data[f];
  547. if(Ext.isDate(v)){
  548. v = Ext.Date.toString(v);
  549. }
  550. o[f] = v;
  551. });
  552. }
  553. data.push(o);
  554. }
  555. });
  556. if(bool){
  557. params.data = Ext.encode(data);
  558. var main = parent.Ext.getCmp("content-panel");
  559. main.getActiveTab().setLoading(true);//loading...
  560. Ext.Ajax.request({
  561. url : basePath + 'fa/PayPleaseController/turnBankRegister.action',
  562. params: params,
  563. method : 'post',
  564. callback : function(options,success,response){
  565. main.getActiveTab().setLoading(false);
  566. var localJson = new Ext.decode(response.responseText);
  567. if(localJson.exceptionInfo){
  568. showError(localJson.exceptionInfo);
  569. return "";
  570. }
  571. if(localJson.success){
  572. if(localJson.log){
  573. showMessage("提示", localJson.log);
  574. }
  575. Ext.Msg.alert("提示", "处理成功!", function(){
  576. var me = this;
  577. //add成功后刷新页面进入可编辑的页面
  578. var value = r[form.keyField];
  579. var formCondition = form.keyField + "IS" + value ;
  580. if(me.contains(window.location.href, '?', true)){
  581. window.location.href = window.location.href + '&formCondition=' +
  582. formCondition;
  583. } else {
  584. window.location.href = window.location.href + '?formCondition=' +
  585. formCondition;
  586. }
  587. });
  588. }
  589. }
  590. });
  591. } else {
  592. showError("没有需要处理的数据!");
  593. }
  594. }
  595. },
  596. turnBillAP: function(){
  597. var grid = Ext.getCmp('paypleasedetailGrid'), catecode = Ext.getCmp('pp_paymentcode').value;
  598. var items = grid.selModel.getSelection();
  599. var thisamount = Ext.getCmp('pp_thispayamount').value, amount = 0;
  600. var ppamount = Ext.getCmp('pp_total').value;
  601. Ext.each(grid.store.data.items,function(item,index){
  602. amount=amount+Number(item.data['ppd_account']);
  603. });
  604. if(thisamount-(ppamount-amount)>0.01){
  605. Ext.getCmp('pp_thispayamount').setValue(ppamount-amount);
  606. }
  607. if(items.length==0){
  608. Ext.Msg.alert('警告','请勾选需要转应付票据的明细行!');
  609. return;
  610. }
  611. if(catecode == null || catecode == ''){
  612. Ext.Msg.alert('警告','请填写需要转应付票据的付款方信息!');
  613. return;
  614. }
  615. if(thisamount == null || thisamount=='' || thisamount==0){
  616. Ext.getCmp('pp_thispayamount').setValue(ppamount-amount);
  617. }
  618. Ext.each(items, function(item, index){
  619. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  620. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  621. grid.multiselected.push(item);
  622. }
  623. });
  624. var form = Ext.getCmp('form');
  625. var records = Ext.Array.unique(grid.multiselected);
  626. var r = form.getValues();
  627. if(records.length > 0){
  628. var params = new Object();
  629. params.caller = caller;
  630. var data = new Array();
  631. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  632. var bool = false;
  633. Ext.each(records, function(record, index){
  634. var f = form.fo_detailMainKeyField;
  635. if(((grid.keyField && this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  636. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0)
  637. ||(f && this.data[f] != null && this.data[f] != ''
  638. && this.data[f] != '0' && this.data[f] != 0))&&(record.data['ppd_statuscode']!='TURNPB')){
  639. bool = true;
  640. var o = new Object();
  641. if(grid.keyField){
  642. o[grid.keyField] = record.data[grid.keyField];
  643. } else {
  644. params.id[index] = record.data[form.fo_detailMainKeyField];
  645. }
  646. if(grid.toField){
  647. Ext.each(grid.toField, function(f, index){
  648. var v = Ext.getCmp(f).value;
  649. if(v != null && v.toString().trim() != '' && v.toString().trim() != 'null'){
  650. o[f] = v;
  651. }
  652. });
  653. }
  654. if(grid.necessaryFields){
  655. Ext.each(grid.necessaryFields, function(f, index){
  656. var v = record.data[f];
  657. if(Ext.isDate(v)){
  658. v = Ext.Date.toString(v);
  659. }
  660. o[f] = v;
  661. });
  662. }
  663. data.push(o);
  664. }
  665. });
  666. if(bool){
  667. params.data = Ext.encode(data);
  668. var main = parent.Ext.getCmp("content-panel");
  669. main.getActiveTab().setLoading(true);//loading...
  670. Ext.Ajax.request({
  671. url : basePath + 'fa/PayPleaseController/turnBillAP.action',
  672. params: params,
  673. method : 'post',
  674. callback : function(options,success,response){
  675. main.getActiveTab().setLoading(false);
  676. var localJson = new Ext.decode(response.responseText);
  677. if(localJson.exceptionInfo){
  678. showError(localJson.exceptionInfo);
  679. return "";
  680. }
  681. if(localJson.success){
  682. if(localJson.log){
  683. showMessage("提示", localJson.log);
  684. }
  685. Ext.Msg.alert("提示", "处理成功!", function(){
  686. var me = this;
  687. //add成功后刷新页面进入可编辑的页面
  688. var value = r[form.keyField];
  689. var formCondition = form.keyField + "IS" + value ;
  690. if(me.contains(window.location.href, '?', true)){
  691. window.location.href = window.location.href + '&formCondition=' +
  692. formCondition;
  693. } else {
  694. window.location.href = window.location.href + '?formCondition=' +
  695. formCondition;
  696. }
  697. });
  698. }
  699. }
  700. });
  701. } else {
  702. showError("没有需要处理的数据!");
  703. }
  704. }
  705. },
  706. turnBillARChange: function(){
  707. var grid = Ext.getCmp('paypleasedetailGrid'), catecode = Ext.getCmp('pp_paymentcode').value;
  708. var items = grid.selModel.getSelection();
  709. var thisamount = Ext.getCmp('pp_thispayamount').value, amount = 0;
  710. var ppamount = Ext.getCmp('pp_total').value;
  711. Ext.each(grid.store.data.items,function(item,index){
  712. amount=amount+Number(item.data['ppd_account']);
  713. });
  714. if(thisamount-(ppamount-amount)>0.01){
  715. Ext.getCmp('pp_thispayamount').setValue(ppamount-amount);
  716. }
  717. if(items.length==0){
  718. Ext.Msg.alert('警告','请勾选需要转应付票据的明细行!');
  719. return;
  720. }
  721. if(catecode == null || catecode == ''){
  722. Ext.Msg.alert('警告','请填写需要转应付票据的付款方信息!');
  723. return;
  724. }
  725. if(thisamount == null || thisamount=='' || thisamount==0){
  726. Ext.getCmp('pp_thispayamount').setValue(ppamount-amount);
  727. }
  728. Ext.each(items, function(item, index){
  729. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  730. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  731. grid.multiselected.push(item);
  732. }
  733. });
  734. var form = Ext.getCmp('form');
  735. var records = Ext.Array.unique(grid.multiselected);
  736. var r = form.getValues();
  737. if(records.length > 0){
  738. var params = new Object();
  739. params.caller = caller;
  740. var data = new Array();
  741. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  742. var bool = false;
  743. Ext.each(records, function(record, index){
  744. var f = form.fo_detailMainKeyField;
  745. if(((grid.keyField && this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  746. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0)
  747. ||(f && this.data[f] != null && this.data[f] != ''
  748. && this.data[f] != '0' && this.data[f] != 0))&&(record.data['ppd_statuscode']!='TURNPB')){
  749. bool = true;
  750. var o = new Object();
  751. if(grid.keyField){
  752. o[grid.keyField] = record.data[grid.keyField];
  753. } else {
  754. params.id[index] = record.data[form.fo_detailMainKeyField];
  755. }
  756. if(grid.toField){
  757. Ext.each(grid.toField, function(f, index){
  758. var v = Ext.getCmp(f).value;
  759. if(v != null && v.toString().trim() != '' && v.toString().trim() != 'null'){
  760. o[f] = v;
  761. }
  762. });
  763. }
  764. if(grid.necessaryFields){
  765. Ext.each(grid.necessaryFields, function(f, index){
  766. var v = record.data[f];
  767. if(Ext.isDate(v)){
  768. v = Ext.Date.toString(v);
  769. }
  770. o[f] = v;
  771. });
  772. }
  773. data.push(o);
  774. }
  775. });
  776. if(bool){
  777. params.data = Ext.encode(data);
  778. var main = parent.Ext.getCmp("content-panel");
  779. main.getActiveTab().setLoading(true);//loading...
  780. Ext.Ajax.request({
  781. url : basePath + 'fa/PayPleaseController/turnBillARChange.action',
  782. params: params,
  783. method : 'post',
  784. callback : function(options,success,response){
  785. main.getActiveTab().setLoading(false);
  786. var localJson = new Ext.decode(response.responseText);
  787. if(localJson.exceptionInfo){
  788. showError(localJson.exceptionInfo);
  789. return "";
  790. }
  791. if(localJson.success){
  792. if(localJson.log){
  793. showMessage("提示", localJson.log);
  794. }
  795. Ext.Msg.alert("提示", "处理成功!", function(){
  796. var me = this;
  797. //add成功后刷新页面进入可编辑的页面
  798. var value = r[form.keyField];
  799. var formCondition = form.keyField + "IS" + value ;
  800. if(me.contains(window.location.href, '?', true)){
  801. window.location.href = window.location.href + '&formCondition=' +
  802. formCondition;
  803. } else {
  804. window.location.href = window.location.href + '?formCondition=' +
  805. formCondition;
  806. }
  807. });
  808. }
  809. }
  810. });
  811. } else {
  812. showError("没有需要处理的数据!");
  813. }
  814. }
  815. },
  816. //点击第一个grid
  817. onGridItemClick1: function(selModel,record){
  818. var me = this;
  819. me.gridLastSelected = record;
  820. var ppd_id = record.data['ppd_id'];
  821. this.ppdid = ppd_id;
  822. var grid = Ext.getCmp('paypleasedetailGrid');
  823. var ppddgrid = Ext.getCmp('paypleasedetaildetGrid');
  824. if(ppd_id > 0 && !me.GridUtil.isBlank(grid,record.data)){
  825. var condition = "ppdd_ppdid='"+ppd_id+"'";
  826. ppddgrid.getMyData(condition);
  827. }
  828. this.onGridItemClick(selModel,record,'paypleasedetailGrid');
  829. },
  830. //点击第二个GRID
  831. onGridItemClick2: function(selModel,record){
  832. this.onGridItemClick(selModel,record,'paypleasedetaildetGrid');
  833. },
  834. onGridItemClick: function(selModel, record,id){//grid行选择
  835. this.GridUtil.onGridItemClick(selModel, record,id);
  836. },
  837. getForm: function(btn){
  838. return btn.ownerCt.ownerCt;
  839. },
  840. beforeSavePayPlease: function(){
  841. this.beforeSave();
  842. },
  843. beforeUpdatePayPlease:function(){
  844. var s = ' ';
  845. var ppdgrid = Ext.getCmp('paypleasedetailGrid');
  846. var items = ppdgrid.store.data.items;
  847. var bool = true;
  848. var pptotal = Number(Ext.getCmp('pp_total').getValue());
  849. var amount = 0;
  850. Ext.each(items,function(item){
  851. var keys = Ext.Object.getKeys(item.modified);
  852. Ext.each(keys,function(key){
  853. if(key=='ppd_auditamount'||key=='ppd_ifpay'){
  854. item.set('ppd_editor',em_name);
  855. item.set('ppd_editorid',em_uu);
  856. }
  857. });
  858. var applyamount = item.data['ppd_applyamount'];
  859. var auditamount = item.data['ppd_auditamount'];
  860. if(applyamount<auditamount){
  861. s=s+(item.index+1)+' ';
  862. bool=false;
  863. }
  864. amount=amount+Number(applyamount);
  865. });
  866. if(bool){
  867. this.beforeUpdate();
  868. // if(amount != pptotal){
  869. // console.log('show error');
  870. // showError($I18N.common.grid.updatePayPleaseError1);
  871. // }else{
  872. // this.beforeUpdate();
  873. // }
  874. }else{
  875. showError($I18N.common.grid.auditApplyPayPlease1 + s + $I18N.common.grid.auditApplyPayPlease2);
  876. }
  877. },
  878. /**
  879. * 检查form未完善的字段
  880. */
  881. checkForm: function(){
  882. var s = '';
  883. var form = Ext.getCmp('form');
  884. form.getForm().getFields().each(function (item,index,length){
  885. if(!item.isValid()){
  886. if(s != ''){
  887. s = s + ',';
  888. }
  889. if(item.fieldLabel){
  890. s = s + item.fieldLabel.replace(/&nbsp;/g,'');
  891. }
  892. }
  893. });
  894. if(s == ''){
  895. return true;
  896. }
  897. showError($I18N.common.form.necessaryInfo1 + '(<font color=green>'+s+'</font>)' + $I18N.common.form.necessaryInfo2);
  898. return false;
  899. },
  900. beforeUpdate: function(me){
  901. var mm = this;
  902. var form = Ext.getCmp('form');
  903. if(! this.checkForm()){
  904. return;
  905. }
  906. var grid = Ext.getCmp('paypleasedetailGrid');
  907. var date = Ext.getCmp('pp_date').getValue();
  908. grid.store.each(function(record){
  909. if(record.dirty && !mm.GridUtil.isBlank(grid, record.data)){
  910. if(Ext.isEmpty(record.get('ppd_startdate'))) {
  911. record.set('ppd_startdate', Ext.Date.getFirstDateOfMonth(date));
  912. }
  913. if(Ext.isEmpty(record.get('ppd_overdate'))) {
  914. record.set('ppd_overdate', Ext.Date.getLastDateOfMonth(date));
  915. }
  916. }
  917. });
  918. var gridsDet = Ext.getCmp('paypleasedetaildetGrid');
  919. var currency1 = '';
  920. if(this.gridLastSelected){
  921. if(this.gridLastSelected.data['ppd_id']){
  922. currency1 = this.gridLastSelected.data['ppd_currency'];
  923. mm.ppdid = this.gridLastSelected.data['ppd_id'];
  924. }
  925. }else{
  926. currency1 = grid.store.data.items[0].data['ppd_currency'];
  927. }
  928. var sameCurrency = true;
  929. Ext.each(gridsDet.store.data.items,function(item, index){
  930. if(item.dirty && !mm.GridUtil.isBlank(gridsDet, item.data)){
  931. var thisapplyamount = item.data['ppdd_thisapplyamount'];
  932. if(thisapplyamount == 0 || thisapplyamount == null){
  933. showError('明细表第' + item.data['ppdd_detno'] + '行本次申请金额不能为空!');return;
  934. return;
  935. }
  936. if(item.data['ppdd_currency'] != currency1){
  937. sameCurrency = false;
  938. }
  939. }
  940. });
  941. if(!sameCurrency){
  942. showError($I18N.common.msg.failure_update_currency);
  943. return;
  944. }
  945. if(mm.ppdid == 0 || mm.ppdid == null){
  946. if(grid){
  947. mm.ppdid = grid.store.data.items[0].data['ppd_id'];
  948. }else{
  949. mm.ppdid = 0;
  950. }
  951. }
  952. //如果ppdid == 0 则次页面为新建页面 活着以前也没有在grid1中添加数据
  953. //grid1 中的数据
  954. var param1 = mm.GridUtil.getGridStore(grid);
  955. //grid2中的数据
  956. var param2 = mm.getGridStoreDet(gridsDet);
  957. //ppdid==0的情况为 grid1第一条没有数据的情况 次情况只能保存grid1中的数据 grid2中的数据保存不上
  958. //如果ppdid!=0 则可能的情况为 1.点击grid1选择了一条数据 2.没有点击grid1 但是grid1中有数据 此时
  959. //grid2中的数据自动保存在grid1中第一条数据下
  960. if(mm.ppdid == 0){
  961. if(param2 == null || param2 == ''){
  962. //此时grid2数据为空 可以保存grid1的数据
  963. mm.onUpdate(param1);
  964. }else{
  965. warnMsg('不能保存从表二中的数据,是否只保存从表一?',function(btn){
  966. if(btn =='yes'){
  967. //保存从表一中的数据
  968. mm.onUpdate(param1);
  969. }else{
  970. //return
  971. return;
  972. }
  973. });
  974. }
  975. }else{
  976. if(param2 ==null||param2==''){
  977. mm.onUpdate(param1);
  978. }else{
  979. mm.onUpdate(param1,param2);
  980. }
  981. }
  982. },
  983. beforeSave: function(me){
  984. var mm = this;
  985. var form = Ext.getCmp('form');
  986. if(! this.checkForm()){
  987. return;
  988. }
  989. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  990. mm.FormUtil.getSeqId(form);
  991. }
  992. var grid = Ext.getCmp('paypleasedetailGrid');
  993. var date = Ext.getCmp('pp_date').getValue();
  994. grid.store.each(function(record){
  995. if(record.dirty && !mm.GridUtil.isBlank(grid, record.data)){
  996. if(Ext.isEmpty(record.get('ppd_startdate'))) {
  997. record.set('ppd_startdate', Ext.Date.getFirstDateOfMonth(date));
  998. }
  999. if(Ext.isEmpty(record.get('ppd_overdate'))) {
  1000. record.set('ppd_overdate', Ext.Date.getLastDateOfMonth(date));
  1001. }
  1002. }
  1003. });
  1004. var gridsDet = Ext.getCmp('paypleasedetaildetGrid');
  1005. var currency1 = '';
  1006. if(this.gridLastSelected){
  1007. currency1 = this.gridLastSelected.data['ppd_currency'];
  1008. mm.ppdid = this.gridLastSelected.data['ppd_id'];
  1009. } else{
  1010. currency1 = grid.store.first().data['ppd_currency'];
  1011. }
  1012. var sameCurrency = true;
  1013. Ext.each(gridsDet.store.data.items,function(item, index){
  1014. if(item.dirty && !mm.GridUtil.isBlank(gridsDet,item.data)){
  1015. if(item.data['ppdd_currency'] != currency1){
  1016. sameCurrency = false;
  1017. }
  1018. }
  1019. });
  1020. if(!sameCurrency){
  1021. showError($I18N.common.msg.failure_save_currency);
  1022. return;
  1023. }
  1024. if(mm.ppdid == 0 || mm.ppdid == null){
  1025. if(grid){
  1026. mm.ppdid = grid.store.data.items[0].data['ppd_id'];
  1027. }else{
  1028. mm.ppdid = 0;
  1029. }
  1030. }
  1031. //如果ppdid == 0 则次页面为新建页面 活着以前也没有在grid1中添加数据
  1032. //grid1 中的数据
  1033. var param1 = mm.GridUtil.getGridStore(grid);
  1034. //grid2中的数据
  1035. var param2 = mm.getGridStoreDet(gridsDet);
  1036. //ppdid==0的情况为 grid1第一条没有数据的情况 次情况只能保存grid1中的数据 grid2中的数据保存不上
  1037. //如果ppdid!=0 则可能的情况为 1.点击grid1选择了一条数据 2.没有点击grid1 但是grid1中有数据 此时
  1038. //grid2中的数据自动保存在grid1中第一条数据下
  1039. if(mm.ppdid == 0){
  1040. if(param2 == null || param2 == ''){
  1041. //此时grid2数据为空 可以保存grid1的数据
  1042. mm.onSave(param1);
  1043. }else{
  1044. warnMsg('不能保存从表二中的数据,是否只保存从表一?',function(btn){
  1045. if(btn =='yes'){
  1046. //保存从表一中的数据
  1047. mm.onSave(param1);
  1048. }else{
  1049. //return
  1050. return;
  1051. }
  1052. });
  1053. }
  1054. }else{
  1055. if(param2 ==null||param2==''){
  1056. mm.onSave(param1);
  1057. }else{
  1058. mm.onSave(param1,param2);
  1059. }
  1060. }
  1061. },
  1062. beforeSubmit: function(){
  1063. var me = this;
  1064. var grid1 = Ext.getCmp('paypleasedetailGrid'),items1=grid1.store.data.items;
  1065. var grid2 = Ext.getCmp('paypleasedetaildetGrid'),items2=grid2.store.data.items;
  1066. var applyamount = 0, nowamount=0,amount=0;
  1067. var bool = true;
  1068. Ext.each(items2,function(item,index){
  1069. if(!me.GridUtil.isBlank(grid2, item.data)){
  1070. nowamount = nowamount+Number(item.data['ppdd_thisapplyamount']);
  1071. if(Math.abs(Number(item.data['ppdd_billamount']))<Math.abs(Number(item.data['ppdd_account']))){
  1072. bool = false;
  1073. showError('发票的已付金额大于发票金额,不能提交');return;
  1074. }
  1075. if(!Ext.isEmpty(item.get('ppdd_ordercode'))) {
  1076. if(Math.abs(Number(item.data['ppdd_billamount'])-Number(item.data['ppdd_account'])) < Math.abs(Number(item.data['ppdd_thisapplyamount']))){
  1077. bool = false;
  1078. showError('本次申请金额大于发票未付的金额,不能提交');return;
  1079. }
  1080. }
  1081. }
  1082. });
  1083. var pptotal = Number(Ext.getCmp('pp_total').getValue());
  1084. var type=Ext.getCmp('pp_type').value;
  1085. if(type=='应付款'){
  1086. Ext.each(items1,function(item,index){
  1087. if(item.data[grid1.necessaryField]!=''&&item.data[grid1.necessaryField]!=null){
  1088. applyamount = Number(item.data['ppd_applyamount']);
  1089. amount = amount+ applyamount;
  1090. if(Math.abs(nowamount-applyamount)>0.001){
  1091. //冲账金额与明细行本次结算总和不等
  1092. //抛出异常
  1093. bool = false;
  1094. showError('申请金额与发票详情中本次申请金额不等,不能提交');return;
  1095. }
  1096. }
  1097. });
  1098. if(amount != pptotal){
  1099. bool = false;
  1100. showError($I18N.common.grid.submitPayPleaseError1);return;
  1101. }
  1102. if(bool)
  1103. me.FormUtil.onSubmit(Ext.getCmp('pp_id').value);
  1104. } else {
  1105. if(bool)
  1106. me.FormUtil.onSubmit(Ext.getCmp('pp_id').value);
  1107. }
  1108. },
  1109. /**
  1110. * 拿到grid里面要提交的数据
  1111. */
  1112. getGridStoreDet: function(grid){
  1113. if(grid == null){
  1114. grid = Ext.getCmp('grid');
  1115. }
  1116. var jsonGridData = new Array();
  1117. var form = Ext.getCmp('form');
  1118. var s = grid.getStore().data.items;//获取store里面的数据
  1119. var dd;
  1120. for(var i=0;i<s.length;i++){//将grid里面各行的数据获取并拼成jsonGridData
  1121. var data = s[i].data;
  1122. dd = new Object();
  1123. if(s[i].dirty && !grid.GridUtil.isBlank(grid, data)){
  1124. Ext.each(grid.columns, function(c){
  1125. if(c.logic != 'ignore'){//只需显示,无需后台操作的字段,自动略去
  1126. if(c.xtype == 'datecolumn'){
  1127. if(Ext.isDate(data[c.dataIndex])){
  1128. dd[c.dataIndex] = Ext.Date.toString(data[c.dataIndex]);//在这里把GMT日期转化成Y-m-d格式日期
  1129. } else {
  1130. dd[c.dataIndex] = Ext.Date.format(new Date(), 'Y-m-d');//如果用户没输入日期,或输入有误,就给个默认日期,
  1131. //或干脆return;并且提示一下用户
  1132. }
  1133. } else if(c.xtype == 'datetimecolumn'){
  1134. if(Ext.isDate(data[c.dataIndex])){
  1135. dd[c.dataIndex] = Ext.Date.format(data[c.dataIndex], 'Y-m-d H:i:s');//在这里把GMT日期转化成Y-m-d H:i:s格式日期
  1136. } else {
  1137. dd[c.dataIndex] = Ext.Date.format(new Date(), 'Y-m-d H:i:s');//默认日期,
  1138. }
  1139. } else if(c.xtype == 'numbercolumn'){//赋个默认值0吧,不然不好保存
  1140. if(data[c.dataIndex] == null || data[c.dataIndex] == ''){
  1141. dd[c.dataIndex] = '0';//也可以从data里面去掉这些字段
  1142. } else {
  1143. dd[c.dataIndex] = String(s[i].data[c.dataIndex]);
  1144. }
  1145. } else {
  1146. dd[c.dataIndex] = s[i].data[c.dataIndex];
  1147. }
  1148. }
  1149. });
  1150. if(grid.mainField){//例如,将pu_id的值赋给pd_puid
  1151. dd[grid.mainField] = this.ppdid;
  1152. }
  1153. jsonGridData.push(Ext.JSON.encode(dd));
  1154. }
  1155. }
  1156. return jsonGridData;
  1157. },
  1158. onUpdate:function(param1,param2){
  1159. var me = this;
  1160. var form =Ext.getCmp('form');
  1161. param1 = param1 == null ? [] : "[" + param1.toString() + "]";
  1162. param2 = param2 == null ? [] : "[" + param2.toString() + "]";
  1163. if(form.getForm().isValid()){
  1164. //form里面数据
  1165. Ext.each(form.items.items, function(item){
  1166. if(item.xtype == 'numberfield'){
  1167. //number类型赋默认值,不然sql无法执行
  1168. if(item.value == null || item.value == ''){
  1169. item.setValue(0);
  1170. }
  1171. }
  1172. });
  1173. var r = form.getValues();
  1174. if(!me.contains(form.updateUrl, '?caller=', true)){
  1175. form.updateUrl = form.updateUrl + "?caller=" + caller;
  1176. }
  1177. me.update(r, param1,param2);
  1178. }else{
  1179. me.checkForm();
  1180. }
  1181. },
  1182. onSave:function(param1,param2){
  1183. var me = this;
  1184. var form =Ext.getCmp('form');
  1185. param1 = param1 == null ? [] : "[" + param1.toString() + "]";
  1186. param2 = param2 == null ? [] : "[" + param2.toString() + "]";
  1187. if(form.getForm().isValid()){
  1188. //form里面数据
  1189. Ext.each(form.items.items, function(item){
  1190. if(item.xtype == 'numberfield'){
  1191. //number类型赋默认值,不然sql无法执行
  1192. if(item.value == null || item.value == ''){
  1193. item.setValue(0);
  1194. }
  1195. }
  1196. });
  1197. var r = form.getValues();
  1198. if(!me.contains(form.saveUrl, '?caller=', true)){
  1199. form.saveUrl = form.saveUrl + "?caller=" + caller;
  1200. }
  1201. me.save(r, param1,param2);
  1202. }else{
  1203. me.checkForm();
  1204. }
  1205. },
  1206. /*
  1207. * 修改
  1208. */
  1209. update:function(){
  1210. var params = new Object();
  1211. var r = arguments[0];
  1212. Ext.each(Ext.Object.getKeys(r), function(k){//去掉页面非表单定义字段
  1213. if(contains(k, 'ext-', true)){
  1214. delete r[k];
  1215. }
  1216. });
  1217. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  1218. params.param1 = unescape(arguments[1].toString().replace(/\\/g,"%"));
  1219. for(var i=2; i<arguments.length; i++) { //兼容多参数
  1220. params['param' + i] = unescape(arguments[i].toString().replace(/\\/g,"%"));
  1221. }
  1222. var me = this;
  1223. var form = Ext.getCmp('form');
  1224. me.getActiveTab().setLoading(true);//loading...
  1225. Ext.Ajax.request({
  1226. url : basePath + form.updateUrl,
  1227. params : params,
  1228. method : 'post',
  1229. callback : function(options,success,response){
  1230. me.getActiveTab().setLoading(false);
  1231. var localJson = new Ext.decode(response.responseText);
  1232. if(localJson.success){
  1233. saveSuccess(function(){
  1234. //add成功后刷新页面进入可编辑的页面
  1235. var value = r[form.keyField];
  1236. var formCondition = form.keyField + "IS" + value ;
  1237. if(me.contains(window.location.href, '?', true)){
  1238. window.location.href = window.location.href + '&formCondition=' +
  1239. formCondition;
  1240. } else {
  1241. window.location.href = window.location.href + '?formCondition=' +
  1242. formCondition;
  1243. }
  1244. });
  1245. } else if(localJson.exceptionInfo){
  1246. var str = localJson.exceptionInfo;
  1247. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  1248. str = str.replace('AFTERSUCCESS', '');
  1249. saveSuccess(function(){
  1250. //add成功后刷新页面进入可编辑的页面
  1251. var value = r[form.keyField];
  1252. var formCondition = form.keyField + "IS" + value ;
  1253. if(me.contains(window.location.href, '?', true)){
  1254. window.location.href = window.location.href + '&formCondition=' +
  1255. formCondition;
  1256. } else {
  1257. window.location.href = window.location.href + '?formCondition=' +
  1258. formCondition;
  1259. }
  1260. });
  1261. showError(str);
  1262. } else {
  1263. showError(str);
  1264. return;
  1265. }
  1266. } else{
  1267. saveFailure();//@i18n/i18n.js
  1268. }
  1269. }
  1270. });
  1271. },
  1272. /**
  1273. * 保存
  1274. */
  1275. save: function(){
  1276. var params = new Object();
  1277. var r = arguments[0];
  1278. Ext.each(Ext.Object.getKeys(r), function(k){//去掉页面非表单定义字段
  1279. if(contains(k, 'ext-', true)){
  1280. delete r[k];
  1281. }
  1282. });
  1283. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  1284. params.param1 = unescape(arguments[1].toString().replace(/\\/g,"%"));
  1285. for(var i=2; i<arguments.length; i++) { //兼容多参数
  1286. params['param' + i] = unescape(arguments[i].toString().replace(/\\/g,"%"));
  1287. }
  1288. var me = this;
  1289. var form = Ext.getCmp('form');
  1290. me.getActiveTab().setLoading(true);//loading...
  1291. Ext.Ajax.request({
  1292. url : basePath + form.saveUrl,
  1293. params : params,
  1294. method : 'post',
  1295. callback : function(options,success,response){
  1296. me.getActiveTab().setLoading(false);
  1297. var localJson = new Ext.decode(response.responseText);
  1298. if(localJson.success){
  1299. saveSuccess(function(){
  1300. //add成功后刷新页面进入可编辑的页面
  1301. var value = r[form.keyField];
  1302. var formCondition = form.keyField + "IS" + value ;
  1303. if(me.contains(window.location.href, '?', true)){
  1304. window.location.href = window.location.href + '&formCondition=' +
  1305. formCondition;
  1306. } else {
  1307. window.location.href = window.location.href + '?formCondition=' +
  1308. formCondition;
  1309. }
  1310. });
  1311. } else if(localJson.exceptionInfo){
  1312. var str = localJson.exceptionInfo;
  1313. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  1314. str = str.replace('AFTERSUCCESS', '');
  1315. saveSuccess(function(){
  1316. //add成功后刷新页面进入可编辑的页面
  1317. var value = r[form.keyField];
  1318. var formCondition = form.keyField + "IS" + value ;
  1319. if(me.contains(window.location.href, '?', true)){
  1320. window.location.href = window.location.href + '&formCondition=' +
  1321. formCondition;
  1322. } else {
  1323. window.location.href = window.location.href + '?formCondition=' +
  1324. formCondition;
  1325. }
  1326. });
  1327. showError(str);
  1328. } else {
  1329. showError(str);
  1330. return;
  1331. }
  1332. } else{
  1333. saveFailure();//@i18n/i18n.js
  1334. }
  1335. }
  1336. });
  1337. },
  1338. getActiveTab: function(){
  1339. var tab = null;
  1340. if(Ext.getCmp("content-panel")){
  1341. tab = Ext.getCmp("content-panel").getActiveTab();
  1342. }
  1343. if(!tab && parent.Ext.getCmp("content-panel"))
  1344. tab = parent.Ext.getCmp("content-panel").getActiveTab();
  1345. if(!tab && parent.parent.Ext.getCmp("content-panel"))
  1346. tab = parent.parent.Ext.getCmp("content-panel").getActiveTab();
  1347. if(!tab){
  1348. var win = parent.Ext.ComponentQuery.query('window');
  1349. if(win.length > 0){
  1350. tab = win[win.length-1];
  1351. }
  1352. }
  1353. return tab;
  1354. },
  1355. /**
  1356. * string:原始字符串
  1357. * substr:子字符串
  1358. * isIgnoreCase:忽略大小写
  1359. */
  1360. contains: function(string,substr,isIgnoreCase){
  1361. if(isIgnoreCase){
  1362. string=string.toLowerCase();
  1363. substr=substr.toLowerCase();
  1364. }
  1365. var startChar=substr.substring(0,1);
  1366. var strLen=substr.length;
  1367. for(var j=0;j<string.length-strLen+1;j++){
  1368. if(string.charAt(j)==startChar){//如果匹配起始字符,开始查找
  1369. if(string.substring(j,j+strLen)==substr){//如果从j开始的字符与str匹配,那ok
  1370. return true;
  1371. }
  1372. }
  1373. }
  1374. return false;
  1375. }
  1376. });