Form.js 18 KB

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