Form.js 12 KB

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