QueryForm.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. Ext.define('erp.view.fa.ars.cmQuery.QueryForm',{
  2. extend: 'Ext.form.Panel',
  3. alias: 'widget.erpCmQueryFormPanel',
  4. id: 'cmqueryform_'+caller,
  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. initComponent : function(){
  22. this.getItemsAndButtons();
  23. this.callParent(arguments);
  24. this.addKeyBoardEvents();
  25. },
  26. onQuery: function() {
  27. var grid = Ext.getCmp('cmquerygrid');
  28. var form = this;
  29. var condition = grid.defaultCondition || '';
  30. condition = form.spellCondition(condition);
  31. form.beforeQuery(caller, condition);//执行查询前逻辑
  32. var gridParam = {caller: caller, condition: condition};
  33. grid.GridUtil.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', gridParam, "");
  34. },
  35. spellCondition: function(condition){
  36. var form = this;
  37. Ext.each(form.items.items, function(f){
  38. if(f.logic != null && f.logic != ''){
  39. if(f.xtype == 'checkbox' && f.value == true){
  40. if(condition == ''){
  41. condition += f.logic;
  42. } else {
  43. condition += ' AND ' + f.logic;
  44. }
  45. } else if(f.xtype == 'datefield' && f.value != null){
  46. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  47. if(condition == ''){
  48. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  49. } else {
  50. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  51. }
  52. } else if(f.xtype == 'datetimefield' && f.value != null){
  53. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  54. if(condition == ''){
  55. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  56. } else {
  57. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  58. }
  59. } else if(f.xtype == 'numberfield' && f.value != null && f.value != ''){
  60. if(condition == ''){
  61. condition += f.logic + '=' + f.value;
  62. } else {
  63. condition += ' AND ' + f.logic + '=' + f.value;
  64. }
  65. } else {
  66. if(f.value != null && f.value != ''){
  67. if(contains(f.value, 'BETWEEN', true) && contains(f.value, 'AND', true)){
  68. if(condition == ''){
  69. condition += f.logic + " " + f.value;
  70. } else {
  71. condition += ' AND (' + f.logic + " " + f.value + ")";
  72. }
  73. } else if(contains(f.value, '||', true)){
  74. var str = '';
  75. Ext.each(f.value.split('||'), function(v){
  76. if(v != null && v != ''){
  77. if(str == ''){
  78. str += f.logic + "='" + v + "'";
  79. } else {
  80. str += ' OR ' + f.logic + "='" + v + "'";
  81. }
  82. }
  83. });
  84. if(condition == ''){
  85. condition += str;
  86. } else {
  87. condition += ' AND (' + str + ")";
  88. }
  89. } else {
  90. if(condition == ''){
  91. condition += f.logic + "='" + f.value + "'";
  92. } else {
  93. condition += ' AND (' + f.logic + "='" + f.value + "')";
  94. }
  95. }
  96. }
  97. }
  98. }
  99. });
  100. return condition;
  101. },
  102. getItemsAndButtons: function(){
  103. var me = this;
  104. this.setLoading(true);
  105. Ext.Ajax.request({//拿到form的items
  106. url : basePath + 'common/singleFormItems.action',
  107. params: {
  108. caller: caller,
  109. condition: ''
  110. },
  111. method : 'post',
  112. callback : function(options,success,response){
  113. me.setLoading(false);
  114. var res = new Ext.decode(response.responseText);
  115. if(res.exceptionInfo != null){
  116. showError(res.exceptionInfo);return;
  117. }
  118. me.fo_keyField = res.fo_keyField;
  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. btn.ownerCt.insert(2, {
  157. xtype: b
  158. });
  159. }
  160. } else {
  161. Ext.getCmp(b).show();
  162. }
  163. });
  164. } else {
  165. if(Ext.getCmp(buttonString)){
  166. Ext.getCmp(buttonString).show();
  167. } else {
  168. var btn = Ext.getCmp('erpVastDealButton');//Ext.getCmp(buttonString);
  169. if(btn){
  170. btn.setText($I18N.common.button[buttonString]);
  171. btn.show();
  172. }
  173. }
  174. }
  175. }
  176. }
  177. });
  178. },
  179. addKeyBoardEvents: function(){
  180. var me = this;
  181. if(Ext.isIE){
  182. document.body.attachEvent('onkeydown', function(){//ie的事件名称不同,也不支持addEventListener
  183. if(window.event.altKey && window.event.ctrlKey && window.event.keyCode == 83){
  184. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  185. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  186. }
  187. });
  188. } else {
  189. document.body.addEventListener("keydown", function(e){
  190. if(Ext.isFF5){//firefox不支持window.event
  191. e = e || window.event;
  192. }
  193. if(e.altKey && e.ctrlKey && e.keyCode == 83){
  194. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  195. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  196. }
  197. });
  198. }
  199. },
  200. beforeQuery: function(call, cond) {
  201. Ext.Ajax.request({
  202. url: basePath + 'common/form/beforeQuery.action',
  203. params: {
  204. caller: call,
  205. condition: cond
  206. },
  207. async: false,
  208. callback: function(opt, s, r) {
  209. var rs = Ext.decode(r.responseText);
  210. if(rs.exceptionInfo) {
  211. showError(rs.exceptionInfo);
  212. }
  213. }
  214. });
  215. }
  216. });