Former.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. Ext.define('erp.view.common.batchDeal.Former',{
  2. extend: 'Ext.form.Panel',
  3. alias: 'widget.erpBatchDealerFormPanel',
  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.CheckVendorUU'],
  17. id: 'dealerform',
  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. xtype: 'erpCheckVendorUUButton',
  126. id: 'erpCheckVendorUUButton',
  127. hidden: true
  128. },'-',{
  129. name: 'export',
  130. id:'export',
  131. text: $I18N.common.button.erpExportButton,
  132. iconCls: 'x-button-icon-excel',
  133. cls: 'x-btn-gray',
  134. handler: function(btn){
  135. var form = btn.ownerCt.ownerCt;
  136. var grid = form.ownerCt.down('grid');
  137. var cond = form.getCondition();
  138. if(Ext.isEmpty(cond)) {
  139. cond = '1=1';
  140. }
  141. if(grid.xtype == 'erpBatchDealerGridPanel') {
  142. var p = grid.plugins[1], fields = Ext.Object.getKeys(p.fields),
  143. fi = new Array();
  144. fi.push(cond);
  145. Ext.each(fields, function(){
  146. var f = p.fields[this];
  147. if(!Ext.isEmpty(f.value)) {
  148. if((f.xtype == 'datefield' || f.xtype == 'datetimefield')
  149. && f.value instanceof Date) {
  150. fi.push('to_char(' + this + ',\'yyyymmdd\')=' + Ext.Date.format(f.value, 'Ymd'));
  151. } else {
  152. fi.push(this + ' like \'%' + f.value + '%\'');
  153. }
  154. }
  155. });
  156. cond = fi.join(' AND ');
  157. }
  158. grid.BaseUtil.createExcel(caller, 'detailgrid', cond);
  159. }
  160. },'-',{
  161. text: $I18N.common.button.erpCloseButton,
  162. iconCls: 'x-button-icon-close',
  163. cls: 'x-btn-gray',
  164. id:'close',
  165. handler: function(){
  166. var main = parent.Ext.getCmp("content-panel");
  167. if(main){
  168. main.getActiveTab().close();
  169. }else parent.Ext.getCmp('win').close();
  170. }
  171. }],
  172. initComponent : function(){
  173. var source=getUrlParam('source');
  174. this.source=source;
  175. this.getItemsAndButtons();
  176. this.addEvents({alladded: true});//items加载完
  177. this.callParent(arguments);
  178. this.addKeyBoardEvents();//监听Ctrl+Alt+S事件
  179. },
  180. getItemsAndButtons: function(){
  181. var me = this;
  182. me.FormUtil.getActiveTab().setLoading(true);
  183. Ext.Ajax.request({//拿到form的items
  184. url : basePath + 'common/singleFormItems.action',
  185. params: {
  186. caller: caller,
  187. condition: '',
  188. _noc: getUrlParam('_noc') || this._noc,
  189. _config:getUrlParam('_config')
  190. },
  191. method : 'post',
  192. callback : function(options,success,response){
  193. me.FormUtil.getActiveTab().setLoading(false);
  194. var res = new Ext.decode(response.responseText);
  195. if(res.exceptionInfo != null){
  196. showError(res.exceptionInfo);return;
  197. }
  198. if(contains(res.buttons, 'addToTempStore', true)){
  199. me.tempStore=true;
  200. }
  201. me.fo_keyField = res.fo_keyField;
  202. me.detailkeyfield = res.detailkeyfield;
  203. me.tablename = res.tablename;
  204. me.fo_id=res.fo_id;
  205. if(res.keyField){
  206. me.keyField = res.keyField;
  207. }
  208. if(res.dealUrl){
  209. me.dealUrl = res.dealUrl;
  210. }
  211. me.fo_detailMainKeyField = res.fo_detailMainKeyField;
  212. Ext.each(res.items, function(item){
  213. if(me.source=='allnavigation'){
  214. item.fieldStyle = item.fieldStyle + ';background:#f1f1f1;';
  215. item.readOnly = true;
  216. }
  217. if(!item.allowBlank && item.fieldLabel ) {
  218. item.fieldLabel= '<font style="color:#F00">'+item.fieldLabel+'</font>';
  219. }
  220. if(screen.width < 1280){//根据屏幕宽度,调整列显示宽度
  221. if(item.columnWidth > 0 && item.columnWidth <= 0.25){
  222. item.columnWidth = 1/3;
  223. } else if(item.columnWidth > 0.25 && item.columnWidth <= 0.5){
  224. item.columnWidth = 2/3;
  225. } else if(item.columnWidth >= 1){
  226. item.columnWidth = 1;
  227. }
  228. } else {
  229. if(item.columnWidth > 0.25 && item.columnWidth < 0.5){
  230. item.columnWidth = 2/3;
  231. }
  232. }
  233. if(item.xtype == 'hidden') {
  234. item.columnWidth = 0;
  235. }
  236. });
  237. me.add(res.items);
  238. me.fireEvent('alladded', me);
  239. //解析buttons字符串,并拼成json格式
  240. var buttonString = res.buttons;
  241. if(buttonString != null && buttonString != ''){
  242. if(contains(buttonString, '#', true)){
  243. Ext.each(buttonString.split('#'), function(b, index){
  244. if(!Ext.getCmp(b)){
  245. var btn = Ext.getCmp('erpVastDealButton');
  246. if (btn){
  247. try {
  248. btn.ownerCt.insert(5, {
  249. xtype: b,
  250. disabled:me.source=='allnavigation'?true:false,
  251. cls: 'x-btn-gray'
  252. });
  253. } catch (e) {
  254. btn.setText($I18N.common.button[b]);
  255. btn.show();
  256. }
  257. }
  258. } else {
  259. Ext.getCmp(b).show();
  260. if(me.source=='allnavigation') Ext.getCmp(buttonString).setDisabled(true);
  261. }
  262. });
  263. } else {
  264. if(caller == 'NewBar!BaPrint' || caller == 'Barcode!BaPrint'){
  265. var btn = Ext.getCmp('erpVastDealButton');
  266. if (btn){
  267. try {
  268. btn.ownerCt.insert(2, {
  269. xtype: buttonString,
  270. disabled:me.source=='allnavigation'?true:false,
  271. cls: 'x-btn-gray'
  272. });
  273. } catch (e) {
  274. btn.setText($I18N.common.button[buttonString]);
  275. btn.show();
  276. }
  277. }
  278. }else{
  279. if(Ext.getCmp(buttonString)){
  280. Ext.getCmp(buttonString).show();
  281. if(me.source=='allnavigation') Ext.getCmp(buttonString).setDisabled(true);
  282. } else {
  283. var btn = Ext.getCmp('erpVastDealButton');//Ext.getCmp(buttonString);
  284. if(btn){
  285. btn.setText($I18N.common.button[buttonString]);
  286. btn.show();
  287. if(me.source=='allnavigation') btn.setDisabled(true);
  288. }
  289. }
  290. }
  291. }
  292. }
  293. }
  294. });
  295. },
  296. /**
  297. * @param select 保留原筛选行
  298. */
  299. onQuery: function(select){
  300. var grid = Ext.getCmp('batchDealerGridPanel'),sel = [];
  301. if(!grid){
  302. grid = Ext.getCmp('grid');
  303. }
  304. var check=grid.headerCt.items.items[0];
  305. if(check && check.isCheckerHd){
  306. check.el.removeCls(Ext.baseCSSPrefix + 'grid-hd-checker-on');
  307. }
  308. grid.multiselected = new Array();
  309. if(select == true) {
  310. sel = grid.selModel.getSelection();
  311. }
  312. var form = this;
  313. var error = form.check();
  314. if(error!=""){
  315. showError("[" + error.slice(0, -1) + "]不允许为空");
  316. return false;
  317. }
  318. var cond = form.getCondition();
  319. if(Ext.isEmpty(cond)) {
  320. cond = '1=1';
  321. }
  322. var constr=form.beforeQuery(caller, cond);//执行查询前逻辑
  323. cond+=constr!=null && constr!=''?" AND ("+constr+")":"";
  324. var gridParam = { caller: caller, condition: cond + form.getOrderBy(grid),page:page,pageSize:pageSize };
  325. //移除掉全选样式
  326. grid.getGridColumnsAndStore(grid, 'common/batchdeal/data.action',gridParam);
  327. if(select == true) {
  328. Ext.each(sel, function(){
  329. grid.selModel.select(this.index);
  330. });
  331. }
  332. },
  333. getCondition: function(grid){
  334. grid = grid || Ext.getCmp('batchDealerGridPanel');
  335. if(!grid){
  336. grid = Ext.getCmp('grid');
  337. }
  338. var form = this;
  339. var condition = typeof grid.getCondition === 'function' ? grid.getCondition(true) :
  340. (Ext.isEmpty(grid.defaultCondition) ? '' : ('(' + grid.defaultCondition + ')'));
  341. Ext.each(form.items.items, function(f){
  342. if(f.logic != null && f.logic != ''){
  343. if((f.xtype == 'checkbox' || f.xtype == 'radio')){
  344. if(f.value == true) {
  345. if(condition == ''){
  346. condition += f.logic;
  347. } else {
  348. condition += ' AND ' + f.logic;
  349. }
  350. }
  351. } else if(f.xtype == 'datefield' && f.value != null && f.value != '' && !contains(f.logic, 'to:', true)){
  352. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  353. if(condition == ''){
  354. condition += "to_char("+f.logic+",'yyyy-MM-dd')='"+v+"'";
  355. } else {
  356. condition += " AND to_char("+f.logic+",'yyyy-MM-dd')='"+v+"'";
  357. }
  358. } else if(f.xtype == 'datetimefield' && f.value != null){
  359. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  360. if(condition == ''){
  361. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  362. } else {
  363. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  364. }
  365. } else if(f.xtype == 'numberfield' && f.value != null && f.value != '' && !contains(f.logic, 'to:', true)){
  366. var endChar = f.logic.substr(f.logic.length - 1);
  367. if(endChar != '>' && endChar != '<')
  368. endChar = '=';
  369. else
  370. endChar = '';
  371. if(condition == ''){
  372. condition += f.logic + endChar + f.value;
  373. } else {
  374. condition += ' AND ' + f.logic + endChar + f.value;
  375. }
  376. } else if(f.xtype == 'combo' && f.value == '$ALL'){
  377. if(f.store.data.length > 1) {
  378. if(condition == ''){
  379. condition += '(';
  380. } else {
  381. condition += ' AND (';
  382. }
  383. var _a = '';
  384. f.store.each(function(d, idx){
  385. if(d.data.value != '$ALL') {
  386. if(_a == ''){
  387. _a += f.logic + "='" + d.data.value + "'";
  388. } else {
  389. _a += ' OR ' + f.logic + "='" + d.data.value + "'";
  390. }
  391. }
  392. });
  393. condition += _a + ')';
  394. }
  395. } else if(f.xtype=='adddbfindtrigger' && f.value != null && f.value != ''){
  396. if(condition == ''){
  397. condition += f.logic + ' in (' ;
  398. } else {
  399. condition += ' AND ' + f.logic + ' in (';
  400. }
  401. var str=f.value,constr="";
  402. for(var i=0;i<str.split("#").length;i++){
  403. if(i<str.split("#").length-1){
  404. constr+="'"+str.split("#")[i]+"',";
  405. }else constr+="'"+str.split("#")[i]+"'";
  406. }
  407. condition +=constr+")";
  408. } else {
  409. //一般情况下,在执行批量处理时,是不需要把form的数据传回去,
  410. //但某些情况下,需要将form的某些字段的值也传回去
  411. //例如 请购批量转采购,如果指定了采购单号,就要把采购单号传回去
  412. if(contains(f.logic, 'to:', true)){
  413. if(!grid.toField){
  414. grid.toField = new Array();
  415. }
  416. grid.toField.push(f.logic.split(':')[1]);
  417. } else {
  418. if(!Ext.isEmpty(f.value)){
  419. if(contains(f.value.toString(), 'BETWEEN', true) && contains(f.value.toString(), 'AND', true)){
  420. if(condition == ''){
  421. condition += f.logic + " " + f.value;
  422. } else {
  423. condition += ' AND (' + f.logic + " " + f.value + ")";
  424. }
  425. } else if(contains(f.value.toString(), '||', true)){
  426. var str = '';
  427. Ext.each(f.value.split('||'), function(v){
  428. if(v != null && v != ''){
  429. if(str == ''){
  430. str += f.logic + "='" + v + "'";
  431. } else {
  432. str += ' OR ' + f.logic + "='" + v + "'";
  433. }
  434. }
  435. });
  436. if(condition == ''){
  437. condition += "(" + str + ")";
  438. } else {
  439. condition += ' AND (' + str + ")";
  440. }
  441. } else if(f.value.toString().charAt(0) == '!'){
  442. if(condition == ''){
  443. condition += 'nvl(' + f.logic + ",' ')<>'" + f.value.substr(1) + "'";
  444. } else {
  445. condition += ' AND (nvl(' + f.logic + ",' ')<>'" + f.value.substr(1) + "')";
  446. }
  447. } else {
  448. if(f.value.toString().indexOf('%') >= 0) {
  449. if(condition == ''){
  450. condition += f.logic + " like '" + f.value + "'";
  451. } else {
  452. condition += ' AND (' + f.logic + " like '" + f.value + "')";
  453. }
  454. } else {
  455. if(condition == ''){
  456. condition += f.logic + "='" + f.value + "'";
  457. } else {
  458. condition += ' AND (' + f.logic + "='" + f.value + "')";
  459. }
  460. }
  461. }
  462. }
  463. }
  464. }
  465. }
  466. });
  467. /*if(urlcondition !=null || urlcondition !=''){
  468. condition =condition+urlcondition;
  469. }*/
  470. return condition;
  471. },
  472. getOrderBy: function(grid){
  473. var ob = new Array();
  474. if(grid.mainField) {
  475. ob.push(grid.mainField + ' desc');
  476. }
  477. if(grid.detno) {
  478. ob.push(grid.detno + ' asc');
  479. }
  480. if(grid.keyField) {
  481. ob.push(grid.keyField + ' desc');
  482. }
  483. var order = '';
  484. if(ob.length > 0) {
  485. order = ' order by ' + ob.join(',');
  486. }
  487. return order;
  488. },
  489. /**
  490. * 监听一些事件
  491. * <br>
  492. * Ctrl+Alt+S 单据配置维护
  493. * Ctrl+Alt+P 参数、逻辑配置维护
  494. */
  495. addKeyBoardEvents: function(){
  496. var me = this;
  497. Ext.EventManager.addListener(document.body, 'keydown', function(e){
  498. if(e.altKey && e.ctrlKey) {
  499. if(e.keyCode == Ext.EventObject.S) {
  500. var url = "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id + "&gridCondition=fd_foidIS" + me.fo_id,
  501. forms = Ext.ComponentQuery.query('form'),
  502. grids = Ext.ComponentQuery.query('gridpanel'),
  503. formSet = [], gridSet = [];
  504. if(forms.length > 0) {
  505. Ext.Array.each(forms, function(f){
  506. f.fo_id && (formSet.push(f.fo_id));
  507. });
  508. }
  509. if(grids.length > 0) {
  510. Ext.Array.each(grids, function(g){
  511. if(g.xtype.indexOf('erpBatchDealerGridPanel') > -1)
  512. gridSet.push(window.caller);
  513. else if(g.caller)
  514. gridSet.push(g.caller);
  515. });
  516. }
  517. if(formSet.length > 0 || gridSet.length > 0) {
  518. url = "jsps/ma/multiform.jsp?formParam=" + formSet.join(',') + '&gridParam=' + gridSet.join(',');
  519. }
  520. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', url);
  521. } else if(e.keyCode == Ext.EventObject.P) {
  522. me.FormUtil.onAdd('configs-' + caller, '逻辑配置维护(' + caller + ')', "jsps/ma/logic/config.jsp?whoami=" + caller);
  523. }
  524. }
  525. });
  526. },
  527. beforeQuery: function(call, cond) {
  528. var str=null;
  529. Ext.Ajax.request({
  530. url: basePath + 'common/form/beforeQuery.action',
  531. params: {
  532. caller: call,
  533. condition: cond
  534. },
  535. async: false,
  536. callback: function(opt, s, r) {
  537. if(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. });
  547. return str;
  548. },
  549. check: function(){
  550. var allowBlank = "";
  551. var items = this.items.items
  552. Ext.each(items, function(item){
  553. if(!item.allowBlank&&item.getRawValue()==""){
  554. allowBlank += item.fieldLabel + ",";
  555. }
  556. });
  557. return allowBlank;
  558. }
  559. });