CheckForm.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. Ext.define('erp.view.common.query.CheckForm',{
  2. extend: 'Ext.form.Panel',
  3. alias: 'widget.erpQueryFormPanel',
  4. id: 'queryform',
  5. region: 'north',
  6. frame : true,
  7. layout : 'column',
  8. header: false,////不显示title
  9. autoScroll : true,
  10. defaultType : 'textfield',
  11. labelSeparator : ':',
  12. buttonAlign : 'center',
  13. fieldDefaults : {
  14. margin : '2 2 2 2',
  15. fieldStyle : "background:#FFFAFA;color:#515151;",
  16. labelAlign : "right",
  17. blankText : $I18N.common.form.blankText
  18. },
  19. FormUtil: Ext.create('erp.util.FormUtil'),
  20. BaseUtil: Ext.create('erp.util.BaseUtil'),
  21. prevTime:null,
  22. tbar: [{
  23. id:'query',
  24. name: 'query',
  25. text: $I18N.common.button.erpQueryButton,
  26. iconCls: 'x-button-icon-query',
  27. cls: 'x-btn-gray',
  28. handler: function(btn){
  29. //限制点击筛选时间间隔不能超过2秒
  30. var form=btn.ownerCt.ownerCt;
  31. if(form.prevTime==null){
  32. form.prevTime=new Date().getTime();
  33. form.onQuery();
  34. }else {
  35. var nowtime=new Date().getTime();
  36. if((nowtime-form.prevTime)/1000<2){
  37. showError('请控制筛选时间间隔不能小于2秒!');
  38. return;
  39. }else {
  40. form.prevTime=nowtime;
  41. form.onQuery();
  42. }
  43. }
  44. }
  45. }, '->', {
  46. name: 'export',
  47. text: $I18N.common.button.erpExportButton,
  48. iconCls: 'x-button-icon-excel',
  49. cls: 'x-btn-gray',
  50. handler: function(btn){
  51. var grid = Ext.getCmp('querygrid');
  52. if(grid.xtype == 'erpQueryGridPanel') {
  53. var condition = grid.defaultCondition || '';
  54. condition = btn.ownerCt.ownerCt.spellCondition(condition);
  55. if(Ext.isEmpty(condition)) {
  56. condition = grid.emptyCondition || '1=1';
  57. }
  58. grid.BaseUtil.createExcel(caller, 'detailgrid', condition);
  59. } else if(grid.xtype == 'erpDatalistGridPanel') {
  60. var condition = grid.getCondition() || '';
  61. condition = btn.ownerCt.ownerCt.spellCondition(condition);
  62. if(Ext.isEmpty(condition)) {
  63. condition = '1=1';
  64. }
  65. if(typeof grid.getCondition === 'function') {
  66. condition += ' and ' + grid.getCondition();
  67. }
  68. grid.BaseUtil.createExcel(caller, 'datalist', condition);
  69. } else {
  70. btn.ownerCt.ownerCt.BaseUtil.exportGrid(grid);
  71. }
  72. }
  73. }, '-',{
  74. name: 'refresh',
  75. text: $I18N.common.button.erpRefreshButton,
  76. iconCls: 'x-button-icon-check',
  77. cls: 'x-btn-gray'
  78. }, {
  79. text: $I18N.common.button.erpCloseButton,
  80. iconCls: 'x-button-icon-close',
  81. cls: 'x-btn-gray',
  82. id:'close',
  83. handler: function(){
  84. var main = parent.Ext.getCmp("content-panel");
  85. main.getActiveTab().close();
  86. }
  87. }],
  88. initComponent : function(){
  89. this.getItemsAndButtons();
  90. this.callParent(arguments);
  91. this.addKeyBoardEvents();
  92. },
  93. onQuery: function() {
  94. var grid = Ext.getCmp('querygrid');
  95. if(!grid){
  96. grid = Ext.getCmp('grid');
  97. }
  98. var form = this;
  99. var error = form.check();
  100. if(error!=""){
  101. showError("[" + error.slice(0, -1) + "]不允许为空");
  102. return false;
  103. }
  104. //特殊校验
  105. if("BarSmtReduce!Query" ==caller || "BarSmtReduce!Query2" ==caller ){
  106. error = form.specialCheck();
  107. if(error!=""){
  108. showError(error);
  109. return false;
  110. }
  111. }
  112. var condition = grid.defaultCondition || '';
  113. condition = form.spellCondition(condition);
  114. if(Ext.isEmpty(condition)) {
  115. condition = grid.emptyCondition || '1=1';
  116. }
  117. form.beforeQuery(caller, condition);
  118. var gridParam = {caller: caller, condition: condition, start: 1, end: getUrlParam('_end')||1000};
  119. grid.GridUtil.loadNewStore(grid, gridParam);
  120. },
  121. spellCondition: function(condition){
  122. var form = this;
  123. Ext.each(form.items.items, function(f){
  124. if(f.logic != null && f.logic != ''){
  125. if(f.xtype == 'checkbox' && f.value == true){
  126. if(condition == ''){
  127. condition += f.logic;
  128. } else {
  129. condition += ' AND ' + f.logic;
  130. }
  131. } else if(f.xtype == 'datefield' && f.value != null){
  132. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  133. if(condition == ''){
  134. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  135. } else {
  136. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  137. }
  138. } else if(f.xtype == 'datetimefield' && f.value != null){
  139. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  140. if(condition == ''){
  141. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  142. } else {
  143. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  144. }
  145. } else if(f.xtype == 'numberfield' && f.value != null && f.value != ''){
  146. if(condition == ''){
  147. condition += f.logic + '=' + f.value;
  148. } else {
  149. condition += ' AND ' + f.logic + '=' + f.value;
  150. }
  151. } else if(f.xtype == 'yeardatefield' && f.value != null && f.value != ''){
  152. if(condition == ''){
  153. condition += f.logic + '=' + f.value;
  154. } else {
  155. condition += ' AND ' + f.logic + '=' + f.value;
  156. }
  157. }else if(f.xtype == 'combo' && f.value == '$ALL'){
  158. if(f.store.data.length > 1) {
  159. if(condition == ''){
  160. condition += '(';
  161. } else {
  162. condition += ' AND (';
  163. }
  164. var _a = '';
  165. f.store.each(function(d, idx){
  166. if(d.data.value != '$ALL') {
  167. if(_a == ''){
  168. _a += f.logic + "='" + d.data.value + "'";
  169. } else {
  170. _a += ' OR ' + f.logic + "='" + d.data.value + "'";
  171. }
  172. }
  173. });
  174. condition += _a + ')';
  175. }
  176. } else if(f.xtype=='adddbfindtrigger' && f.value != null && f.value != ''){
  177. if(condition == ''){
  178. condition += f.logic + ' in (' ;
  179. } else {
  180. condition += ' AND ' + f.logic + ' in (';
  181. }
  182. var str=f.value,constr="";
  183. for(var i=0;i<str.split("#").length;i++){
  184. if(i<str.split("#").length-1){
  185. constr+="'"+str.split("#")[i]+"',";
  186. }else constr+="'"+str.split("#")[i]+"'";
  187. }
  188. condition +=constr+")";
  189. } else {
  190. if(f.value != null && f.value != ''){
  191. var val = String(f.value);
  192. if(contains(val, 'BETWEEN', true) && contains(val, 'AND', true)){
  193. if(condition == ''){
  194. condition += f.logic + " " + f.value;
  195. } else {
  196. condition += ' AND (' + f.logic + " " + f.value + ")";
  197. }
  198. } else if(f.logic == 'ym_view_param') {
  199. if(condition == ''){
  200. condition += " " + f.value;
  201. } else {
  202. condition += ' AND (' + f.value + ")";
  203. }
  204. } else if(contains(val, '||', true)){
  205. var str = '';
  206. Ext.each(f.value.split('||'), function(v){
  207. if(v != null && v != ''){
  208. if(str == ''){
  209. str += f.logic + "='" + v + "'";
  210. } else {
  211. str += ' OR ' + f.logic + "='" + v + "'";
  212. }
  213. }
  214. });
  215. if(condition == ''){
  216. condition += str;
  217. } else {
  218. condition += ' AND (' + str + ")";
  219. }
  220. } else {
  221. if(val.indexOf('%') >= 0) {
  222. if(condition == ''){
  223. condition += f.logic + " like '" + f.value + "'";
  224. } else {
  225. condition += ' AND (' + f.logic + " like '" + f.value + "')";
  226. }
  227. } else {
  228. if(f.logic=='CONDITION'){
  229. if(condition == ''){
  230. condition += f.value ;
  231. } else {
  232. condition += ' AND ' + f.value;
  233. }
  234. }else{
  235. if(condition == ''){
  236. condition += f.logic + "='" + f.value + "'";
  237. } else {
  238. condition += ' AND (' + f.logic + "='" + f.value + "')";
  239. }
  240. }
  241. }
  242. }
  243. }
  244. }
  245. }
  246. });
  247. return condition;
  248. },
  249. _noc: 0,
  250. getItemsAndButtons: function(){
  251. var me = this;
  252. this.setLoading(true);
  253. Ext.Ajax.request({//鎷垮埌form鐨刬tems
  254. url : basePath + 'common/singleFormItems.action',
  255. params: {
  256. caller: caller,
  257. condition: '',
  258. _noc: (getUrlParam('_noc') || me._noc)
  259. },
  260. method : 'post',
  261. callback : function(options,success,response){
  262. me.setLoading(false);
  263. var res = new Ext.decode(response.responseText);
  264. if(res.exceptionInfo != null){
  265. showError(res.exceptionInfo);return;
  266. }
  267. me.fo_keyField = res.fo_keyField;
  268. me.tablename = res.tablename;
  269. me.fo_id=res.fo_id;
  270. if(res.keyField){
  271. me.keyField = res.keyField;
  272. }
  273. if(res.dealUrl){
  274. me.dealUrl = res.dealUrl;
  275. }
  276. me.fo_detailMainKeyField = res.fo_detailMainKeyField;
  277. var necessaryCss = res.necessaryFieldColor;
  278. Ext.each(res.items, function(item){
  279. if(screen.width < 1280){//鏍规嵁灞忓箷瀹藉害锛岃皟鏁村垪鏄剧ず瀹藉害
  280. if(item.columnWidth > 0 && item.columnWidth <= 0.25){
  281. item.columnWidth = 1/3;
  282. } else if(item.columnWidth > 0.25 && item.columnWidth <= 0.5){
  283. item.columnWidth = 2/3;
  284. } else if(item.columnWidth >= 1){
  285. item.columnWidth = 1;
  286. }
  287. } else {
  288. if(item.columnWidth > 0.25 && item.columnWidth < 0.5){
  289. item.columnWidth = 2/3;
  290. }
  291. }
  292. if(!item.allowBlank && item.fieldLabel && necessaryCss) {
  293. item.labelStyle = 'color:#' + necessaryCss;
  294. item.fieldStyle = 'background:#FFFAFA;color:#515151;'
  295. }
  296. if(item.xtype == 'hidden') {
  297. item.columnWidth = 0;
  298. }
  299. });
  300. me.add(res.items);
  301. me.fireEvent('alladded', me);
  302. //瑙f瀽buttons瀛楃涓诧紝骞舵嫾鎴恓son鏍煎紡
  303. var buttonString = res.buttons;
  304. if(buttonString != null && buttonString != ''){
  305. if(contains(buttonString, '#', true)){
  306. Ext.each(buttonString.split('#'), function(b, index){
  307. if(!Ext.getCmp(b)){
  308. var btn = Ext.getCmp('erpVastDealButton');
  309. if(btn){
  310. btn.ownerCt.insert(2, {
  311. xtype: b
  312. });
  313. }
  314. } else {
  315. Ext.getCmp(b).show();
  316. }
  317. });
  318. } else {
  319. if(Ext.getCmp(buttonString)){
  320. Ext.getCmp(buttonString).show();
  321. } else {
  322. var btn = Ext.getCmp('erpVastDealButton');//Ext.getCmp(buttonString);
  323. if(btn){
  324. btn.setText($I18N.common.button[buttonString]);
  325. btn.show();
  326. }
  327. }
  328. }
  329. }
  330. }
  331. });
  332. },
  333. /**
  334. * 监听一些事件
  335. * <br>
  336. * Ctrl+Alt+S 单据配置维护
  337. * Ctrl+Alt+P 参数、逻辑配置维护
  338. */
  339. addKeyBoardEvents: function(){
  340. var me = this;
  341. Ext.EventManager.addListener(document.body, 'keydown', function(e){
  342. if(e.altKey && e.ctrlKey) {
  343. if(e.keyCode == Ext.EventObject.S) {
  344. var url = "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id + "&gridCondition=fd_foidIS" + me.fo_id,
  345. forms = Ext.ComponentQuery.query('form'),
  346. grids = Ext.ComponentQuery.query('gridpanel'),
  347. formSet = [], gridSet = [];
  348. if(forms.length > 0) {
  349. Ext.Array.each(forms, function(f){
  350. f.fo_id && (formSet.push(f.fo_id));
  351. });
  352. }
  353. if(grids.length > 0) {
  354. Ext.Array.each(grids, function(g){
  355. if(g.xtype.indexOf('erpQueryGridPanel') > -1)
  356. gridSet.push(window.caller);
  357. else if(g.caller)
  358. gridSet.push(g.caller);
  359. });
  360. }
  361. if(formSet.length > 0 || gridSet.length > 0) {
  362. url = "jsps/ma/multiform.jsp?formParam=" + formSet.join(',') + '&gridParam=' + gridSet.join(',');
  363. }
  364. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', url);
  365. } else if(e.keyCode == Ext.EventObject.P) {
  366. me.FormUtil.onAdd('configs-' + caller, '逻辑配置维护(' + caller + ')', "jsps/ma/logic/config.jsp?whoami=" + caller);
  367. }
  368. }
  369. });
  370. },
  371. beforeQuery: function(call, cond) {
  372. Ext.Ajax.request({
  373. url: basePath + 'common/form/beforeQuery.action',
  374. params: {
  375. caller: call,
  376. condition: cond
  377. },
  378. async: false,
  379. callback: function(opt, s, r) {
  380. var rs = Ext.decode(r.responseText);
  381. if(rs.exceptionInfo) {
  382. showError(rs.exceptionInfo);
  383. }
  384. }
  385. });
  386. },
  387. check: function(){
  388. var allowBlank = "";
  389. var items = this.items.items
  390. Ext.each(items, function(item){
  391. if(!item.allowBlank&&item.getRawValue()==""){
  392. allowBlank += item.fieldLabel + ",";
  393. }
  394. });
  395. return allowBlank;
  396. },
  397. specialCheck:function(){
  398. var re = "";
  399. if("BarSmtReduce!Query2"==caller) {
  400. //fieldLabel
  401. var bar = Ext.getCmp("msl_barcode");
  402. var macode = Ext.getCmp("SMT_MS_MAKECODE");
  403. var vendbar = Ext.getCmp("bar_vendbarcode");
  404. if(bar && bar.value == ""){
  405. if((vendbar && vendbar.value == "") && (macode && macode.value == "")){
  406. re ="料卷号或者工单号需要必填其中一个项!";
  407. return re;
  408. }
  409. if((vendbar && vendbar.value == "") || (macode && macode.value == "")){
  410. re ="料卷号未填写时,工单号必填!";
  411. return re;
  412. }
  413. }
  414. if(!bar || !macode || !vendbar){
  415. re ="主表筛选字段必须包含料卷号、工单号、供应商批号!";
  416. return re;
  417. }
  418. //msl_barcode,SMT_MS_MAKECODE 、bar_vendbarcode
  419. }else if("BarSmtReduce!Query"==caller) {
  420. //msl_barcode ,SMT_MS_MAKECODE,bar_vendbarcode ,msl_prodcode
  421. var bar = Ext.getCmp("msl_barcode");
  422. var macode = Ext.getCmp("SMT_MS_MAKECODE");
  423. var vendbar = Ext.getCmp("bar_vendbarcode");
  424. var prodcode = Ext.getCmp("msl_prodcode");
  425. if(bar && bar.value == ""){
  426. if((vendbar && vendbar.value == "") && (macode && macode.value == "") && (prodcode && prodcode.value == "")){
  427. re ="料卷号或者(工单号+物料编号)需要必填其中一个项!";
  428. return re;
  429. }
  430. if((vendbar && vendbar.value == "") || (macode && macode.value == "") || (prodcode && macode.prodcode == "")){
  431. re ="料卷号未填写时,工单号、物料编号都必填!";
  432. return re;
  433. }
  434. }
  435. if(!bar || !macode || !vendbar || !prodcode){
  436. re ="主表筛选条件必须包含料卷号、工单号、供应商批号、物料编号!";
  437. return re;
  438. }
  439. }
  440. return re;
  441. }
  442. });