CheckForm.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. var condition = grid.defaultCondition || '';
  105. condition = form.spellCondition(condition);
  106. if(Ext.isEmpty(condition)) {
  107. condition = grid.emptyCondition || '1=1';
  108. }
  109. form.beforeQuery(caller, condition);//鎵ц鏌ヨ鍓嶉�杈�
  110. var gridParam = {caller: caller, condition: condition, start: 1, end: getUrlParam('_end')||1000};
  111. grid.GridUtil.loadNewStore(grid, gridParam);
  112. },
  113. spellCondition: function(condition){
  114. var form = this;
  115. Ext.each(form.items.items, function(f){
  116. if(f.logic != null && f.logic != ''){
  117. if(f.xtype == 'checkbox' && f.value == true){
  118. if(condition == ''){
  119. condition += f.logic;
  120. } else {
  121. condition += ' AND ' + f.logic;
  122. }
  123. } else if(f.xtype == 'datefield' && f.value != null){
  124. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  125. if(condition == ''){
  126. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  127. } else {
  128. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  129. }
  130. } else if(f.xtype == 'datetimefield' && f.value != null){
  131. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  132. if(condition == ''){
  133. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  134. } else {
  135. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  136. }
  137. } else if(f.xtype == 'numberfield' && f.value != null && f.value != ''){
  138. if(condition == ''){
  139. condition += f.logic + '=' + f.value;
  140. } else {
  141. condition += ' AND ' + f.logic + '=' + f.value;
  142. }
  143. } else if(f.xtype == 'yeardatefield' && f.value != null && f.value != ''){
  144. if(condition == ''){
  145. condition += f.logic + '=' + f.value;
  146. } else {
  147. condition += ' AND ' + f.logic + '=' + f.value;
  148. }
  149. }else if(f.xtype == 'combo' && f.value == '$ALL'){
  150. if(f.store.data.length > 1) {
  151. if(condition == ''){
  152. condition += '(';
  153. } else {
  154. condition += ' AND (';
  155. }
  156. var _a = '';
  157. f.store.each(function(d, idx){
  158. if(d.data.value != '$ALL') {
  159. if(_a == ''){
  160. _a += f.logic + "='" + d.data.value + "'";
  161. } else {
  162. _a += ' OR ' + f.logic + "='" + d.data.value + "'";
  163. }
  164. }
  165. });
  166. condition += _a + ')';
  167. }
  168. } else if(f.xtype=='adddbfindtrigger' && f.value != null && f.value != ''){
  169. if(condition == ''){
  170. condition += f.logic + ' in (' ;
  171. } else {
  172. condition += ' AND ' + f.logic + ' in (';
  173. }
  174. var str=f.value,constr="";
  175. for(var i=0;i<str.split("#").length;i++){
  176. if(i<str.split("#").length-1){
  177. constr+="'"+str.split("#")[i]+"',";
  178. }else constr+="'"+str.split("#")[i]+"'";
  179. }
  180. condition +=constr+")";
  181. } else {
  182. if(f.value != null && f.value != ''){
  183. var val = String(f.value);
  184. if(contains(val, 'BETWEEN', true) && contains(val, 'AND', true)){
  185. if(condition == ''){
  186. condition += f.logic + " " + f.value;
  187. } else {
  188. condition += ' AND (' + f.logic + " " + f.value + ")";
  189. }
  190. } else if(f.logic == 'ym_view_param') {
  191. if(condition == ''){
  192. condition += " " + f.value;
  193. } else {
  194. condition += ' AND (' + f.value + ")";
  195. }
  196. } else if(contains(val, '||', true)){
  197. var str = '';
  198. Ext.each(f.value.split('||'), function(v){
  199. if(v != null && v != ''){
  200. if(str == ''){
  201. str += f.logic + "='" + v + "'";
  202. } else {
  203. str += ' OR ' + f.logic + "='" + v + "'";
  204. }
  205. }
  206. });
  207. if(condition == ''){
  208. condition += str;
  209. } else {
  210. condition += ' AND (' + str + ")";
  211. }
  212. } else {
  213. if(val.indexOf('%') >= 0) {
  214. if(condition == ''){
  215. condition += f.logic + " like '" + f.value + "'";
  216. } else {
  217. condition += ' AND (' + f.logic + " like '" + f.value + "')";
  218. }
  219. } else {
  220. if(f.logic=='CONDITION'){
  221. if(condition == ''){
  222. condition += f.value ;
  223. } else {
  224. condition += ' AND ' + f.value;
  225. }
  226. }else{
  227. if(condition == ''){
  228. condition += f.logic + "='" + f.value + "'";
  229. } else {
  230. condition += ' AND (' + f.logic + "='" + f.value + "')";
  231. }
  232. }
  233. }
  234. }
  235. }
  236. }
  237. }
  238. });
  239. return condition;
  240. },
  241. _noc: 0,
  242. getItemsAndButtons: function(){
  243. var me = this;
  244. this.setLoading(true);
  245. Ext.Ajax.request({//鎷垮埌form鐨刬tems
  246. url : basePath + 'common/singleFormItems.action',
  247. params: {
  248. caller: caller,
  249. condition: '',
  250. _noc: (getUrlParam('_noc') || me._noc)
  251. },
  252. method : 'post',
  253. callback : function(options,success,response){
  254. me.setLoading(false);
  255. var res = new Ext.decode(response.responseText);
  256. if(res.exceptionInfo != null){
  257. showError(res.exceptionInfo);return;
  258. }
  259. me.fo_keyField = res.fo_keyField;
  260. me.tablename = res.tablename;
  261. me.fo_id=res.fo_id;
  262. if(res.keyField){
  263. me.keyField = res.keyField;
  264. }
  265. if(res.dealUrl){
  266. me.dealUrl = res.dealUrl;
  267. }
  268. me.fo_detailMainKeyField = res.fo_detailMainKeyField;
  269. var necessaryCss = res.necessaryFieldColor;
  270. Ext.each(res.items, function(item){
  271. if(screen.width < 1280){//鏍规嵁灞忓箷瀹藉害锛岃皟鏁村垪鏄剧ず瀹藉害
  272. if(item.columnWidth > 0 && item.columnWidth <= 0.25){
  273. item.columnWidth = 1/3;
  274. } else if(item.columnWidth > 0.25 && item.columnWidth <= 0.5){
  275. item.columnWidth = 2/3;
  276. } else if(item.columnWidth >= 1){
  277. item.columnWidth = 1;
  278. }
  279. } else {
  280. if(item.columnWidth > 0.25 && item.columnWidth < 0.5){
  281. item.columnWidth = 2/3;
  282. }
  283. }
  284. if(!item.allowBlank && item.fieldLabel && necessaryCss) {
  285. item.labelStyle = 'color:#' + necessaryCss;
  286. item.fieldStyle = 'background:#FFFAFA;color:#515151;'
  287. }
  288. if(item.xtype == 'hidden') {
  289. item.columnWidth = 0;
  290. }
  291. });
  292. me.add(res.items);
  293. me.fireEvent('alladded', me);
  294. //瑙f瀽buttons瀛楃涓诧紝骞舵嫾鎴恓son鏍煎紡
  295. var buttonString = res.buttons;
  296. if(buttonString != null && buttonString != ''){
  297. if(contains(buttonString, '#', true)){
  298. Ext.each(buttonString.split('#'), function(b, index){
  299. if(!Ext.getCmp(b)){
  300. var btn = Ext.getCmp('erpVastDealButton');
  301. if(btn){
  302. btn.ownerCt.insert(2, {
  303. xtype: b
  304. });
  305. }
  306. } else {
  307. Ext.getCmp(b).show();
  308. }
  309. });
  310. } else {
  311. if(Ext.getCmp(buttonString)){
  312. Ext.getCmp(buttonString).show();
  313. } else {
  314. var btn = Ext.getCmp('erpVastDealButton');//Ext.getCmp(buttonString);
  315. if(btn){
  316. btn.setText($I18N.common.button[buttonString]);
  317. btn.show();
  318. }
  319. }
  320. }
  321. }
  322. }
  323. });
  324. },
  325. /**
  326. * 监听一些事件
  327. * <br>
  328. * Ctrl+Alt+S 单据配置维护
  329. * Ctrl+Alt+P 参数、逻辑配置维护
  330. */
  331. addKeyBoardEvents: function(){
  332. var me = this;
  333. Ext.EventManager.addListener(document.body, 'keydown', function(e){
  334. if(e.altKey && e.ctrlKey) {
  335. if(e.keyCode == Ext.EventObject.S) {
  336. var url = "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id + "&gridCondition=fd_foidIS" + me.fo_id,
  337. forms = Ext.ComponentQuery.query('form'),
  338. grids = Ext.ComponentQuery.query('gridpanel'),
  339. formSet = [], gridSet = [];
  340. if(forms.length > 0) {
  341. Ext.Array.each(forms, function(f){
  342. f.fo_id && (formSet.push(f.fo_id));
  343. });
  344. }
  345. if(grids.length > 0) {
  346. Ext.Array.each(grids, function(g){
  347. if(g.xtype.indexOf('erpQueryGridPanel') > -1)
  348. gridSet.push(window.caller);
  349. else if(g.caller)
  350. gridSet.push(g.caller);
  351. });
  352. }
  353. if(formSet.length > 0 || gridSet.length > 0) {
  354. url = "jsps/ma/multiform.jsp?formParam=" + formSet.join(',') + '&gridParam=' + gridSet.join(',');
  355. }
  356. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', url);
  357. } else if(e.keyCode == Ext.EventObject.P) {
  358. me.FormUtil.onAdd('configs-' + caller, '逻辑配置维护(' + caller + ')', "jsps/ma/logic/config.jsp?whoami=" + caller);
  359. }
  360. }
  361. });
  362. },
  363. beforeQuery: function(call, cond) {
  364. Ext.Ajax.request({
  365. url: basePath + 'common/form/beforeQuery.action',
  366. params: {
  367. caller: call,
  368. condition: cond
  369. },
  370. async: false,
  371. callback: function(opt, s, r) {
  372. var rs = Ext.decode(r.responseText);
  373. if(rs.exceptionInfo) {
  374. showError(rs.exceptionInfo);
  375. }
  376. }
  377. });
  378. },
  379. check: function(){
  380. var allowBlank = "";
  381. var items = this.items.items
  382. Ext.each(items, function(item){
  383. if(!item.allowBlank&&item.getRawValue()==""){
  384. allowBlank += item.fieldLabel + ",";
  385. }
  386. });
  387. return allowBlank;
  388. }
  389. });