Form.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. Ext.define('erp.view.pm.bom.CompareBom.Form',{
  2. extend: 'Ext.form.Panel',
  3. alias: 'widget.erpQueryFormPanel1',
  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. tbar: [{
  22. id:'query',
  23. name: 'query',
  24. text: $I18N.common.button.erpQueryButton,
  25. iconCls: 'x-button-icon-query',
  26. cls: 'x-btn-gray',
  27. /*handler: function(btn){
  28. btn.ownerCt.ownerCt.onQuery();
  29. }*/
  30. }, '->', {
  31. name: 'export',
  32. text: $I18N.common.button.erpExportButton,
  33. iconCls: 'x-button-icon-submit',
  34. cls: 'x-btn-gray',
  35. handler: function(btn){
  36. var grid = Ext.getCmp('querygrid');
  37. grid.BaseUtil.exportGrid(grid);
  38. }
  39. }, '-', {
  40. text: $I18N.common.button.erpCloseButton,
  41. iconCls: 'x-button-icon-close',
  42. cls: 'x-btn-gray',
  43. handler: function(){
  44. var main = parent.Ext.getCmp("content-panel");
  45. main.getActiveTab().close();
  46. }
  47. }],
  48. initComponent : function(){
  49. this.getItemsAndButtons();
  50. this.callParent(arguments);
  51. this.addKeyBoardEvents();
  52. },
  53. onQuery: function() {
  54. var grid = Ext.getCmp('querygrid');
  55. var form = this;
  56. var condition = grid.defaultCondition || '';
  57. condition = form.spellCondition(condition);
  58. form.beforeQuery(caller, condition);//执行查询前逻辑
  59. var gridParam = {caller: caller, condition: condition};
  60. grid.GridUtil.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', gridParam, "");
  61. },
  62. spellCondition: function(condition){
  63. var form = this;
  64. Ext.each(form.items.items, function(f){
  65. if(f.logic != null && f.logic != ''){
  66. if(f.xtype == 'checkbox' && f.value == true){
  67. if(condition == ''){
  68. condition += f.logic;
  69. } else {
  70. condition += ' AND ' + f.logic;
  71. }
  72. } else if(f.xtype == 'datefield' && f.value != null){
  73. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  74. if(condition == ''){
  75. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  76. } else {
  77. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  78. }
  79. } else if(f.xtype == 'datetimefield' && f.value != null){
  80. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  81. if(condition == ''){
  82. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  83. } else {
  84. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  85. }
  86. } else if(f.xtype == 'numberfield' && f.value != null && f.value != ''){
  87. if(condition == ''){
  88. condition += f.logic + '=' + f.value;
  89. } else {
  90. condition += ' AND ' + f.logic + '=' + f.value;
  91. }
  92. } else {
  93. if(f.value != null && f.value != ''){
  94. if(contains(f.value, 'BETWEEN', true) && contains(f.value, 'AND', true)){
  95. if(condition == ''){
  96. condition += f.logic + " " + f.value;
  97. } else {
  98. condition += ' AND (' + f.logic + " " + f.value + ")";
  99. }
  100. } else if(contains(f.value, '||', true)){
  101. var str = '';
  102. Ext.each(f.value.split('||'), function(v){
  103. if(v != null && v != ''){
  104. if(str == ''){
  105. str += f.logic + "='" + v + "'";
  106. } else {
  107. str += ' OR ' + f.logic + "='" + v + "'";
  108. }
  109. }
  110. });
  111. if(condition == ''){
  112. condition += str;
  113. } else {
  114. condition += ' AND (' + str + ")";
  115. }
  116. } else {
  117. if(condition == ''){
  118. condition += f.logic + "='" + f.value + "'";
  119. } else {
  120. condition += ' AND (' + f.logic + "='" + f.value + "')";
  121. }
  122. }
  123. }
  124. }
  125. }
  126. });
  127. return condition;
  128. },
  129. getItemsAndButtons: function(){
  130. var me = this;
  131. this.setLoading(true);
  132. Ext.Ajax.request({//拿到form的items
  133. url : basePath + 'common/singleFormItems.action',
  134. params: {
  135. caller: caller,
  136. condition: ''
  137. },
  138. method : 'post',
  139. callback : function(options,success,response){
  140. me.setLoading(false);
  141. var res = new Ext.decode(response.responseText);
  142. if(res.exceptionInfo != null){
  143. showError(res.exceptionInfo);return;
  144. }
  145. me.fo_keyField = res.fo_keyField;
  146. me.tablename = res.tablename;
  147. me.fo_id=res.fo_id;
  148. if(res.keyField){
  149. me.keyField = res.keyField;
  150. }
  151. if(res.dealUrl){
  152. me.dealUrl = res.dealUrl;
  153. }
  154. me.fo_detailMainKeyField = res.fo_detailMainKeyField;
  155. Ext.each(res.items, function(item){
  156. if(screen.width < 1280){//根据屏幕宽度,调整列显示宽度
  157. if(item.columnWidth > 0 && item.columnWidth <= 0.25){
  158. item.columnWidth = 1/3;
  159. } else if(item.columnWidth > 0.25 && item.columnWidth <= 0.5){
  160. item.columnWidth = 2/3;
  161. } else if(item.columnWidth >= 1){
  162. item.columnWidth = 1;
  163. }
  164. } else {
  165. if(item.columnWidth > 0.25 && item.columnWidth < 0.5){
  166. item.columnWidth = 2/3;
  167. }
  168. }
  169. if(item.xtype == 'hidden') {
  170. item.columnWidth = 0;
  171. }
  172. });
  173. me.add(res.items);
  174. me.fireEvent('alladded', me);
  175. //解析buttons字符串,并拼成json格式
  176. var buttonString = res.buttons;
  177. if(buttonString != null && buttonString != ''){
  178. if(contains(buttonString, '#', true)){
  179. Ext.each(buttonString.split('#'), function(b, index){
  180. if(!Ext.getCmp(b)){
  181. var btn = Ext.getCmp('erpVastDealButton');
  182. if(btn){
  183. btn.ownerCt.insert(2, {
  184. xtype: b
  185. });
  186. }
  187. } else {
  188. Ext.getCmp(b).show();
  189. }
  190. });
  191. } else {
  192. if(Ext.getCmp(buttonString)){
  193. Ext.getCmp(buttonString).show();
  194. } else {
  195. var btn = Ext.getCmp('erpVastDealButton');//Ext.getCmp(buttonString);
  196. if(btn){
  197. btn.setText($I18N.common.button[buttonString]);
  198. btn.show();
  199. }
  200. }
  201. }
  202. }
  203. }
  204. });
  205. },
  206. addKeyBoardEvents: function(){
  207. var me = this;
  208. if(Ext.isIE){
  209. document.body.attachEvent('onkeydown', function(){//ie的事件名称不同,也不支持addEventListener
  210. if(window.event.altKey && window.event.ctrlKey && window.event.keyCode == 83){
  211. if(Ext.ComponentQuery.query('gridpanel').length > 0){//有grid
  212. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  213. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  214. } else {
  215. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id +
  216. "&gridCondition=fd_foidIS" + me.fo_id);
  217. }
  218. }
  219. });
  220. document.body.attachEvent("onmouseover", function(){
  221. if(window.event.ctrlKey){
  222. var e = window.event;
  223. me.Contextvalue = e.target.textContent == "" ? e.target.value : e.target.textContent;
  224. textarea_text = parent.document.getElementById("textarea_text");
  225. textarea_text.value = me.Contextvalue;
  226. textarea_text.focus();
  227. textarea_text.select();
  228. }
  229. });
  230. } else {
  231. document.body.addEventListener("keydown", function(e){
  232. if(Ext.isFF5){//firefox不支持window.event
  233. e = e || window.event;
  234. }
  235. if(e.altKey && e.ctrlKey && e.keyCode == 83){
  236. if(Ext.ComponentQuery.query('gridpanel').length > 0){//有grid
  237. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  238. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  239. } else {
  240. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id +
  241. "&gridCondition=fd_foidIS" + me.fo_id);
  242. }
  243. }
  244. });
  245. document.body.addEventListener("mouseover", function(e){
  246. if(Ext.isFF5){
  247. e = e || window.event;
  248. }
  249. if(e.ctrlKey){
  250. me.Contextvalue = e.target.textContent == "" ? e.target.value : e.target.textContent;
  251. textarea_text = parent.document.getElementById("textarea_text");
  252. textarea_text.value = me.Contextvalue;
  253. textarea_text.focus();
  254. textarea_text.select();
  255. }
  256. });
  257. }
  258. },
  259. beforeQuery: function(call, cond) {
  260. Ext.Ajax.request({
  261. url: basePath + 'common/form/beforeQuery.action',
  262. params: {
  263. caller: call,
  264. condition: cond
  265. },
  266. async: false,
  267. callback: function(opt, s, r) {
  268. var rs = Ext.decode(r.responseText);
  269. if(rs.exceptionInfo) {
  270. showError(rs.exceptionInfo);
  271. }
  272. }
  273. });
  274. }
  275. });