Form.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. ,{
  47. name: 'export',
  48. text: $I18N.common.button.erpExportButton,
  49. iconCls: 'x-button-icon-excel',
  50. cls: 'x-btn-gray',
  51. handler: function(btn){
  52. var grid = Ext.getCmp('querygrid');
  53. if(grid.xtype == 'erpQueryGridPanel') {
  54. var condition = grid.defaultCondition || '';
  55. condition = btn.ownerCt.ownerCt.spellCondition(condition);
  56. if(Ext.isEmpty(condition)) {
  57. condition = grid.emptyCondition || '1=1';
  58. }
  59. grid.BaseUtil.createExcel(caller, 'detailgrid', condition, null, null, null, grid);
  60. } else if(grid.xtype == 'erpDatalistGridPanel') {
  61. var 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, null, null, null, grid);
  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 {
  177. if(f.value != null && f.value != ''){
  178. var val = String(f.value);
  179. if(contains(val, 'BETWEEN', true) && contains(val, 'AND', true)){
  180. if(condition == ''){
  181. condition += f.logic + " " + f.value;
  182. } else {
  183. condition += ' AND (' + f.logic + " " + f.value + ")";
  184. }
  185. } else if(f.logic == 'ym_view_param') {
  186. if(condition == ''){
  187. condition += " " + f.value;
  188. } else {
  189. condition += ' AND (' + f.value + ")";
  190. }
  191. } else if(contains(val, '||', true)){
  192. var str = '';
  193. Ext.each(f.value.split('||'), function(v){
  194. if(v != null && v != ''){
  195. if(str == ''){
  196. str += f.logic + "='" + v + "'";
  197. } else {
  198. str += ' OR ' + f.logic + "='" + v + "'";
  199. }
  200. }
  201. });
  202. if(condition == ''){
  203. condition += str;
  204. } else {
  205. condition += ' AND (' + str + ")";
  206. }
  207. } else {
  208. if(val.indexOf('%') >= 0) {
  209. if(condition == ''){
  210. condition += f.logic + " like '" + f.value + "'";
  211. } else {
  212. condition += ' AND (' + f.logic + " like '" + f.value + "')";
  213. }
  214. } else {
  215. if(f.logic=='CONDITION'){
  216. if(condition == ''){
  217. condition += f.value ;
  218. } else {
  219. condition += ' AND ' + f.value;
  220. }
  221. }else{
  222. if(condition == ''){
  223. condition += f.logic + "='" + f.value + "'";
  224. } else {
  225. condition += ' AND (' + f.logic + "='" + f.value + "')";
  226. }
  227. }
  228. }
  229. }
  230. }
  231. }
  232. }
  233. });
  234. return condition;
  235. },
  236. _noc: 0,
  237. getItemsAndButtons: function(){
  238. var me = this;
  239. this.setLoading(true);
  240. Ext.Ajax.request({//拿到form的items
  241. url : basePath + 'common/singleFormItems.action',
  242. params: {
  243. caller: caller,
  244. condition: '',
  245. _noc: (getUrlParam('_noc') || me._noc)
  246. },
  247. method : 'post',
  248. callback : function(options,success,response){
  249. me.setLoading(false);
  250. var res = new Ext.decode(response.responseText);
  251. if(res.exceptionInfo != null){
  252. showError(res.exceptionInfo);return;
  253. }
  254. me.fo_keyField = res.fo_keyField;
  255. me.tablename = res.tablename;
  256. me.fo_id=res.fo_id;
  257. if(res.keyField){
  258. me.keyField = res.keyField;
  259. }
  260. if(res.dealUrl){
  261. me.dealUrl = res.dealUrl;
  262. }
  263. me.fo_detailMainKeyField = res.fo_detailMainKeyField;
  264. Ext.each(res.items, function(item){
  265. if(screen.width < 1280){//根据屏幕宽度,调整列显示宽度
  266. if(item.columnWidth > 0 && item.columnWidth <= 0.25){
  267. item.columnWidth = 1/3;
  268. } else if(item.columnWidth > 0.25 && item.columnWidth <= 0.5){
  269. item.columnWidth = 2/3;
  270. } else if(item.columnWidth >= 1){
  271. item.columnWidth = 1;
  272. }
  273. } else {
  274. if(item.columnWidth > 0.25 && item.columnWidth < 0.5){
  275. item.columnWidth = 2/3;
  276. }
  277. }
  278. if(item.xtype == 'hidden') {
  279. item.columnWidth = 0;
  280. }
  281. });
  282. me.add(res.items);
  283. me.fireEvent('alladded', me);
  284. //解析buttons字符串,并拼成json格式
  285. var buttonString = res.buttons;
  286. if(buttonString != null && buttonString != ''){
  287. if(contains(buttonString, '#', true)){
  288. Ext.each(buttonString.split('#'), function(b, index){
  289. if(!Ext.getCmp(b)){
  290. var btn = Ext.getCmp('erpVastDealButton');
  291. if(btn){
  292. btn.ownerCt.insert(2, {
  293. xtype: b
  294. });
  295. }
  296. } else {
  297. Ext.getCmp(b).show();
  298. }
  299. });
  300. } else {
  301. if(Ext.getCmp(buttonString)){
  302. Ext.getCmp(buttonString).show();
  303. } else {
  304. var btn = Ext.getCmp('erpVastDealButton');//Ext.getCmp(buttonString);
  305. if(btn){
  306. btn.setText($I18N.common.button[buttonString]);
  307. btn.show();
  308. }
  309. }
  310. }
  311. }
  312. }
  313. });
  314. },
  315. addKeyBoardEvents: function(){
  316. var me = this;
  317. if(Ext.isIE){
  318. document.body.attachEvent('onkeydown', function(){//ie的事件名称不同,也不支持addEventListener
  319. if(window.event.altKey && window.event.ctrlKey && window.event.keyCode == 83){
  320. if(Ext.ComponentQuery.query('gridpanel').length > 0){//有grid
  321. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  322. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  323. } else {
  324. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id +
  325. "&gridCondition=fd_foidIS" + me.fo_id);
  326. }
  327. }
  328. });
  329. document.body.attachEvent("onmouseover", function(){
  330. if(window.event.ctrlKey){
  331. var e = window.event;
  332. me.Contextvalue = e.target.textContent == "" ? e.target.value : e.target.textContent;
  333. textarea_text = parent.document.getElementById("textarea_text");
  334. textarea_text.value = me.Contextvalue;
  335. textarea_text.focus();
  336. textarea_text.select();
  337. }
  338. });
  339. } else {
  340. document.body.addEventListener("keydown", function(e){
  341. if(Ext.isFF5){//firefox不支持window.event
  342. e = e || window.event;
  343. }
  344. if(e.altKey && e.ctrlKey && e.keyCode == 83){
  345. if(Ext.ComponentQuery.query('gridpanel').length > 0){//有grid
  346. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  347. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  348. } else {
  349. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id +
  350. "&gridCondition=fd_foidIS" + me.fo_id);
  351. }
  352. }
  353. });
  354. document.body.addEventListener("mouseover", function(e){
  355. if(Ext.isFF5){
  356. e = e || window.event;
  357. }
  358. if(e.ctrlKey){
  359. me.Contextvalue = e.target.textContent == "" ? e.target.value : e.target.textContent;
  360. textarea_text = parent.document.getElementById("textarea_text");
  361. textarea_text.value = me.Contextvalue;
  362. textarea_text.focus();
  363. textarea_text.select();
  364. }
  365. });
  366. }
  367. },
  368. beforeQuery: function(call, cond) {
  369. Ext.Ajax.request({
  370. url: basePath + 'common/form/beforeQuery.action',
  371. params: {
  372. caller: call,
  373. condition: cond
  374. },
  375. async: false,
  376. callback: function(opt, s, r) {
  377. var rs = Ext.decode(r.responseText);
  378. if(rs.exceptionInfo) {
  379. showError(rs.exceptionInfo);
  380. }
  381. }
  382. });
  383. }
  384. });