ProjectEvaluation.js 17 KB

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