Form.js 14 KB

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