Form.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. Ext.define('erp.view.common.batchDeal.Form',{
  2. extend: 'Ext.form.Panel',
  3. alias: 'widget.erpBatchDealFormPanel',
  4. requires: ['erp.view.core.button.VastDeal','erp.view.core.button.VastPrint','erp.view.core.button.VastAnalyse','erp.view.core.button.TurnVastOtherIn',
  5. 'erp.view.core.button.GetVendor','erp.view.core.button.VastTurnPurc','erp.view.core.button.DealMake','erp.view.core.button.TurnVastSaleReturn',
  6. 'erp.view.core.button.MakeOccur','erp.view.core.button.SaleOccur','erp.view.core.button.AllThrow','erp.view.core.button.AllThrowNotify',
  7. 'erp.view.core.button.SelectThrow','erp.view.core.button.GetPrice','erp.view.core.button.RePrice','erp.view.core.button.SelectThrowNotify',
  8. 'erp.view.core.button.BussAccount','erp.view.core.button.FeeShare','erp.view.core.button.VastSave','erp.view.core.button.TurnStockScrap',
  9. 'erp.view.core.button.UseableReplace','erp.view.core.button.Consistency', 'erp.view.core.button.VastPost','erp.view.core.button.BatchTurnAppropriationOut',
  10. 'erp.view.core.button.VastTurnPreProduct', 'erp.view.core.button.RefreshQty', 'erp.view.core.button.SetVendorRate','erp.view.core.button.CancelApproveNum',
  11. 'erp.view.core.button.ScmTurnOtherOut','erp.view.core.button.ScmTurnExchangeOut','erp.view.core.button.ScmTurnAppropriationOut','erp.view.core.button.TurnGoodsUp',
  12. 'erp.view.core.button.ConfirmVendor','erp.view.core.button.GetForecastVendor','erp.view.core.button.VastTurnProdIn','erp.view.core.button.SetVendorRateAdd',
  13. 'erp.view.core.button.DeliveryChange','erp.view.core.button.SaveCostDetail','erp.view.core.button.DifferVoucherCredit','erp.view.core.button.NowhVoucherCredit',
  14. 'erp.view.core.button.BatchPrint','erp.view.core.button.B2CPurchase','erp.view.core.button.ConfirmYFYF','erp.view.core.button.ConfirmYSYS','erp.view.core.button.VastMakeOpen',
  15. 'erp.view.core.button.VastMakeClose','erp.view.core.button.CallBack','erp.view.core.button.Transfer','erp.view.core.button.BusDistribute','erp.view.core.button.BatchQuotePrice',
  16. 'erp.view.core.button.VastCancelSubs','erp.view.core.button.VastAddSubs','erp.view.core.button.BreakingBatch','erp.view.core.button.CombiningAndBreaking'],
  17. id: 'dealform',
  18. source:'',//全功能导航展示使用
  19. region: 'north',
  20. tempStore:false,
  21. detailkeyfield:'',
  22. frame : true,
  23. header: false,//不显示title
  24. layout : 'column',
  25. padding: '0 4 0 4',
  26. autoScroll : true,
  27. defaultType : 'textfield',
  28. labelSeparator : ':',
  29. buttonAlign : 'center',
  30. fieldDefaults : {
  31. fieldStyle : "background:#FFFAFA;color:#515151;",
  32. labelAlign : "right",
  33. blankText : $I18N.common.form.blankText
  34. },
  35. FormUtil: Ext.create('erp.util.FormUtil'),
  36. GridUtil: Ext.create('erp.util.GridUtil'),
  37. tbar: [{
  38. name: 'query',
  39. id: 'query',
  40. text: $I18N.common.button.erpQueryButton,
  41. iconCls: 'x-button-icon-query',
  42. cls: 'x-btn-gray',
  43. handler: function(btn){
  44. btn.ownerCt.ownerCt.onQuery();
  45. }
  46. }, '->',
  47. {
  48. name: 'addToTempStore',
  49. id: 'addToTempStore',
  50. text: $I18N.common.button.erpAddToTempStore,
  51. iconCls: 'x-button-icon-submit',
  52. cls: 'x-btn-gray',
  53. hidden: true
  54. },{
  55. name: 'checkTempStore',
  56. id: 'checkTempStore',
  57. hidden: true,
  58. text: $I18N.common.button.erpCheckTempStore,
  59. iconCls: 'x-button-icon-submit',
  60. cls: 'x-btn-gray'
  61. },'-',
  62. {
  63. xtype: 'erpMakeOccurButton',
  64. id: 'erpMakeOccurButton',
  65. hidden: true
  66. },
  67. {
  68. xtype: 'erpSaleOccurButton',
  69. id: 'erpSaleOccurButton',
  70. hidden: true
  71. },
  72. {
  73. xtype: 'erpVastAnalyseButton',
  74. id: 'erpVastAnalyseButton',
  75. hidden: true
  76. },{
  77. xtype: 'erpVastPrintButton',
  78. id: 'erpVastPrintButton',
  79. hidden: true
  80. },{
  81. xtype: 'erpVastDealButton',
  82. id: 'erpVastDealButton',
  83. hidden: true
  84. },
  85. {
  86. xtype:'erpBatchPriceButton',
  87. id:'erpBatchPriceButton',
  88. hidden:true
  89. }
  90. ,{
  91. xtype: 'erpRefreshQtyButton',
  92. id: 'erpRefreshQtyButton',
  93. hidden: true
  94. },{
  95. xtype: 'erpDeliveryChangeButton',
  96. id: 'erpDeliveryChangeButton',
  97. hidden: true
  98. },{
  99. xtype: 'erpSaveCostDetailButton',
  100. id: 'erpSaveCostDetailButton',
  101. hidden: true
  102. },{
  103. xtype: 'erpDifferVoucherCreditButton',
  104. id: 'erpDifferVoucherCreditButton',
  105. hidden: true
  106. },{
  107. xtype: 'erpNowhVoucherCreditButton',
  108. id: 'erpNowhVoucherCreditButton',
  109. hidden: true
  110. },{
  111. xtype: 'erpConfirmYFYFButton',
  112. hidden: true
  113. },{
  114. xtype: 'erpConfirmYSYSButton',
  115. hidden: true
  116. },{
  117. xtype: 'erpVastAddSubsApplyButton',
  118. id: 'erpVastAddSubsApplyButton',
  119. hidden: true
  120. },{
  121. xtype: 'erpVastCancelSubsApplyButton',
  122. id: 'erpVastCancelSubsApplyButton',
  123. hidden: true
  124. },'-',{
  125. name: 'export',
  126. id:'export',
  127. text: $I18N.common.button.erpExportButton,
  128. iconCls: 'x-button-icon-excel',
  129. cls: 'x-btn-gray',
  130. handler: function(btn){
  131. var form = btn.ownerCt.ownerCt;
  132. // grid = Ext.getCmp('batchDealGridPanel');
  133. var grid = form.ownerCt.down('grid');
  134. var cond = form.getCondition();
  135. if(Ext.isEmpty(cond)) {
  136. cond = '1=1';
  137. }
  138. if(grid.xtype == 'erpBatchDealGridPanel') {
  139. var p = grid.plugins[1], fields = Ext.Object.getKeys(p.fields),
  140. fi = new Array();
  141. fi.push(cond);
  142. Ext.each(fields, function(){
  143. var f = p.fields[this];
  144. if(!Ext.isEmpty(f.value)) {
  145. if((f.xtype == 'datefield' || f.xtype == 'datetimefield')
  146. && f.value instanceof Date) {
  147. fi.push('to_char(' + this + ',\'yyyymmdd\')=' + Ext.Date.format(f.value, 'Ymd'));
  148. } else {
  149. fi.push(this + ' like \'%' + f.value + '%\'');
  150. }
  151. }
  152. });
  153. cond = fi.join(' AND ');
  154. }
  155. grid.BaseUtil.createExcel(caller, 'detailgrid', cond);
  156. }
  157. },'-',{
  158. text: $I18N.common.button.erpCloseButton,
  159. iconCls: 'x-button-icon-close',
  160. cls: 'x-btn-gray',
  161. id:'close',
  162. handler: function(){
  163. var main = parent.Ext.getCmp("content-panel");
  164. if(main){
  165. main.getActiveTab().close();
  166. }else parent.Ext.getCmp('win').close();
  167. }
  168. }],
  169. initComponent : function(){
  170. var source=getUrlParam('source');
  171. this.source=source;
  172. this.getItemsAndButtons();
  173. this.addEvents({alladded: true});//items加载完
  174. this.callParent(arguments);
  175. this.addKeyBoardEvents();//监听Ctrl+Alt+S事件
  176. },
  177. getItemsAndButtons: function(){
  178. var me = this;
  179. me.FormUtil.getActiveTab().setLoading(true);
  180. Ext.Ajax.request({//拿到form的items
  181. url : basePath + 'common/singleFormItems.action',
  182. params: {
  183. caller: caller,
  184. condition: '',
  185. _noc: getUrlParam('_noc') || this._noc
  186. },
  187. method : 'post',
  188. callback : function(options,success,response){
  189. me.FormUtil.getActiveTab().setLoading(false);
  190. var res = new Ext.decode(response.responseText);
  191. if(res.exceptionInfo != null){
  192. showError(res.exceptionInfo);return;
  193. }
  194. if(contains(res.buttons, 'addToTempStore', true)){
  195. me.tempStore=true;
  196. }
  197. me.fo_keyField = res.fo_keyField;
  198. me.detailkeyfield = res.detailkeyfield;
  199. me.tablename = res.tablename;
  200. me.fo_id=res.fo_id;
  201. if(res.keyField){
  202. me.keyField = res.keyField;
  203. }
  204. if(res.dealUrl){
  205. me.dealUrl = res.dealUrl;
  206. }
  207. me.fo_detailMainKeyField = res.fo_detailMainKeyField;
  208. Ext.each(res.items, function(item){
  209. if(me.source=='allnavigation'){
  210. item.fieldStyle = item.fieldStyle + ';background:#f1f1f1;';
  211. item.readOnly = true;
  212. }
  213. if(screen.width < 1280){//根据屏幕宽度,调整列显示宽度
  214. if(item.columnWidth > 0 && item.columnWidth <= 0.25){
  215. item.columnWidth = 1/3;
  216. } else if(item.columnWidth > 0.25 && item.columnWidth <= 0.5){
  217. item.columnWidth = 2/3;
  218. } else if(item.columnWidth >= 1){
  219. item.columnWidth = 1;
  220. }
  221. } else {
  222. if(item.columnWidth > 0.25 && item.columnWidth < 0.5){
  223. item.columnWidth = 2/3;
  224. }
  225. }
  226. if(item.xtype == 'hidden') {
  227. item.columnWidth = 0;
  228. }
  229. });
  230. me.add(res.items);
  231. me.fireEvent('alladded', me);
  232. //解析buttons字符串,并拼成json格式
  233. var buttonString = res.buttons;
  234. if(buttonString != null && buttonString != ''){
  235. if(contains(buttonString, '#', true)){
  236. Ext.each(buttonString.split('#'), function(b, index){
  237. if(!Ext.getCmp(b)){
  238. var btn = Ext.getCmp('erpVastDealButton');
  239. if (btn){
  240. try {
  241. btn.ownerCt.insert(5, {
  242. xtype: b,
  243. disabled:me.source=='allnavigation'?true:false,
  244. cls: 'x-btn-gray'
  245. });
  246. } catch (e) {
  247. btn.setText($I18N.common.button[b]);
  248. btn.show();
  249. }
  250. }
  251. } else {
  252. Ext.getCmp(b).show();
  253. if(me.source=='allnavigation') Ext.getCmp(buttonString).setDisabled(true);
  254. }
  255. });
  256. } else {
  257. if(caller == 'NewBar!BaPrint'||caller == 'ScanCodeLogin!query'){
  258. var btn = Ext.getCmp('erpVastDealButton');
  259. if (btn){
  260. try {
  261. btn.ownerCt.insert(2, {
  262. xtype: buttonString,
  263. disabled:me.source=='allnavigation'?true:false,
  264. cls: 'x-btn-gray'
  265. });
  266. } catch (e) {
  267. btn.setText($I18N.common.button[buttonString]);
  268. btn.show();
  269. }
  270. }
  271. }else{
  272. if(Ext.getCmp(buttonString)){
  273. Ext.getCmp(buttonString).show();
  274. if(me.source=='allnavigation') Ext.getCmp(buttonString).setDisabled(true);
  275. } else {
  276. var btn = Ext.getCmp('erpVastDealButton');//Ext.getCmp(buttonString);
  277. if(btn){
  278. btn.setText($I18N.common.button[buttonString]);
  279. btn.show();
  280. if(me.source=='allnavigation') btn.setDisabled(true);
  281. }
  282. }
  283. }
  284. }
  285. }
  286. }
  287. });
  288. },
  289. /**
  290. * @param select 保留原筛选行
  291. */
  292. onQuery: function(select){
  293. var grid = Ext.getCmp('batchDealGridPanel'),sel = [];
  294. if(!grid){
  295. grid = Ext.getCmp('grid');
  296. }
  297. var check=grid.headerCt.items.items[0];
  298. if(check && check.isCheckerHd){
  299. check.el.removeCls(Ext.baseCSSPrefix + 'grid-hd-checker-on');
  300. }
  301. grid.multiselected = new Array();
  302. if(select == true) {
  303. sel = grid.selModel.getSelection();
  304. }
  305. var form = this;
  306. var cond = form.getCondition();
  307. if(Ext.isEmpty(cond)) {
  308. cond = '1=1';
  309. }
  310. var constr=form.beforeQuery(caller, cond);//执行查询前逻辑
  311. cond+=constr!=null && constr!=''?" AND ("+constr+")":"";
  312. var gridParam = { caller: caller, condition: cond + form.getOrderBy(grid) };
  313. if(!grid.bigVolume) {
  314. gridParam.start = 1;
  315. gridParam.end = 1000;
  316. }
  317. if(grid.maxDataSize) {
  318. gridParam.start = 1;
  319. gridParam.end = grid.maxDataSize;
  320. }
  321. //移除掉全选样式
  322. if(grid.getGridColumnsAndStore){
  323. grid.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', gridParam, "");
  324. } else {
  325. //grid.GridUtil.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', gridParam, "");
  326. grid.GridUtil.loadNewStore(grid, gridParam);
  327. }
  328. if(select == true) {
  329. Ext.each(sel, function(){
  330. grid.selModel.select(this.index);
  331. });
  332. }
  333. },
  334. getCondition: function(grid){
  335. grid = grid || Ext.getCmp('batchDealGridPanel');
  336. if(!grid){
  337. grid = Ext.getCmp('grid');
  338. }
  339. var form = this;
  340. var condition = typeof grid.getCondition === 'function' ? grid.getCondition(true) :
  341. (Ext.isEmpty(grid.defaultCondition) ? '' : ('(' + grid.defaultCondition + ')'));
  342. Ext.each(form.items.items, function(f){
  343. if(f.logic != null && f.logic != ''){
  344. if((f.xtype == 'checkbox' || f.xtype == 'radio')){
  345. if(f.value == true) {
  346. if(condition == ''){
  347. condition += f.logic;
  348. } else {
  349. condition += ' AND ' + f.logic;
  350. }
  351. }
  352. } else if(f.xtype == 'datefield' && f.value != null && f.value != '' && !contains(f.logic, 'to:', true)){
  353. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  354. if(condition == ''){
  355. condition += "to_char("+f.logic+",'yyyy-MM-dd')='"+v+"'";
  356. } else {
  357. condition += " AND to_char("+f.logic+",'yyyy-MM-dd')='"+v+"'";
  358. }
  359. } else if(f.xtype == 'datetimefield' && f.value != null){
  360. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  361. if(condition == ''){
  362. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  363. } else {
  364. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  365. }
  366. } else if(f.xtype == 'numberfield' && f.value != null && f.value != '' && !contains(f.logic, 'to:', true)){
  367. var endChar = f.logic.substr(f.logic.length - 1);
  368. if(endChar != '>' && endChar != '<')
  369. endChar = '=';
  370. else
  371. endChar = '';
  372. if(condition == ''){
  373. condition += f.logic + endChar + f.value;
  374. } else {
  375. condition += ' AND ' + f.logic + endChar + f.value;
  376. }
  377. } else if(f.xtype == 'combo' && f.value == '$ALL'){
  378. if(f.store.data.length > 1) {
  379. if(condition == ''){
  380. condition += '(';
  381. } else {
  382. condition += ' AND (';
  383. }
  384. var _a = '';
  385. f.store.each(function(d, idx){
  386. if(d.data.value != '$ALL') {
  387. if(_a == ''){
  388. _a += f.logic + "='" + d.data.value + "'";
  389. } else {
  390. _a += ' OR ' + f.logic + "='" + d.data.value + "'";
  391. }
  392. }
  393. });
  394. condition += _a + ')';
  395. }
  396. } else if(f.xtype=='adddbfindtrigger' && f.value != null && f.value != ''){
  397. if(condition == ''){
  398. condition += f.logic + ' in (' ;
  399. } else {
  400. condition += ' AND ' + f.logic + ' in (';
  401. }
  402. var str=f.value,constr="";
  403. for(var i=0;i<str.split("#").length;i++){
  404. if(i<str.split("#").length-1){
  405. constr+="'"+str.split("#")[i]+"',";
  406. }else constr+="'"+str.split("#")[i]+"'";
  407. }
  408. condition +=constr+")";
  409. } else {
  410. //一般情况下,在执行批量处理时,是不需要把form的数据传回去,
  411. //但某些情况下,需要将form的某些字段的值也传回去
  412. //例如 请购批量转采购,如果指定了采购单号,就要把采购单号传回去
  413. if(contains(f.logic, 'to:', true)){
  414. if(!grid.toField){
  415. grid.toField = new Array();
  416. }
  417. grid.toField.push(f.logic.split(':')[1]);
  418. } else {
  419. if(!Ext.isEmpty(f.value)){
  420. if(contains(f.value.toString(), 'BETWEEN', true) && contains(f.value.toString(), 'AND', true)){
  421. if(condition == ''){
  422. condition += f.logic + " " + f.value;
  423. } else {
  424. condition += ' AND (' + f.logic + " " + f.value + ")";
  425. }
  426. } else if(contains(f.value.toString(), '||', true)){
  427. var str = '';
  428. Ext.each(f.value.split('||'), function(v){
  429. if(v != null && v != ''){
  430. if(str == ''){
  431. str += f.logic + "='" + v + "'";
  432. } else {
  433. str += ' OR ' + f.logic + "='" + v + "'";
  434. }
  435. }
  436. });
  437. if(condition == ''){
  438. condition += "(" + str + ")";
  439. } else {
  440. condition += ' AND (' + str + ")";
  441. }
  442. } else if(f.value.toString().charAt(0) == '!'){
  443. if(condition == ''){
  444. condition += 'nvl(' + f.logic + ",' ')<>'" + f.value.substr(1) + "'";
  445. } else {
  446. condition += ' AND (nvl(' + f.logic + ",' ')<>'" + f.value.substr(1) + "')";
  447. }
  448. } else {
  449. if(f.value.toString().indexOf('%') >= 0) {
  450. if(condition == ''){
  451. condition += f.logic + " like '" + f.value + "'";
  452. } else {
  453. condition += ' AND (' + f.logic + " like '" + f.value + "')";
  454. }
  455. } else {
  456. if(condition == ''){
  457. condition += f.logic + "='" + f.value + "'";
  458. } else {
  459. condition += ' AND (' + f.logic + "='" + f.value + "')";
  460. }
  461. }
  462. }
  463. }
  464. }
  465. }
  466. }
  467. });
  468. /*if(urlcondition !=null || urlcondition !=''){
  469. condition =condition+urlcondition;
  470. }*/
  471. return condition;
  472. },
  473. getOrderBy: function(grid){
  474. var ob = new Array();
  475. if(grid.mainField) {
  476. ob.push(grid.mainField + ' desc');
  477. }
  478. if(grid.detno) {
  479. ob.push(grid.detno + ' asc');
  480. }
  481. if(grid.keyField) {
  482. ob.push(grid.keyField + ' desc');
  483. }
  484. var order = '';
  485. if(ob.length > 0) {
  486. order = ' order by ' + ob.join(',');
  487. }
  488. return order;
  489. },
  490. /**
  491. * 监听一些事件
  492. * <br>
  493. * Ctrl+Alt+S 单据配置维护
  494. * Ctrl+Alt+P 参数、逻辑配置维护
  495. */
  496. addKeyBoardEvents: function(){
  497. var me = this;
  498. Ext.EventManager.addListener(document.body, 'keydown', function(e){
  499. if(e.altKey && e.ctrlKey) {
  500. if(e.keyCode == Ext.EventObject.S) {
  501. var url = "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id + "&gridCondition=fd_foidIS" + me.fo_id,
  502. forms = Ext.ComponentQuery.query('form'),
  503. grids = Ext.ComponentQuery.query('gridpanel'),
  504. formSet = [], gridSet = [];
  505. if(forms.length > 0) {
  506. Ext.Array.each(forms, function(f){
  507. f.fo_id && (formSet.push(f.fo_id));
  508. });
  509. }
  510. if(grids.length > 0) {
  511. Ext.Array.each(grids, function(g){
  512. if(g.xtype.indexOf('erpBatchDealGridPanel') > -1)
  513. gridSet.push(window.caller);
  514. else if(g.caller)
  515. gridSet.push(g.caller);
  516. });
  517. }
  518. if(formSet.length > 0 || gridSet.length > 0) {
  519. url = "jsps/ma/multiform.jsp?formParam=" + formSet.join(',') + '&gridParam=' + gridSet.join(',');
  520. }
  521. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', url);
  522. } else if(e.keyCode == Ext.EventObject.P) {
  523. me.FormUtil.onAdd('configs-' + caller, '逻辑配置维护(' + caller + ')', "jsps/ma/logic/config.jsp?whoami=" + caller);
  524. }
  525. }
  526. });
  527. },
  528. beforeQuery: function(call, cond) {
  529. var str=null;
  530. Ext.Ajax.request({
  531. url: basePath + 'common/form/beforeQuery.action',
  532. params: {
  533. caller: call,
  534. condition: cond
  535. },
  536. async: false,
  537. callback: function(opt, s, r) {
  538. var rs = Ext.decode(r.responseText);
  539. if(rs.exceptionInfo) {
  540. showError(rs.exceptionInfo);
  541. }else if(rs.data){
  542. str=rs.data;
  543. }
  544. }
  545. });
  546. return str;
  547. }
  548. });