SaleProject.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.scm.sale.SaleProject', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. BaseUtil: Ext.create('erp.util.BaseUtil'),
  6. views:[
  7. 'scm.sale.SaleProject','core.form.Panel','core.form.MultiField',
  8. 'core.button.Add','core.button.Save','core.button.Update','core.button.Delete','core.button.Submit','core.button.ResSubmit',
  9. 'core.button.Audit','core.button.ResAudit','core.button.Close','core.button.TurnSale','core.form.FileField',
  10. 'core.trigger.TextAreaTrigger','core.trigger.DbfindTrigger','core.form.YnField','core.form.CheckBoxGroup','core.form.CheckBoxContainer',
  11. 'core.form.RadioGroup','core.form.SplitTextField','core.grid.ItemGrid','core.button.TurnProject','core.form.FileField'
  12. ],
  13. init:function(){
  14. var me = this;
  15. this.control({
  16. // 'erpFormPanel': {
  17. // afterrender: function(){
  18. // var panel = parent.Ext.getCmp('tree-tab');
  19. // if(panel && !panel.collapsed) {
  20. // panel.toggleCollapse();
  21. // }
  22. // }
  23. // },
  24. 'erpTurnProject':{
  25. afterrender:function(btn){
  26. var status = Ext.getCmp('sp_statuscode');
  27. if(status && status.value != 'AUDITED'){
  28. btn.hide();
  29. }
  30. },
  31. click: function(btn){
  32. warnMsg("确定要转入立项申请吗?", function(btn){
  33. if(btn == 'yes'){
  34. Ext.Ajax.request({
  35. url: basePath + 'scm/sale/turnProject.action',
  36. params: {
  37. id:Ext.getCmp('sp_id').getValue()
  38. },
  39. waitMsg: '转单中...',
  40. method: 'post',
  41. callback: function(options, success, response) {
  42. var localJson = new Ext.decode(response.responseText);
  43. if (localJson.success) {
  44. turnSuccess(function() {
  45. //add成功后刷新页面进入可编辑的页面
  46. // this.loadSplitData(originaldetno, said, record);
  47. if(localJson.clickurl){
  48. // showError(localJson.clickurl);
  49. window.location.reload();
  50. }
  51. });
  52. } else if (localJson.exceptionInfo) {
  53. showError(localJson.exceptionInfo);
  54. } else {
  55. saveFailure();
  56. }
  57. }
  58. });
  59. }
  60. });
  61. }
  62. },
  63. 'erpSaveButton': {
  64. click: function(btn){
  65. var form = me.getForm(btn);
  66. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  67. me.BaseUtil.getRandomNumber(); //自动添加编号
  68. }
  69. // me.beforeSave(form);
  70. this.FormUtil.beforeSave(this);
  71. }
  72. },
  73. 'erpDeleteButton' : {
  74. afterrender: function(btn){
  75. var status = Ext.getCmp('sp_statuscode');
  76. if(status && status.value != 'ENTERING'){
  77. btn.hide();
  78. }
  79. },
  80. click: function(btn){
  81. me.FormUtil.onDelete(Ext.getCmp('sp_id').value);
  82. }
  83. },
  84. 'erpUpdateButton': {
  85. afterrender: function(btn){
  86. var status = Ext.getCmp('sp_statuscode');
  87. if(status && status.value != 'ENTERING'){
  88. btn.hide();
  89. }
  90. },
  91. click: function(btn){
  92. me.onUpdate(this);
  93. }
  94. },
  95. 'erpAddButton': {
  96. click: function(){
  97. me.FormUtil.onAdd('addSaleProject', '新增订单评审', 'jsps/scm/sale/saleProject.jsp');
  98. }
  99. },
  100. 'erpCloseButton': {
  101. click: function(btn){
  102. me.FormUtil.beforeClose(me);
  103. }
  104. },
  105. 'erpSubmitButton': {
  106. afterrender: function(btn){
  107. var status = Ext.getCmp('sp_statuscode');
  108. if(status && status.value != 'ENTERING'){
  109. btn.hide();
  110. }
  111. },
  112. click: function(btn){
  113. me.onSubmit(Ext.getCmp('sp_id').value);
  114. }
  115. },
  116. 'erpResSubmitButton': {
  117. afterrender: function(btn){
  118. var status = Ext.getCmp('sp_statuscode');
  119. if(status && status.value != 'COMMITED'){
  120. btn.hide();
  121. }
  122. },
  123. click: function(btn){
  124. me.FormUtil.onResSubmit(Ext.getCmp('sp_id').value);
  125. }
  126. },
  127. 'erpAuditButton': {
  128. afterrender: function(btn){
  129. var status = Ext.getCmp('sp_statuscode');
  130. if(status && status.value != 'COMMITED'){
  131. btn.hide();
  132. }
  133. },
  134. click: function(btn){
  135. me.FormUtil.onAudit(Ext.getCmp('sp_id').value);
  136. }
  137. },
  138. 'erpResAuditButton': {
  139. afterrender: function(btn){
  140. var status = Ext.getCmp('sp_statuscode');
  141. if(status && status.value != 'AUDITED'){
  142. btn.hide();
  143. }
  144. },
  145. click: function(btn){
  146. me.FormUtil.onResAudit(Ext.getCmp('sp_id').value);
  147. }
  148. },
  149. // 'dbfindtrigger[name=ps_address]': {
  150. // afterrender:function(trigger){
  151. // trigger.dbKey='ps_custcode';
  152. // trigger.mappingKey='cu_code';
  153. // trigger.dbMessage='请先选客户编号!';
  154. // }
  155. // },
  156. 'combo[name=ps_type]': {
  157. delay: 200,
  158. change: function(m){
  159. this.hidecolumns(m);
  160. }
  161. }
  162. });
  163. },
  164. getForm: function(btn){
  165. return btn.ownerCt.ownerCt;
  166. },
  167. /**
  168. * 单据保存
  169. * @param param 传递过来的数据,比如gridpanel的数据
  170. */
  171. onSave: function(param){
  172. var me = this;
  173. var form = Ext.getCmp('form');
  174. if(form.getForm().isValid()){
  175. //form里面数据
  176. Ext.each(form.items.items, function(item){
  177. if(item.xtype == 'numberfield'){
  178. //number类型赋默认值,不然sql无法执行
  179. if(item.value == null || item.value == ''){
  180. item.setValue(0);
  181. }
  182. }
  183. });
  184. var r = form.getValues();
  185. //去除ignore字段
  186. var keys = Ext.Object.getKeys(r), f;
  187. var reg = /[!@#$%^&*()'":,\/?]/;
  188. Ext.each(keys, function(k){
  189. f = form.down('#' + k);
  190. if(f && f.logic == 'ignore') {
  191. delete r[k];
  192. }
  193. //codeField值强制大写,自动过滤特殊字符
  194. if(k == form.codeField && !Ext.isEmpty(r[k])) {
  195. r[k] = r[k].trim().toUpperCase().replace(reg, '');
  196. }
  197. });
  198. if(!me.FormUtil.contains(form.saveUrl, '?caller=', true)){
  199. form.saveUrl = form.saveUrl + "?caller=" + caller;
  200. }
  201. me.save(r, param);
  202. }else{
  203. me.FormUtil.checkForm();
  204. }
  205. },
  206. save: function(){
  207. var params = new Object();
  208. var r = arguments[0];
  209. Ext.each(Ext.Object.getKeys(r), function(k){//去掉页面非表单定义字段
  210. if(contains(k, 'ext-', true)){
  211. delete r[k];
  212. }
  213. });
  214. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  215. var me = this;
  216. var form = Ext.getCmp('form');
  217. me.FormUtil.setLoading(true);
  218. Ext.Ajax.request({
  219. url : basePath + form.saveUrl,
  220. params : params,
  221. method : 'post',
  222. callback : function(options,success,response){
  223. me.FormUtil.setLoading(false);
  224. var localJson = new Ext.decode(response.responseText);
  225. if(localJson.success){
  226. saveSuccess(function(){
  227. //add成功后刷新页面进入可编辑的页面
  228. var value = r[form.keyField];
  229. var formCondition = form.keyField + "IS" + value ;
  230. var gridCondition = '';
  231. if(me.FormUtil.contains(window.location.href, '?', true)){
  232. window.location.href = window.location.href + '&formCondition=' +
  233. formCondition + '&gridCondition=' + gridCondition;
  234. } else {
  235. window.location.href = window.location.href + '?formCondition=' +
  236. formCondition + '&gridCondition=' + gridCondition;
  237. }
  238. });
  239. } else if(localJson.exceptionInfo){
  240. var str = localJson.exceptionInfo;
  241. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  242. str = str.replace('AFTERSUCCESS', '');
  243. saveSuccess(function(){
  244. //add成功后刷新页面进入可编辑的页面
  245. var value = r[form.keyField];
  246. var formCondition = form.keyField + "IS" + value ;
  247. var gridCondition = '';
  248. if(me.FormUtil.contains(window.location.href, '?', true)){
  249. window.location.href = window.location.href + '&formCondition=' +
  250. formCondition + '&gridCondition=' + gridCondition;
  251. } else {
  252. window.location.href = window.location.href + '?formCondition=' +
  253. formCondition + '&gridCondition=' + gridCondition;
  254. }
  255. });
  256. showError(str);
  257. } else {
  258. showError(str);
  259. return;
  260. }
  261. } else{
  262. saveFailure();//@i18n/i18n.js
  263. }
  264. }
  265. });
  266. },
  267. /**
  268. * 检查form未完善的字段
  269. */
  270. checkForm: function(){
  271. var s = '';
  272. var form = Ext.getCmp('form');
  273. form.getForm().getFields().each(function (item, index, length){
  274. if(!item.isValid()){
  275. if(s != ''){
  276. s += ',';
  277. }
  278. if(item.fieldLabel || item.ownerCt.fieldLabel){
  279. s += item.fieldLabel || item.ownerCt.fieldLabel;
  280. }
  281. }
  282. });
  283. if(s == ''){
  284. return true;
  285. }
  286. showError($I18N.common.form.necessaryInfo1 + '(<font color=green>' + s.replace(/&nbsp;/g,'') +
  287. '</font>)' + $I18N.common.form.necessaryInfo2);
  288. return false;
  289. },
  290. /**
  291. * 单据修改
  292. * @param form formpanel表
  293. * @param param 传递过来的数据,比如gridpanel的数据
  294. */
  295. onUpdate: function(me){
  296. var mm = this;
  297. var form = Ext.getCmp('form');
  298. // var s1 = mm.checkFormDirty(form);
  299. var s2 = '';
  300. var grids = Ext.ComponentQuery.query('gridpanel');
  301. var removea = new Array();
  302. Ext.each(grids,function(g,index){
  303. if(g.xtype=='itemgrid'){
  304. g.updateValue();
  305. removea.push(g);
  306. }
  307. });
  308. Ext.each(removea,function(r,index){
  309. Ext.Array.remove(grids,r);
  310. });
  311. if(grids.length > 0){//check所有grid是否已修改
  312. Ext.each(grids, function(grid, index){
  313. if(grid.GridUtil){
  314. var msg = grid.GridUtil.checkGridDirty(grid);
  315. if(msg.length > 0){
  316. s2 = s2 + '<br/>' + grid.GridUtil.checkGridDirty(grid);
  317. }
  318. }
  319. });
  320. }
  321. if(form && form.getForm().isValid()){
  322. //form里面数据
  323. var r = form.getValues(false, true);
  324. //去除ignore字段
  325. var keys = Ext.Object.getKeys(r), f;
  326. Ext.each(keys, function(k){
  327. f = form.down('#' + k);
  328. if(f && f.logic == 'ignore') {
  329. delete r[k];
  330. }
  331. });
  332. if(!mm.FormUtil.contains(form.updateUrl, '?caller=', true)){
  333. form.updateUrl = form.updateUrl + "?caller=" + caller;
  334. }
  335. var params = [];
  336. if(grids.length > 0){
  337. var param = grids[0].GridUtil.getGridStore();
  338. if(grids[0].necessaryField.length > 0 && (param == null || param == '')){
  339. warnMsg('明细表还未添加数据,是否继续?', function(btn){
  340. if(btn == 'yes'){
  341. params = unescape("[" + param.toString().replace(/\\/g,"%") + "]");
  342. } else {
  343. return;
  344. }
  345. });
  346. } else {
  347. params = unescape("[" + param.toString().replace(/\\/g,"%") + "]");
  348. }
  349. }
  350. mm.update(r, params);
  351. }else{
  352. mm.checkForm(form);
  353. }
  354. },
  355. update: function(){
  356. var me = this, params = new Object();
  357. var r = arguments[0];
  358. Ext.each(Ext.Object.getKeys(r), function(k){//去掉页面非表单定义字段
  359. if(contains(k, 'ext-', true)){
  360. delete r[k];
  361. }
  362. });
  363. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  364. params.param = unescape(arguments[1].toString().replace(/\\/g,"%"));
  365. for(var i=2; i<arguments.length; i++) { //兼容多参数
  366. params['param' + i] = unescape(arguments[i].toString().replace(/\\/g,"%"));
  367. }
  368. var form = Ext.getCmp('form');
  369. me.FormUtil.setLoading(true);//loading...
  370. Ext.Ajax.request({
  371. url : basePath + form.updateUrl,
  372. params: params,
  373. method : 'post',
  374. callback : function(options,success,response){
  375. me.FormUtil.setLoading(false);
  376. var localJson = new Ext.decode(response.responseText);
  377. if(localJson.success){
  378. showMessage('提示', '保存成功!', 1000);
  379. //update成功后刷新页面进入可编辑的页面
  380. var u = String(window.location.href);
  381. if (u.indexOf('formCondition') == -1) {
  382. var value = r[form.keyField];
  383. var formCondition = form.keyField + "IS" + value ;
  384. var gridCondition = '';
  385. var grid = Ext.getCmp('grid');
  386. if(grid && grid.mainField){
  387. gridCondition = grid.mainField + "IS" + value;
  388. }
  389. if(me.FormUtil.contains(window.location.href, '?', true)){
  390. window.location.href = window.location.href + '&formCondition=' +
  391. formCondition + '&gridCondition=' + gridCondition;
  392. } else {
  393. window.location.href = window.location.href + '?formCondition=' +
  394. formCondition + '&gridCondition=' + gridCondition;
  395. }
  396. } else {
  397. window.location.reload();
  398. }
  399. } else if(localJson.exceptionInfo){
  400. var str = localJson.exceptionInfo;
  401. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  402. str = str.replace('AFTERSUCCESS', '');
  403. //update成功后刷新页面进入可编辑的页面
  404. var u = String(window.location.href);
  405. if (u.indexOf('formCondition') == -1) {
  406. var value = r[form.keyField];
  407. var formCondition = form.keyField + "IS" + value ;
  408. var gridCondition = '';
  409. var grid = Ext.getCmp('grid');
  410. if(grid && grid.mainField){
  411. gridCondition = grid.mainField + "IS" + value;
  412. }
  413. if(me.FormUtil.contains(window.location.href, '?', true)){
  414. window.location.href = window.location.href + '&formCondition=' +
  415. formCondition + '&gridCondition=' + gridCondition;
  416. } else {
  417. window.location.href = window.location.href + '?formCondition=' +
  418. formCondition + '&gridCondition=' + gridCondition;
  419. }
  420. } else {
  421. window.location.reload();
  422. }
  423. }
  424. showError(str);return;
  425. } else {
  426. updateFailure();
  427. }
  428. }
  429. });
  430. },
  431. /**
  432. * @param allowEmpty 是否允许Grid为空
  433. */
  434. onSubmit: function(id, allowEmpty){
  435. var me = this;
  436. var form = Ext.getCmp('form');
  437. if(form && form.getForm().isValid()){
  438. // var s = '';
  439. var grids = Ext.ComponentQuery.query('gridpanel');
  440. if(grids.length > 0){//check所有grid是否已修改
  441. var param = grids[0].GridUtil.getAllGridStore(grids[0]);
  442. if(grids[0].necessaryField && grids[0].necessaryField.length > 0 && (param == null || param == '') && (allowEmpty !== true)){
  443. showError("明细表还未添加数据,无法提交!");
  444. return;
  445. }
  446. Ext.each(grids, function(grid, index){
  447. if(grid.GridUtil){
  448. var msg = grid.GridUtil.checkGridDirty(grid);
  449. if(msg.length > 0){
  450. // s = s + '<br/>' + grid.GridUtil.checkGridDirty(grid);
  451. }
  452. }
  453. });
  454. }
  455. me.submit(id);
  456. } else {
  457. me.checkForm();
  458. }
  459. },
  460. submit: function(id){
  461. var me = this;
  462. var form = Ext.getCmp('form');
  463. if(!me.FormUtil.contains(form.submitUrl, '?caller=', true)){
  464. form.submitUrl = form.submitUrl + "?caller=" + caller;
  465. }
  466. me.FormUtil.setLoading(true);//loading...
  467. Ext.Ajax.request({
  468. url : basePath + form.submitUrl,
  469. params: {
  470. id: id
  471. },
  472. method : 'post',
  473. callback : function(options,success,response){
  474. me.FormUtil.setLoading(false);
  475. var localJson = new Ext.decode(response.responseText);
  476. if(localJson.success){
  477. //跳转之前 若节点指定多人则指定候选人
  478. Ext.Ajax.request({
  479. url : basePath + me.FormUtil.getMultiAssigns,
  480. params: {
  481. id: id,
  482. caller:caller
  483. },
  484. method : 'post',
  485. callback : function(options,success,response){
  486. var localJson = new Ext.decode(response.responseText);
  487. if(localJson.exceptionInfo){
  488. var str = localJson.exceptionInfo;
  489. showError(str);
  490. }else {
  491. if(localJson.MultiAssign){
  492. me.FormUtil.showAssignWin(localJson.assigns,localJson.nodeId);
  493. }else {
  494. showMessage('提示', '提交成功!', 1000);
  495. window.location.reload();
  496. }
  497. }
  498. }
  499. });
  500. //submit成功后刷新页面进入可编辑的页面
  501. } else {
  502. if(localJson.exceptionInfo){
  503. var str = localJson.exceptionInfo;
  504. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  505. str = str.replace('AFTERSUCCESS', '');
  506. Ext.Ajax.request({
  507. url : basePath + me.FormUtil.getMultiAssigns,
  508. params: {
  509. id: id,
  510. caller:caller
  511. },
  512. method : 'post',
  513. callback : function(options,success,response){
  514. var localJson = new Ext.decode(response.responseText);
  515. if(localJson.exceptionInfo){
  516. var str = localJson.exceptionInfo;
  517. showError(str);
  518. }else {
  519. if(localJson.MultiAssign){
  520. me.FormUtil.showAssignWin(localJson.assigns,localJson.nodeId);
  521. }else {
  522. showMessage('提示', '提交成功!', 1000);
  523. window.location.reload();
  524. }
  525. }
  526. }
  527. });
  528. }
  529. showMessage("提示", str);return;
  530. }
  531. }
  532. }
  533. });
  534. }
  535. });