PreRec.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.ars.PreRec', {
  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. views:[
  8. 'core.form.Panel','fa.ars.PreRec','core.grid.Panel2','core.toolbar.Toolbar', 'core.form.SeparNumber',
  9. 'core.button.Save','core.button.Add','core.button.Close','core.button.Delete','core.button.Submit','core.button.ResAudit',
  10. 'core.button.Audit','core.button.ResSubmit','core.button.Post','core.button.ResPost','core.button.Update','core.button.DeleteDetail',
  11. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.button.ResAccounted','core.button.AssMain','core.button.Accounted','core.button.StrikeBalance',
  12. 'core.trigger.CateTreeDbfindTrigger','core.trigger.HrOrgTreeDbfindTrigger','core.button.Print','core.button.AssDetail','core.button.GetSumAmount', 'core.form.SeparNumber'
  13. ],
  14. init:function(){
  15. var me = this;
  16. me.gridLastSelected = null;
  17. this.control({
  18. 'erpGridPanel2': {
  19. itemclick:function(selModel, record){
  20. me.onGridItemClick(selModel, record);
  21. var btn = Ext.getCmp('assdetail');
  22. var ass = record.data['ca_asstype'];
  23. if(!Ext.isEmpty(ass)){
  24. btn.setDisabled(false);
  25. } else {
  26. btn.setDisabled(true);
  27. }
  28. }
  29. },
  30. 'field[name=pr_currency]': {
  31. beforetrigger: function(field) {
  32. var t = field.up('form').down('field[name=pr_date]'),
  33. value = t.getValue();
  34. if(value) {
  35. field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
  36. }
  37. }
  38. },
  39. 'erpGetSumAmountButton':{
  40. click: function(btn){
  41. var grid = Ext.getCmp("grid"),items = grid.store.data.items;
  42. var detailamount1 = 0;
  43. Ext.each(items,function(item,index){
  44. if(!me.GridUtil.isBlank(grid,item.data)) {
  45. detailamount1 = detailamount1 + Number(item.data['prd_nowbalance']);
  46. }
  47. });
  48. Ext.getCmp("pr_amount").setValue(detailamount1);
  49. Ext.getCmp("pr_cmamount").setValue(detailamount1);
  50. }
  51. },
  52. 'erpAssMainButton':{
  53. afterrender:function(btn){
  54. if(Ext.getCmp('ca_asstype').getValue()==null||Ext.getCmp('ca_asstype').getValue()==""){
  55. btn.setDisabled(true);
  56. }else{
  57. btn.setDisabled(false);
  58. }
  59. }
  60. },
  61. 'erpSaveButton': {
  62. click: function(btn){
  63. var form = me.getForm(btn);
  64. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  65. me.BaseUtil.getRandomNumber('PreRec');
  66. }
  67. me.getJsamount();
  68. //保存之前的一些前台的逻辑判定
  69. this.beforeSaveAccountRegister();
  70. }
  71. },
  72. 'erpDeleteDetailButton': {
  73. afterrender: function(btn){
  74. //辅助核算
  75. btn.ownerCt.add({
  76. xtype:'erpAssDetailButton',
  77. disabled:true
  78. });
  79. }
  80. },
  81. 'field[name=pr_amount]':{
  82. beforerender: function(field){
  83. if(Ext.getCmp('pr_source')&&Ext.getCmp('pr_source').value!=""){
  84. field.readOnly=true;
  85. }
  86. }
  87. },
  88. 'erpDeleteButton' : {
  89. click: function(btn){
  90. var source = Ext.getCmp('pr_source');
  91. if(source && source.value){
  92. showError("请在来源:"+source.value+",单号:"+Ext.getCmp('pr_sourcecode').value+"中进行反审核或者反记账操作!");
  93. return;
  94. }
  95. me.FormUtil.onDelete(Ext.getCmp('pr_id').value);
  96. }
  97. },
  98. 'erpPostButton' : {
  99. afterrender: function(btn){
  100. var status = Ext.getCmp('pr_statuscode');
  101. if(status && status.value != 'UNPOST'){
  102. btn.hide();
  103. }
  104. },
  105. click: function(btn){
  106. var amount = Number(Ext.getCmp('pr_amount').getValue());
  107. var cmamount =Number(Ext.getCmp('pr_cmamount').getValue());
  108. var cmcurrency = Ext.getCmp('pr_cmcurrency').getValue();
  109. var cmrate = Number(Ext.getCmp('pr_cmrate').getValue());
  110. var currency = Ext.getCmp('pr_currency').getValue();
  111. if(amount != 0 && cmamount != 0){
  112. if(Ext.Number.toFixed(cmrate, 8)!= Ext.Number.toFixed(cmamount/amount, 8)){
  113. showError('冲账汇率不正确,不能过账!');
  114. return;
  115. }
  116. }
  117. if(currency == cmcurrency){
  118. if(cmrate != 1){
  119. showError('币别相同,冲账汇率不等于1,不能过账!');
  120. return;
  121. }
  122. }
  123. if(currency != cmcurrency){
  124. if(cmrate == 1){
  125. showError('币别不相同,冲账汇率等于1,不能过账!');
  126. return;
  127. }
  128. }
  129. me.FormUtil.onPost(Ext.getCmp('pr_id').value);
  130. }
  131. },
  132. 'erpResPostButton' : {
  133. afterrender: function(btn){
  134. var status = Ext.getCmp('pr_statuscode');
  135. if(status && status.value != 'POSTED'){
  136. btn.hide();
  137. }
  138. },
  139. click: function(btn){
  140. me.FormUtil.onResPost(Ext.getCmp('pr_id').value);
  141. }
  142. },
  143. 'erpUpdateButton': {
  144. click: function(btn){
  145. me.getJsamount();
  146. me.beforeUpdate();
  147. }
  148. },
  149. 'erpAddButton': {
  150. click: function(){
  151. var form = Ext.getCmp('form');
  152. var title = '新增';
  153. if(form){
  154. if(form.title){
  155. title = title+form.title;
  156. }
  157. }
  158. me.FormUtil.onAdd('addPreRec', title, 'jsps/fa/ars/preRec.jsp?whoami='+caller);
  159. }
  160. },
  161. 'erpCloseButton': {
  162. click: function(btn){
  163. me.FormUtil.beforeClose(me);
  164. }
  165. },
  166. 'erpSubmitButton': {
  167. afterrender: function(btn){
  168. var status = Ext.getCmp(me.getForm(btn).statuscodeField),
  169. poststatus = Ext.getCmp('pr_statuscode');
  170. if(status && status.value != 'ENTERING'){
  171. btn.hide();
  172. }
  173. if(poststatus && poststatus.value == 'POSTED'){
  174. btn.hide();
  175. }
  176. },
  177. click: function(btn){
  178. var amount = Number(Ext.getCmp('pr_amount').getValue());
  179. var cmamount =Number(Ext.getCmp('pr_cmamount').getValue());
  180. var cmcurrency = Ext.getCmp('pr_cmcurrency').getValue();
  181. var cmrate = Number(Ext.getCmp('pr_cmrate').getValue());
  182. var currency = Ext.getCmp('pr_currency').getValue();
  183. if(amount != 0 && cmamount != 0){
  184. if(Ext.Number.toFixed(cmrate, 8)!= Ext.Number.toFixed(cmamount/amount, 8)){
  185. showError('冲账汇率不正确,不能提交!');
  186. return;
  187. }
  188. }
  189. if(currency == cmcurrency){
  190. if(cmrate != 1){
  191. showError('币别相同,冲账汇率不等于1,不能提交!');
  192. return;
  193. }
  194. }
  195. if(currency != cmcurrency){
  196. if(cmrate == 1){
  197. showError('币别不相同,冲账汇率等于1,不能提交!');
  198. return;
  199. }
  200. }
  201. me.onSubmit(Ext.getCmp('pr_id').value);
  202. }
  203. },
  204. 'erpResSubmitButton': {
  205. afterrender: function(btn){
  206. var status = Ext.getCmp(me.getForm(btn).statuscodeField),
  207. poststatus = Ext.getCmp('pr_statuscode');
  208. if(status && status.value != 'COMMITED'){
  209. btn.hide();
  210. }
  211. if(poststatus && poststatus.value == 'POSTED'){
  212. btn.hide();
  213. }
  214. },
  215. click: function(btn){
  216. me.FormUtil.onResSubmit(Ext.getCmp('pr_id').value);
  217. }
  218. },
  219. 'erpAuditButton': {
  220. afterrender: function(btn){
  221. var status = Ext.getCmp(me.getForm(btn).statuscodeField),
  222. poststatus = Ext.getCmp('pr_statuscode');
  223. if(status && status.value != 'COMMITED'){
  224. btn.hide();
  225. }
  226. if(poststatus && poststatus.value == 'POSTED'){
  227. btn.hide();
  228. }
  229. },
  230. click: function(btn){
  231. me.FormUtil.onAudit(Ext.getCmp('pr_id').value);
  232. }
  233. },
  234. 'erpResAuditButton': {
  235. afterrender: function(btn){
  236. var status = Ext.getCmp(me.getForm(btn).statuscodeField),
  237. postStatus = Ext.getCmp('pr_statuscode');
  238. if((status && status.value != 'AUDITED') ||(postStatus && postStatus.value == 'POSTED')){
  239. btn.hide();
  240. }
  241. },
  242. click: function(btn){
  243. me.FormUtil.onResAudit(Ext.getCmp('pr_id').value);
  244. }
  245. },
  246. 'erpPrintButton': {
  247. click: function(btn){
  248. me.FormUtil.onPrint(Ext.getCmp('pr_id').value);
  249. }
  250. },
  251. 'textfield[name=pr_amount]':{
  252. change: me.changeCmamount
  253. },
  254. 'textfield[name=pr_cmrate]':{
  255. change: me.changeCmamount
  256. },
  257. 'cateTreeDbfindTrigger[name=pr_accountcode]':{
  258. aftertrigger:function(trigger, data){
  259. Ext.getCmp('pr_accountname').setValue(data[0].raw.data.ca_name);
  260. var asstype = data[0].raw.data.ca_asstype;
  261. var btn = Ext.getCmp("assmainbutton");
  262. if(Ext.isEmpty(asstype)){
  263. btn.setDisabled(true);
  264. }else{
  265. btn.setDisabled(false);
  266. }
  267. }
  268. },
  269. 'field[name=prd_ordercode]': {
  270. afterrender: function(t){
  271. t.gridKey="pr_custcode";
  272. t.mappinggirdKey="sa_apcustcode";
  273. t.gridErrorMessage="请先选择客户";
  274. }
  275. },
  276. 'textfield[name=pr_amount]':{
  277. change: function(){
  278. me.changeCmrateOrCmamount();
  279. }
  280. },
  281. 'textfield[name=pr_cmrate]':{
  282. change: function(){
  283. me.changeCmrateOrCmamount();
  284. }
  285. },
  286. 'textfield[name=pr_cmamount]':{
  287. change: function(){
  288. me.changeCmrateOrCmamount();
  289. }
  290. }/*,
  291. 'dbfindtrigger[name=pr_custcode]':{
  292. //pr_beginlast
  293. beforetrigger:function(t){
  294. if(caller =='PreRec!Ars!DEPR'){
  295. var dateField = Ext.getCmp('pr_date');
  296. var dateStr = dateField.rawValue; // 2013-03-19
  297. var s=dateStr.split('-');
  298. var config =''; //得到的月份其次 格式为 201303
  299. Ext.each(s,function(i,index){
  300. config=config+i+'';
  301. });
  302. if(config.length>6){
  303. config=config.substring(0,6);
  304. }
  305. // t.findConfig = " cu_code in (select distinct cm_custcode from custmonth where cm_yearmonth<='"+config+"' and cm_beginlast >0)";
  306. t.findConfig = " ca_prepayamount>0 and cu_auditstatuscode='AUDITED' group by cu_id,cu_code,cu_name,cu_sellerid,cu_sellername ";
  307. }
  308. }
  309. }*/
  310. });
  311. },
  312. changeCmrateOrCmamount: function () {
  313. var me = this;
  314. if(Ext.getCmp('pr_cmrate').readOnly){
  315. me.changeCmrate();
  316. }else{
  317. me.changeCmamount();
  318. }
  319. },
  320. changeCmrate:function () {
  321. if(Ext.getCmp('pr_cmamount')&&Ext.getCmp('pr_amount')&&Ext.getCmp('pr_cmrate')){
  322. var cmamount = Ext.getCmp('pr_cmamount').getValue();;
  323. var amount = Ext.getCmp('pr_amount').getValue();
  324. var rate = Number(cmamount/amount);
  325. rate = Ext.Number.toFixed(rate,8);
  326. Ext.getCmp('pr_cmrate').setValue(rate);
  327. }
  328. },
  329. //计算冲账金额 = 预收金额*冲账汇率
  330. changeCmamount:function(){
  331. if(Ext.getCmp('pr_amount')&&Ext.getCmp('pr_cmrate')){
  332. var pramount = Ext.getCmp('pr_amount').getValue();
  333. var prcmrate = Ext.getCmp('pr_cmrate').getValue();
  334. if(!Ext.isNumber(pramount)){
  335. pramount = Ext.Number.from(pramount,0);
  336. }
  337. if(!Ext.isNumber(prcmrate)){
  338. prcmrate = Ext.Number.from(prcmrate,0);
  339. }
  340. var cmamount = pramount*prcmrate;
  341. Ext.getCmp('pr_cmamount').setValue(Ext.util.Format.number(cmamount,'0.00'));
  342. }
  343. },
  344. onGridItemClick: function(selModel, record){//grid行选择
  345. this.gridLastSelected = record;
  346. var grid = Ext.getCmp('grid');
  347. if(record.data[grid.necessaryField] == null || record.data[grid.necessaryField] == ''){
  348. this.gridLastSelected.findable = true;//空数据可以在输入完code,并移开光标后,自动调出该条数据
  349. } else {
  350. this.gridLastSelected.findable = false;
  351. }
  352. this.GridUtil.onGridItemClick(selModel, record);
  353. },
  354. getForm: function(btn){
  355. return btn.ownerCt.ownerCt;
  356. },
  357. beforeSaveAccountRegister: function(){
  358. var me = this;
  359. var grid = Ext.getCmp('grid');
  360. var items = grid.store.data.items;
  361. var bool = true;
  362. var warnStr='';
  363. Ext.each(items,function(item,index){
  364. if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ''){
  365. var orderamount =item.data['prd_orderamount']; //订单金额
  366. var havebalance = item.data['sa_prepayamount']; //已预收金额prd_havebalance
  367. var nowbalance = item.data['prd_nowbalance']; //本次预收额
  368. //订单金额>=已预收金额+本次预收额
  369. //此种情况不能进行保存
  370. if(havebalance+nowbalance>orderamount){
  371. var i = index+1;
  372. if(warnStr ==''||warnStr.length<=0){
  373. warnStr = warnStr +i;
  374. }else{
  375. warnStr = warnStr +','+i;
  376. }
  377. bool = false;
  378. }
  379. }
  380. });
  381. if(bool){
  382. me.beforeSave(this);
  383. }else{
  384. if(warnStr != ''||warnStr.length>0){
  385. showError('明细表第'+warnStr+'行 已预收金额与本次预收额的合计超过订单金额,不能保存');return;
  386. }
  387. }
  388. },
  389. getJsamount: function(){
  390. var grid = Ext.getCmp('grid');
  391. var items = grid.store.data.items;
  392. var jsamount = 0;
  393. var detailcount = 0;
  394. var cateamount = 0;
  395. Ext.each(items,function(item,index){
  396. if(item.data['prd_catecode']!=null&&item.data['prd_catecode']!=""){
  397. cateamount = cateamount + Number(item.data['prd_nowbalance']);
  398. }
  399. });
  400. Ext.getCmp('pr_jsamount').setValue(Ext.Number.from(Ext.getCmp('pr_cmamount').getValue())-cateamount);
  401. },
  402. beforeSave:function(){
  403. var me = this;
  404. var form = Ext.getCmp('form');
  405. if(! me.FormUtil.checkForm()){
  406. return;
  407. }
  408. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  409. me.FormUtil.getSeqId(form);
  410. }
  411. var detail = Ext.getCmp('grid');
  412. var param2 = new Array();
  413. var param3 = new Array();
  414. if(Ext.getCmp('assdetail')){
  415. Ext.each(Ext.Object.getKeys(Ext.getCmp('assdetail').cacheStoreGrid), function(key){
  416. Ext.each(Ext.getCmp('assdetail').cacheStoreGrid[key], function(d){
  417. d['dass_condid'] = key;
  418. param2.push(d);
  419. });
  420. });
  421. }
  422. if(Ext.getCmp('assmainbutton')){
  423. Ext.each(Ext.Object.getKeys(Ext.getCmp('assmainbutton').cacheStoreForm), function(key){
  424. Ext.each(Ext.getCmp('assmainbutton').cacheStoreForm[key], function(d){
  425. d['ass_conid'] = key;
  426. param3.push(d);
  427. });
  428. });
  429. }
  430. Ext.each(detail.store.data.items, function(item){
  431. if(item.data.prd_id == null || item.data.prd_id == 0){
  432. item.data.prd_id = -item.index;
  433. }
  434. });
  435. var param1 = me.GridUtil.getGridStore(detail);
  436. if(detail.necessaryField.length > 0 && (param1.length == 0)){
  437. showError($I18N.common.grid.emptyDetail);
  438. return;
  439. }
  440. me.onSave(form, param1, param2,param3);
  441. },
  442. onSave: function(form, param1, param2,param3) {
  443. var me = this;
  444. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  445. param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
  446. param3 = param3 == null ? [] : Ext.encode(param3).replace(/\\/g,"%");
  447. if(form.getForm().isValid()){
  448. Ext.each(form.items.items, function(item){
  449. if(item.xtype == 'numberfield'){
  450. if(item.value == null || item.value == ''){
  451. item.setValue(0);
  452. }
  453. }
  454. });
  455. var r = form.getValues();
  456. form.getForm().getFields().each(function(){
  457. if(this.logic == 'ignore') {
  458. delete r[this.name];
  459. }
  460. });
  461. me.FormUtil.save(r, param1, param2,param3);
  462. }else{
  463. me.FormUtil.checkForm();
  464. }
  465. },
  466. beforeUpdate: function(){
  467. var me = this;
  468. var form = Ext.getCmp('form');
  469. if(! me.FormUtil.checkForm()){
  470. return;
  471. }
  472. var detail = Ext.getCmp('grid');
  473. Ext.each(detail.store.data.items, function(item){
  474. if(item.data.prd_id == null || item.data.prd_id == 0){
  475. item.data.prd_id = -item.index;
  476. }
  477. });
  478. var param1 = me.GridUtil.getGridStore(detail);
  479. var param2 = new Array();
  480. var param3 = new Array();
  481. if(Ext.getCmp('assdetail')){
  482. Ext.each(Ext.Object.getKeys(Ext.getCmp('assdetail').cacheStoreGrid), function(key){
  483. Ext.each(Ext.getCmp('assdetail').cacheStoreGrid[key], function(d){
  484. d['dass_condid'] = key;
  485. param2.push(d);
  486. });
  487. });
  488. }
  489. if(Ext.getCmp('assmainbutton')){
  490. Ext.each(Ext.Object.getKeys(Ext.getCmp('assmainbutton').cacheStoreForm), function(key){
  491. Ext.each(Ext.getCmp('assmainbutton').cacheStoreForm[key], function(d){
  492. d['ass_conid'] = key;
  493. param3.push(d);
  494. });
  495. });
  496. }
  497. if(me.FormUtil.checkFormDirty(form) == '' && detail.necessaryField.length > 0 && (param1.length == 0)
  498. && param2.length == 0&& param3.length == 0){
  499. showError($I18N.common.grid.emptyDetail);
  500. return;
  501. } else {
  502. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  503. param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
  504. param3 = param3 == null ? [] : Ext.encode(param3).replace(/\\/g,"%");
  505. if(form.getForm().isValid()){
  506. Ext.each(form.items.items, function(item){
  507. if(item.xtype == 'numberfield'){
  508. if(item.value == null || item.value == ''){
  509. item.setValue(0);
  510. }
  511. }
  512. });
  513. var r = form.getValues();
  514. form.getForm().getFields().each(function(){
  515. if(this.logic == 'ignore') {
  516. delete r[this.name];
  517. }
  518. });
  519. me.FormUtil.update(r, param1, param2,param3);
  520. }else{
  521. me.FormUtil.checkForm();
  522. }
  523. }
  524. },
  525. //提交时的相关操作开始
  526. checkFormDirty: function(){
  527. var form = Ext.getCmp('form');
  528. var s = '';
  529. form.getForm().getFields().each(function (item,index,length){
  530. var value = item.value == null ? "" : item.value;
  531. item.originalValue = item.originalValue == null ? "" : item.originalValue;
  532. if(item.originalValue.toString() != value.toString()){//isDirty、wasDirty、dirty一直都是true,没办法判断,所以直接用item.originalValue,原理是一样的
  533. var label = item.fieldLabel || item.ownerCt.fieldLabel ||
  534. item.boxLabel || item.ownerCt.title;//针对fieldContainer、radio、fieldset等
  535. if(label){
  536. s = s + '&nbsp;' + label.replace(/&nbsp;/g,'');
  537. }
  538. }
  539. });
  540. return (s == '') ? s : ('表单字段(<font color=green>'+s+'</font>)已修改');
  541. },
  542. onSubmit: function(id){
  543. var me = this;
  544. var form = Ext.getCmp('form');
  545. if(form && form.getForm().isValid()){
  546. var s = me.checkFormDirty(form);
  547. var grids = Ext.ComponentQuery.query('gridpanel');
  548. if(grids.length > 0){//check所有grid是否已修改
  549. var param = grids[0].GridUtil.getAllGridStore(grids[0]);
  550. // if(grids[0].necessaryField.length > 0 && (param == null || param == '')){
  551. // showError("明细表还未添加数据,无法提交!");
  552. // return;
  553. // }
  554. Ext.each(grids, function(grid, index){
  555. if(grid.GridUtil){
  556. var msg = grid.GridUtil.checkGridDirty(grid);
  557. if(msg.length > 0){
  558. s = s + '<br/>' + grid.GridUtil.checkGridDirty(grid);
  559. }
  560. }
  561. });
  562. }
  563. if(s == '' || s == '<br/>'){
  564. me.submit(id);
  565. } else {
  566. Ext.MessageBox.show({
  567. title:'保存修改?',
  568. msg: '该单据已被修改:<br/>' + s + '<br/>提交前要先保存吗?',
  569. buttons: Ext.Msg.YESNOCANCEL,
  570. icon: Ext.Msg.WARNING,
  571. fn: function(btn){
  572. if(btn == 'yes'){
  573. me.beforeUpdate(form);
  574. } else if(btn == 'no'){
  575. } else {
  576. return;
  577. }
  578. }
  579. });
  580. }
  581. } else {
  582. me.checkForm();
  583. }
  584. },
  585. contains: function(string,substr,isIgnoreCase){
  586. if(isIgnoreCase){
  587. string=string.toLowerCase();
  588. substr=substr.toLowerCase();
  589. }
  590. var startChar=substr.substring(0,1);
  591. var strLen=substr.length;
  592. for(var j=0;j<string.length-strLen+1;j++){
  593. if(string.charAt(j)==startChar){//如果匹配起始字符,开始查找
  594. if(string.substring(j,j+strLen)==substr){//如果从j开始的字符与str匹配,那ok
  595. return true;
  596. }
  597. }
  598. }
  599. return false;
  600. },
  601. getActiveTab: function(){
  602. var tab = null;
  603. if(Ext.getCmp("content-panel")){
  604. tab = Ext.getCmp("content-panel").getActiveTab();
  605. }
  606. if(!tab && parent.Ext.getCmp("content-panel"))
  607. tab = parent.Ext.getCmp("content-panel").getActiveTab();
  608. if(!tab && parent.parent.Ext.getCmp("content-panel"))
  609. tab = parent.parent.Ext.getCmp("content-panel").getActiveTab();
  610. if(!tab){
  611. var win = parent.Ext.ComponentQuery.query('window');
  612. if(win.length > 0){
  613. tab = win[win.length-1];
  614. }
  615. }
  616. return tab;
  617. },
  618. submit: function(id){
  619. var me = this;
  620. var form = Ext.getCmp('form');
  621. if(!me.contains(form.submitUrl, '?caller=', true)){
  622. form.submitUrl = form.submitUrl + "?caller=" + caller;
  623. }
  624. me.getActiveTab().setLoading(true);//loading...
  625. Ext.Ajax.request({
  626. url : basePath + form.submitUrl,
  627. params: {
  628. id: id
  629. },
  630. method : 'post',
  631. callback : function(options,success,response){
  632. me.getActiveTab().setLoading(false);
  633. var localJson = new Ext.decode(response.responseText);
  634. if(localJson.success){
  635. //submit成功后刷新页面进入可编辑的页面
  636. submitSuccess(function(){
  637. window.location.href = window.location.href;
  638. });
  639. } else {
  640. if(localJson.exceptionInfo){
  641. var str = localJson.exceptionInfo;
  642. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  643. str = str.replace('AFTERSUCCESS', '');
  644. submitSuccess(function(){
  645. var url = window.location.href;
  646. var formCondition = form.keyField + "IS" + id;
  647. var gridCondition = '';
  648. var grid = Ext.getCmp('grid');
  649. if(grid && grid.mainField){
  650. gridCondition = grid.mainField + "IS" + id;
  651. }
  652. if(me.contains(url, 'formCondition', true)){
  653. url = url.replace('formCondition', 1);
  654. url = url.replace('gridCondition', 1);
  655. }
  656. if(me.contains(url, '?', true)){
  657. url = url + '&formCondition=' +
  658. formCondition + '&gridCondition=' + gridCondition;
  659. } else {
  660. url = url + '?formCondition=' +
  661. formCondition + '&gridCondition=' + gridCondition;
  662. }
  663. window.location.href = url;
  664. });
  665. }
  666. showMessage("提示", str);return;
  667. }
  668. }
  669. }
  670. });
  671. }
  672. //提交时的相关操作结束
  673. // beforeUpdate: function(){
  674. // var grid = Ext.getCmp('grid');
  675. // Ext.Array.each(grid.store.data.items, function(item){
  676. // item.set('prd_prid',Ext.getCmp('pr_id').value);
  677. // });
  678. // //采购价格不能为0
  679. // var grid = Ext.getCmp('grid');
  680. // var items = grid.store.data.items;
  681. // var bool = true;
  682. // var warnStr='';
  683. // Ext.each(items,function(item,index){
  684. // if(item.dirty && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ''){
  685. // var orderamount =item.data['prd_orderamount']; //订单金额
  686. // var havebalance = item.data['sa_prepayamount']; //已预收金额
  687. // var nowbalance = item.data['prd_nowbalance']; //本次预收额
  688. // //订单金额>=已预收金额+本次预收额
  689. //
  690. // //此种情况不能进行保存
  691. // if(havebalance+nowbalance>orderamount){
  692. // var i = index+1;
  693. // if(warnStr ==''||warnStr.length<=0){
  694. // warnStr = warnStr +i;
  695. // }else{
  696. // warnStr = warnStr +','+i;
  697. // }
  698. // bool = false;
  699. // }
  700. // }
  701. //
  702. // });
  703. //
  704. // if(bool){
  705. // this.FormUtil.onUpdate(this);
  706. // }else{
  707. // if(warnStr != ''||warnStr.length>0){
  708. // showError('明细表第'+warnStr+'行 已预收金额与本次预收额的合计超过订单金额,不能保存');return;
  709. // }
  710. // }
  711. //
  712. // }
  713. });