SaleForecastAsk.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.drp.distribution.SaleForecastAsk', {
  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','drp.distribution.SaleForecastAsk','core.grid.Panel2','core.toolbar.Toolbar','core.form.MultiField',
  9. 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.Upload','core.button.ChangeDate',
  10. 'core.button.ResAudit','core.button.Scan','core.button.DeleteDetail','core.button.ResSubmit','core.button.FeatureDefinition',
  11. 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.End','core.button.ResEnd','core.button.Print',
  12. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField','core.grid.YnColumn','core.button.FeatureView','core.button.TurnSale'
  13. ],
  14. init:function(){
  15. var me = this;
  16. this.control({
  17. 'erpGridPanel2': {
  18. itemclick: function(selModel, record){
  19. Ext.getCmp('featuredefinition').setDisabled(false);
  20. Ext.getCmp('featureview').setDisabled(false);
  21. this.onGridItemClick
  22. }
  23. },
  24. 'erpChangeDateButton':{
  25. afterrender: function(btn){
  26. var status = Ext.getCmp('sf_statuscode');
  27. if(status && status.value != 'AUDITED'){
  28. btn.hide();
  29. }
  30. },
  31. click:function(btn){
  32. var keyvalue=Ext.getCmp('sf_id').value;
  33. var condition='sd_sfid='+keyvalue;
  34. var win = new Ext.window.Window({
  35. id : 'win',
  36. height: "100%",
  37. width: "80%",
  38. maximizable : true,
  39. buttonAlign : 'center',
  40. layout : 'anchor',
  41. items: [{
  42. tag : 'iframe',
  43. frame : true,
  44. anchor : '100% 100%',
  45. layout : 'fit',
  46. html : '<iframe id="iframe_' + caller + '" src="' + basePath + 'jsps/common/editorColumn.jsp?caller=SaleForecast!Change'
  47. +"&condition=" + condition +'" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  48. }],
  49. buttons : [{
  50. text : $I18N.common.button.erpConfirmButton,
  51. iconCls: 'x-button-icon-confirm',
  52. cls: 'x-btn-gray',
  53. handler : function(){
  54. var grid = Ext.getCmp('win').items.items[0].body.dom.getElementsByTagName('iframe')[0].contentWindow.Ext.getCmp("editorColumnGridPanel");
  55. var data = grid.getEffectData();
  56. if(data != null){
  57. grid.setLoading(true);
  58. Ext.Ajax.request({
  59. url : basePath + 'scm/sale/SaleForecastChangedate.action',
  60. params: {
  61. caller: caller,
  62. data: Ext.encode(data)
  63. },
  64. method : 'post',
  65. callback : function(options,success,response){
  66. grid.setLoading(false);
  67. var localJson = new Ext.decode(response.responseText);
  68. if(localJson.exceptionInfo){
  69. showError(localJson.exceptionInfo);
  70. return "";
  71. }
  72. if(localJson.success){
  73. if(localJson.log){
  74. showMessage("提示", localJson.log);
  75. }
  76. Ext.Msg.alert("提示", "处理成功!", function(){
  77. win.close();
  78. var detailgrid= Ext.getCmp('grid');
  79. gridParam = {caller: 'SaleForecast', condition: condition};
  80. me.GridUtil.getGridColumnsAndStore(detailgrid, 'common/singleGridPanel.action', gridParam, "")
  81. });
  82. }
  83. }
  84. });
  85. }
  86. }
  87. }, {
  88. text : $I18N.common.button.erpCloseButton,
  89. iconCls: 'x-button-icon-close',
  90. cls: 'x-btn-gray',
  91. handler : function(){
  92. Ext.getCmp('win').close();
  93. }
  94. }]
  95. });
  96. win.show();
  97. }
  98. },
  99. 'erpSaveButton': {
  100. click: function(btn){
  101. var form = me.getForm(btn);
  102. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  103. me.BaseUtil.getRandomNumber();//自动添加编号
  104. }
  105. this.beforeSaveSaleForecast(this);
  106. }
  107. },
  108. 'erpDeleteDetailButton': {
  109. afterrender: function(btn){
  110. btn.ownerCt.add({
  111. xtype: 'erpFeatureDefinitionButton'
  112. });
  113. btn.ownerCt.add({
  114. xtype: 'erpFeatureViewButton'
  115. });
  116. }
  117. },
  118. 'erpDeleteButton' : {
  119. click: function(btn){
  120. me.FormUtil.onDelete(Ext.getCmp('sf_id').value);
  121. }
  122. },
  123. 'erpUpdateButton': {
  124. click: function(btn){
  125. this.beforeUpdate(this);
  126. }
  127. },
  128. 'erpAddButton': {
  129. click: function(){
  130. me.FormUtil.onAdd('addSaleForecastAsk', '新增待确认销售预测单', 'jsps/drp/distribution/saleForecastAsk.jsp');
  131. }
  132. },
  133. 'erpCloseButton': {
  134. click: function(btn){
  135. me.FormUtil.beforeClose(me);
  136. }
  137. },
  138. 'erpSubmitButton': {
  139. afterrender: function(btn){
  140. var status = Ext.getCmp('sf_statuscode');
  141. if(status && status.value != 'ENTERING'){
  142. btn.hide();
  143. }
  144. },
  145. click: function(btn){
  146. me.FormUtil.onSubmit(Ext.getCmp('sf_id').value);
  147. }
  148. },
  149. 'erpResSubmitButton': {
  150. afterrender: function(btn){
  151. var status = Ext.getCmp('sf_statuscode');
  152. if(status && status.value != 'COMMITED'){
  153. btn.hide();
  154. }
  155. },
  156. click: function(btn){
  157. me.FormUtil.onResSubmit(Ext.getCmp('sf_id').value);
  158. }
  159. },
  160. 'erpAuditButton': {
  161. afterrender: function(btn){
  162. var status = Ext.getCmp('sf_statuscode');
  163. if(status && status.value != 'COMMITED'){
  164. btn.hide();
  165. }
  166. },
  167. click: function(btn){
  168. me.FormUtil.onAudit(Ext.getCmp('sf_id').value);
  169. }
  170. },
  171. 'erpResAuditButton': {
  172. afterrender: function(btn){
  173. var status = Ext.getCmp('sf_statuscode');
  174. if(status && status.value != 'AUDITED'){
  175. btn.hide();
  176. }
  177. },
  178. click: function(btn){
  179. me.FormUtil.onResAudit(Ext.getCmp('sf_id').value);
  180. }
  181. },
  182. 'erpPrintButton': {
  183. click:function(btn){
  184. var reportName="SaleForecastAudit1";
  185. var condition='{SaleForeCast.sf_id}='+Ext.getCmp('sf_id').value+'';
  186. var id=Ext.getCmp('sf_id').value;
  187. me.FormUtil.onwindowsPrint(id,reportName,condition);
  188. }
  189. },
  190. 'erpEndButton': {
  191. afterrender: function(btn){
  192. var status = Ext.getCmp('sf_statuscode');
  193. if(status && status.value != 'AUDITED'){
  194. btn.hide();
  195. }
  196. },
  197. click: function(btn){
  198. me.FormUtil.onEnd(Ext.getCmp('sf_id').value);
  199. }
  200. },
  201. 'erpResEndButton': {
  202. afterrender: function(btn){
  203. var status = Ext.getCmp('sf_statuscode');
  204. if(status && status.value != 'FINISH'){
  205. btn.hide();
  206. }
  207. },
  208. click: function(btn){
  209. me.FormUtil.onResEnd(Ext.getCmp('sf_id').value);
  210. }
  211. },
  212. 'erpFeatureDefinitionButton':{
  213. click: function(btn){
  214. var grid = Ext.getCmp('grid');
  215. var record = grid.selModel.lastSelected;
  216. console.log(record);
  217. if(record.data.sd_prodcode != null){
  218. Ext.Ajax.request({//拿到grid的columns
  219. url : basePath + "pm/bom/getDescription.action",
  220. params: {
  221. tablename: 'Product',
  222. field: 'pr_specvalue',
  223. condition: "pr_code='" + record.data.sd_prodcode + "'"
  224. },
  225. method : 'post',
  226. async: false,
  227. callback : function(options,success,response){
  228. var res = new Ext.decode(response.responseText);
  229. if(res.exceptionInfo){
  230. showError(res.exceptionInfo);return;
  231. }
  232. if(res.success){
  233. if(res.description != '' && res.description != null && res.description == 'SPECIFIC'){
  234. var win = new Ext.window.Window({
  235. id : 'win' + record.data.sd_id,
  236. title: '生成特征料号',
  237. height: "90%",
  238. width: "70%",
  239. maximizable : true,
  240. buttonAlign : 'center',
  241. layout : 'anchor',
  242. items: [{
  243. tag : 'iframe',
  244. frame : true,
  245. anchor : '100% 100%',
  246. layout : 'fit',
  247. html : '<iframe id="iframe_' + record.data.sd_id + '" src="' + basePath +
  248. "jsps/pm/bom/FeatureValueSet.jsp?fromwhere=SaleForecastDetail&condition=formidIS" + record.data.sd_id + ' AND pr_codeIS' + record.data.sd_prodcode + ' AND pr_nameIS' + record.data.pr_detail +'" height="100%" width="100%" frameborder="0" scrolling="yes"></iframe>'
  249. }]
  250. });
  251. win.show();
  252. } else {
  253. showError('物料特征必须为 虚拟特征件');return;
  254. }
  255. }
  256. }
  257. });
  258. }
  259. }
  260. },
  261. 'erpFeatureViewButton':{
  262. click: function(btn){
  263. var grid = Ext.getCmp('grid');
  264. var record = grid.selModel.lastSelected;
  265. console.log(record);
  266. if(record.data.sd_prodcode != null){
  267. Ext.Ajax.request({//拿到grid的columns
  268. url : basePath + "pm/bom/getDescription.action",
  269. params: {
  270. tablename: 'Product',
  271. field: 'pr_specvalue',
  272. condition: "pr_code='" + record.data.sd_prodcode + "'"
  273. },
  274. method : 'post',
  275. async: false,
  276. callback : function(options,success,response){
  277. var res = new Ext.decode(response.responseText);
  278. if(res.exceptionInfo){
  279. showError(res.exceptionInfo);return;
  280. }
  281. if(res.success){
  282. if(res.description != '' && res.description != null && res.description == 'NOTSPECIFIC'){
  283. var win = new Ext.window.Window({
  284. id : 'win' + record.data.sd_id,
  285. title: '特征查看',
  286. height: "90%",
  287. width: "70%",
  288. maximizable : true,
  289. buttonAlign : 'center',
  290. layout : 'anchor',
  291. items: [{
  292. tag : 'iframe',
  293. frame : true,
  294. anchor : '100% 100%',
  295. layout : 'fit',
  296. html : '<iframe id="iframe_' + record.data.sd_id + '" src="' + basePath +
  297. "jsps/pm/bom/FeatureValueView.jsp?fromwhere=SaleForecastDetail&condition=formidIS" + record.data.sd_id + ' AND pr_codeIS' + record.data.sd_prodcode + ' AND pr_nameIS' + record.data.pr_detail +'" height="100%" width="100%" frameborder="0" scrolling="yes"></iframe>'
  298. }]
  299. });
  300. win.show();
  301. } else {
  302. showError('物料特征必须为 虚拟特征件');return;
  303. }
  304. }
  305. }
  306. });
  307. }
  308. }
  309. },
  310. 'textfield[name=sf_fromdate]': {
  311. change: function(field){
  312. if(field.value != null && field.value != ''){
  313. var grid = Ext.getCmp('grid');
  314. var date = field.value;
  315. Ext.Array.each(grid.getStore().data.items,function(item){
  316. item.set('sd_startdate',date);
  317. });
  318. }
  319. }
  320. },
  321. 'textfield[name=sf_todate]': {
  322. change: function(field){
  323. if(field.value != null && field.value != ''){
  324. var grid = Ext.getCmp('grid');
  325. var date = field.value;
  326. Ext.Array.each(grid.getStore().data.items,function(item){
  327. item.set('sd_enddate',date);
  328. });
  329. }
  330. }
  331. },
  332. 'textfield[name=sf_custcode]': {
  333. change: function(field){
  334. if(field.value != null && field.value != ''){
  335. var grid = Ext.getCmp('grid');
  336. var date = field.value;
  337. Ext.Array.each(grid.getStore().data.items,function(item){
  338. item.set('sd_custcode',date);
  339. });
  340. }
  341. }
  342. },
  343. 'erpTurnSaleButton': {
  344. afterrender: function(btn){
  345. var status = Ext.getCmp('sf_statuscode');
  346. if(status && status.value != 'AUDITED'){
  347. btn.hide();
  348. }
  349. },
  350. click: function(btn){
  351. var grid = Ext.getCmp('grid');
  352. var form = Ext.getCmp('form');
  353. if(form.getForm().isValid()){
  354. //form里面数据
  355. Ext.each(form.items.items, function(item){
  356. if(item.xtype == 'numberfield'){
  357. //number类型赋默认值,不然sql无法执行
  358. if(item.value == null || item.value == ''){
  359. item.setValue(0);
  360. }
  361. }
  362. });
  363. var r = form.getValues();
  364. //去除ignore字段
  365. var keys = Ext.Object.getKeys(r), f;
  366. var reg = /[!@#$%^&*()'":,\/?]/;
  367. Ext.each(keys, function(k){
  368. f = form.down('#' + k);
  369. if(f && f.logic == 'ignore') {
  370. delete r[k];
  371. }
  372. //codeField值强制大写,自动过滤特殊字符
  373. if(k == form.codeField && !Ext.isEmpty(r[k])) {
  374. r[k] = r[k].trim().toUpperCase().replace(reg, '');
  375. }
  376. //获取新id
  377. if(k==form.keyField){
  378. Ext.Ajax.request({
  379. url : basePath + 'common/getId.action?seq=SALEFORECAST_SEQ',
  380. method : 'get',
  381. async: false,
  382. callback : function(options,success,response){
  383. var rs = new Ext.decode(response.responseText);
  384. if(rs.exceptionInfo){
  385. showError(rs.exceptionInfo);return;
  386. }
  387. if(rs.success){
  388. r[k]=rs.id
  389. }
  390. }
  391. });
  392. }
  393. });
  394. }
  395. var param=new Array();
  396. var s = grid.getStore().data.items;//获取store里面的数据
  397. var dd;
  398. for(var i=0;i<s.length;i++){//将grid里面各行的数据获取并拼成jsonGridData
  399. var data = s[i].data;
  400. dd = new Object();
  401. Ext.each(grid.columns, function(c){
  402. if((!c.isCheckerHd)&&(c.logic != 'ignore')){//只需显示,无需后台操作的字段,自动略去
  403. if(c.xtype == 'datecolumn'){
  404. c.format = c.format || 'Y-m-d';
  405. if(Ext.isDate(data[c.dataIndex])){
  406. dd[c.dataIndex] = Ext.Date.format(data[c.dataIndex], c.format);
  407. } else {
  408. if(c.editor){
  409. dd[c.dataIndex] = Ext.Date.format(new Date(), c.format);//如果用户没输入日期,或输入有误,就给个默认日期,
  410. }
  411. }
  412. } else if(c.xtype == 'datetimecolumn'){
  413. if(Ext.isDate(data[c.dataIndex])){
  414. dd[c.dataIndex] = Ext.Date.format(data[c.dataIndex], 'Y-m-d H:i:s');//在这里把GMT日期转化成Y-m-d H:i:s格式日期
  415. } else {
  416. if(c.editor){
  417. dd[c.dataIndex] = Ext.Date.format(new Date(), 'Y-m-d H:i:s');//默认日期,
  418. }
  419. }
  420. } else if(c.xtype == 'numbercolumn'){//赋个默认值0吧,不然不好保存
  421. if(data[c.dataIndex] == null || data[c.dataIndex] == ''){
  422. dd[c.dataIndex] = '0';//也可以从data里面去掉这些字段
  423. } else {
  424. dd[c.dataIndex] = s[i].data[c.dataIndex];
  425. }
  426. } else {
  427. dd[c.dataIndex] = s[i].data[c.dataIndex];
  428. }
  429. }
  430. });
  431. if(grid.mainField && form && form.keyField){//例如,将pu_id的值赋给pd_puid
  432. dd[grid.mainField] = r[form.keyField];
  433. }
  434. param.push(Ext.JSON.encode(dd));
  435. }
  436. var params = new Object();
  437. Ext.each(Ext.Object.getKeys(r), function(k){//去掉页面非表单定义字段
  438. if(contains(k, 'ext-', true)){
  439. delete r[k];
  440. }
  441. });
  442. params.formStore = unescape(Ext.JSON.encode(r).replace(/\\/g,"%"));
  443. params.param = unescape(param.toString().replace(/\\/g,"%"));
  444. for(var i=2; i<arguments.length; i++) { //兼容多参数
  445. params['param' + i] = unescape(arguments[i].toString().replace(/\\/g,"%"));
  446. }
  447. var me = this;
  448. var form = Ext.getCmp('form');
  449. /* me.getActiveTab().setLoading(true);//loading...
  450. */ Ext.Ajax.request({
  451. url : basePath + 'drp/distribution/saveSaleForecast.action?caller=SaleForecast',
  452. params : params,
  453. method : 'post',
  454. callback : function(options,success,response){
  455. var localJson = new Ext.decode(response.responseText);
  456. if(localJson.success){
  457. saveSuccess(function(){
  458. });
  459. } else if(localJson.exceptionInfo){
  460. var str = localJson.exceptionInfo;
  461. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  462. str = str.replace('AFTERSUCCESS', '');
  463. saveSuccess(function(){
  464. //add成功后刷新页面进入可编辑的页面
  465. var value = r[form.keyField];
  466. var formCondition = form.keyField + "IS" + value ;
  467. var gridCondition = '';
  468. var grid = Ext.getCmp('grid');
  469. if(grid && grid.mainField){
  470. gridCondition = grid.mainField + "IS" + value;
  471. }
  472. if(me.contains(window.location.href, '?', true)){
  473. window.location.href = window.location.href + '&formCondition=' +
  474. formCondition + '&gridCondition=' + gridCondition;
  475. } else {
  476. window.location.href = window.location.href + '?formCondition=' +
  477. formCondition + '&gridCondition=' + gridCondition;
  478. }
  479. });
  480. showError(str);
  481. } else {
  482. showError(str);
  483. return;
  484. }
  485. } else{
  486. saveFailure();//@i18n/i18n.js
  487. }
  488. }
  489. });
  490. }
  491. },
  492. });
  493. },
  494. onGridItemClick: function(selModel, record){//grid行选择
  495. this.GridUtil.onGridItemClick(selModel, record);
  496. },
  497. getForm: function(btn){
  498. return btn.ownerCt.ownerCt;
  499. },
  500. beforeSaveSaleForecast: function(){
  501. var grid = Ext.getCmp('grid'), items = grid.store.data.items, c = Ext.getCmp('sf_code').value;
  502. Ext.Array.each(items, function(item){
  503. item.set('sd_code', c);
  504. });
  505. //保存
  506. this.FormUtil.beforeSave(this);
  507. },
  508. beforeUpdate: function(){
  509. var grid = Ext.getCmp('grid'), items = grid.store.data.items, c = Ext.getCmp('sf_code').value;
  510. Ext.Array.each(items, function(item){
  511. item.set('sd_code', c);
  512. });
  513. //更新
  514. this.FormUtil.onUpdate(this);
  515. }
  516. });