Form.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. Ext.define('erp.view.common.Batchlevel.Form',{
  2. extend: 'Ext.form.Panel',
  3. alias: 'widget.erpBatchDealFormPanel',
  4. id: 'dealform',
  5. region: 'north',
  6. frame : true,
  7. header: false,//不显示title
  8. layout : 'column',
  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. tbar: [{
  21. name: 'query',
  22. id: 'query',
  23. text: $I18N.common.button.erpQueryButton,
  24. iconCls: 'x-button-icon-query',
  25. cls: 'x-btn-gray',
  26. handler: function(){
  27. Ext.getCmp('dealform').onQuery();
  28. }
  29. }, '->', {
  30. xtype: 'erpMakeOccurButton',
  31. id: 'erpMakeOccurButton',
  32. hidden: true
  33. },
  34. {
  35. xtype: 'erpSaleOccurButton',
  36. id: 'erpSaleOccurButton',
  37. hidden: true
  38. },
  39. {
  40. xtype: 'erpVastAnalyseButton',
  41. id: 'erpVastAnalyseButton',
  42. hidden: true
  43. },{
  44. xtype: 'erpVastDealButton',
  45. id: 'erpVastDealButton',
  46. hidden: true
  47. },'-',{
  48. name: 'export',
  49. text: $I18N.common.button.erpExportButton,
  50. iconCls: 'x-button-icon-excel',
  51. cls: 'x-btn-gray',
  52. handler: function(){
  53. var grid = Ext.getCmp('batchDealGridPanel');
  54. grid.BaseUtil.exportexcel(grid);
  55. }
  56. },'-',{
  57. text: $I18N.common.button.erpCloseButton,
  58. iconCls: 'x-button-icon-close',
  59. cls: 'x-btn-gray',
  60. handler: function(){
  61. var main = parent.Ext.getCmp("content-panel");
  62. if(main){
  63. main.getActiveTab().close();
  64. }
  65. parent.Ext.getCmp('dbwin').close();
  66. }
  67. }],
  68. initComponent : function(){
  69. this.getItemsAndButtons();
  70. this.callParent(arguments);
  71. this.addKeyBoardEvents();//监听Ctrl+Alt+S事件
  72. },
  73. getItemsAndButtons: function(){
  74. var me = this;
  75. me.FormUtil.getActiveTab().setLoading(true);
  76. Ext.Ajax.request({//拿到form的items
  77. url : basePath + 'common/singleFormItems.action',
  78. params: {
  79. caller: caller,
  80. condition: ''
  81. },
  82. method : 'post',
  83. callback : function(options,success,response){
  84. me.FormUtil.getActiveTab().setLoading(false);
  85. var res = new Ext.decode(response.responseText);
  86. if(res.exceptionInfo != null){
  87. showError(res.exceptionInfo);return;
  88. }
  89. me.fo_keyField = res.fo_keyField;
  90. me.tablename = res.tablename;
  91. if(res.keyField){
  92. me.keyField = res.keyField;
  93. }
  94. if(res.dealUrl){
  95. me.dealUrl = res.dealUrl;
  96. }
  97. me.fo_detailMainKeyField = res.fo_detailMainKeyField;
  98. Ext.each(res.items, function(item){
  99. if(screen.width < 1280){//根据屏幕宽度,调整列显示宽度
  100. if(item.columnWidth > 0 && item.columnWidth <= 0.25){
  101. item.columnWidth = 1/3;
  102. } else if(item.columnWidth > 0.25 && item.columnWidth <= 0.5){
  103. item.columnWidth = 2/3;
  104. } else if(item.columnWidth >= 1){
  105. item.columnWidth = 1;
  106. }
  107. } else {
  108. if(item.columnWidth > 0.25 && item.columnWidth < 0.5){
  109. item.columnWidth = 1/3;
  110. }
  111. }
  112. });
  113. me.add(res.items);
  114. //解析buttons字符串,并拼成json格式
  115. var buttonString = res.buttons;
  116. if(buttonString != null && buttonString != ''){
  117. if(contains(buttonString, '#', true)){
  118. Ext.each(buttonString.split('#'), function(b, index){
  119. if(!Ext.getCmp(b)){
  120. var btn = Ext.getCmp('erpVastDealButton');
  121. if(btn){
  122. btn.ownerCt.insert(2, {
  123. xtype: b
  124. });
  125. Ext.getCmp(b).show();
  126. }
  127. } else {
  128. Ext.getCmp(b).show();
  129. }
  130. });
  131. } else {
  132. if(Ext.getCmp(buttonString)){
  133. Ext.getCmp(buttonString).show();
  134. } else {
  135. var btn = Ext.getCmp('erpVastDealButton');//Ext.getCmp(buttonString);
  136. if(btn){
  137. btn.setText($I18N.common.button[buttonString]);
  138. btn.show();
  139. }
  140. }
  141. }
  142. }
  143. }
  144. });
  145. },
  146. onQuery: function(){
  147. var grid = Ext.getCmp('batchDealGridPanel');
  148. grid.multiselected = new Array();
  149. var form = this;
  150. var condition = grid.defaultCondition || '';
  151. Ext.each(form.items.items, function(f){
  152. if(f.logic != null && f.logic != ''){
  153. if(f.xtype == 'checkbox' && f.value == true){
  154. if(condition == ''){
  155. condition += f.logic;
  156. } else {
  157. condition += ' AND ' + f.logic;
  158. }
  159. } else if(f.xtype == 'datefield' && f.value != null){
  160. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  161. if(condition == ''){
  162. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  163. } else {
  164. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  165. }
  166. } else if(f.xtype == 'datetimefield' && f.value != null){
  167. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  168. if(condition == ''){
  169. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  170. } else {
  171. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  172. }
  173. } else if(f.xtype == 'numberfield' && f.value != null && f.value != ''){
  174. if(condition == ''){
  175. condition += f.logic + '=' + f.value;
  176. } else {
  177. condition += ' AND ' + f.logic + '=' + f.value;
  178. }
  179. } else if(f.xtype == 'checkgroup' &&f.value !=null){
  180. if(contains(f.value, ',', true)){
  181. }else{
  182. condition += ' AND (' + f.logic + "='" + f.value + "')";
  183. }
  184. }else {
  185. //一般情况下,在执行批量处理时,是不需要把form的数据传回去,
  186. //但某些情况下,需要将form的某些字段的值也传回去
  187. //例如 请购批量转采购,如果指定了采购单号,就要把采购单号传回去
  188. if(contains(f.logic, 'to:', true)){
  189. if(!grid.toField){
  190. grid.toField = new Array();
  191. }
  192. grid.toField.push(f.logic.split(':')[1]);
  193. } else {
  194. if(f.value != null && f.value != ''){
  195. if(contains(f.value, 'BETWEEN', true) && contains(f.value, 'AND', true)){
  196. if(condition == ''){
  197. condition += f.logic + " " + f.value;
  198. } else {
  199. condition += ' AND (' + f.logic + " " + f.value + ")";
  200. }
  201. } else if(contains(f.value, '||', 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(condition == ''){
  219. condition += f.logic + "='" + f.value + "'";
  220. } else {
  221. condition += ' AND (' + f.logic + "='" + f.value + "')";
  222. }
  223. }
  224. }
  225. }
  226. }
  227. }
  228. });
  229. var gridParam = {caller: caller, condition: condition};
  230. // grid.GridUtil.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', gridParam, "");
  231. if(grid.getGridColumnsAndStore){
  232. grid.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', gridParam, "");
  233. } else {
  234. grid.GridUtil.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', gridParam, "");
  235. }
  236. },
  237. /**
  238. * 监听一些事件
  239. * <br>
  240. * Ctrl+Alt+S 单据配置维护
  241. * Ctrl+Alt+P 参数、逻辑配置维护
  242. */
  243. addKeyBoardEvents: function(){
  244. var me = this;
  245. Ext.EventManager.addListener(document.body, 'keydown', function(e){
  246. if(e.altKey && e.ctrlKey) {
  247. if(e.keyCode == Ext.EventObject.S) {
  248. var url = "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id + "&gridCondition=fd_foidIS" + me.fo_id,
  249. forms = Ext.ComponentQuery.query('form'),
  250. grids = Ext.ComponentQuery.query('gridpanel'),
  251. formSet = [], gridSet = [];
  252. if(forms.length > 0) {
  253. Ext.Array.each(forms, function(f){
  254. f.fo_id && (formSet.push(f.fo_id));
  255. });
  256. }
  257. if(grids.length > 0) {
  258. Ext.Array.each(grids, function(g){
  259. if(g.xtype.indexOf('erpBatchDealGridPanel') > -1)
  260. gridSet.push(window.caller);
  261. else if(g.caller)
  262. gridSet.push(g.caller);
  263. });
  264. }
  265. if(formSet.length > 0 || gridSet.length > 0) {
  266. url = "jsps/ma/multiform.jsp?formParam=" + formSet.join(',') + '&gridParam=' + gridSet.join(',');
  267. }
  268. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', url);
  269. } else if(e.keyCode == Ext.EventObject.P) {
  270. me.FormUtil.onAdd('configs-' + caller, '逻辑配置维护(' + caller + ')', "jsps/ma/logic/config.jsp?whoami=" + caller);
  271. }
  272. }
  273. });
  274. }
  275. });