Form.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. Ext.define('erp.view.common.batchUpdate.Form',{
  2. extend: 'Ext.form.Panel',
  3. alias: 'widget.erpBatchUpdateFormPanel',
  4. requires: ['erp.view.core.button.UseableReplace','erp.view.core.button.Consistency', 'erp.view.core.button.VastPost'],
  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. GridUtil: Ext.create('erp.util.GridUtil'),
  21. BaseUtil: Ext.create('erp.util.BaseUtil'),
  22. items:[{
  23. columnWidth:1,
  24. html:'<div style="color:blue;">只支持.xls格式 EXCEL的导入 ,日期格式必须采用标准日期格式(例如:2013-9-5) 限制行数不能超过5000行</div></br>'
  25. },{
  26. xtype: 'filefield',
  27. name: 'file',
  28. fieldLable:'选择文件',
  29. width: 400,
  30. columnWidth:'0.6',
  31. labelWidth: 50,
  32. emptyText: '选择文件...',
  33. buttonConfig: {
  34. iconCls: 'x-button-icon-excel',
  35. text: $I18N.common.button.erpImportExcelButton,
  36. id:'filebutton',
  37. },
  38. listeners: {
  39. change: function(field){
  40. field.ownerCt.upexcel(field);
  41. }
  42. }
  43. },{
  44. xtype:'button',
  45. name:'download',
  46. text:'下载模板',
  47. margin:'2 3 0 10',
  48. iconCls: 'x-button-icon-download',
  49. handler:function(btn){
  50. var title = parent.Ext.getCmp("content-panel").getActiveTab().tabConfig.tooltip +"模板 ";
  51. var grid=Ext.getCmp('grid');
  52. btn.ownerCt.BaseUtil.exportGrid(grid,title);
  53. /* var columns = grid.columns,cm = new Array(),datas = new Array();
  54. Ext.Array.each(columns, function(c){
  55. if(!c.hidden && c.width > 0 && !c.isCheckerHd) {
  56. if(c.items && c.items.length > 0) {
  57. var items = c.items.items;
  58. Ext.Array.each(items, function(item){
  59. if(!item.hidden)
  60. cm.push({text: (Ext.isEmpty(c.text) ? ' ' : c.text.replace(/<br>/g, '\n')) + '(' + item.text.replace(/<br>/g, '\n') + ')',
  61. dataIndex: item.dataIndex, width: item.width});
  62. });
  63. } else {
  64. cm.push({text: (Ext.isEmpty(c.text) ? ' ' : c.text.replace(/<br>/g, '\n')), dataIndex: c.dataIndex, width: c.width});
  65. }
  66. }
  67. });
  68. if (!Ext.fly('ext-grid-excel')) {
  69. var frm = document.createElement('form');
  70. frm.id = 'ext-grid-excel';
  71. frm.name = id;
  72. frm.className = 'x-hidden';
  73. document.body.appendChild(frm);
  74. }
  75. Ext.Ajax.request({
  76. url: basePath + 'common/excel/grid.xls',
  77. method: 'post',
  78. form: Ext.fly('ext-grid-excel'),
  79. isUpload: true,
  80. params: {
  81. datas: unescape(Ext.JSON.encode(datas).replace(/\\/g,"%")),
  82. columns: unescape(Ext.encode(cm).replace(/\\/g,"%")),
  83. title: title
  84. }
  85. });*/
  86. }
  87. },{
  88. xtype:'hidden',
  89. name:'caller',
  90. id:'caller',
  91. value:caller
  92. },{
  93. xtype: 'htmleditor',
  94. enableColors: false,
  95. enableAlignments: false,
  96. columnWidth:1,
  97. enableFont: false,
  98. enableFontSize: false,
  99. enableFormat: false,
  100. enableLinks: false,
  101. enableLists: false,
  102. enableSourceEdit: false,
  103. cls :'form-field-allowBlank',
  104. style:'background:#fffac0;color:#515151;',
  105. frame: false,
  106. id:'html',
  107. height:250,
  108. readOnly:true,
  109. listeners: {
  110. afterrender: function(editor){
  111. editor.getToolbar().hide();
  112. }
  113. }}],
  114. initComponent : function(){
  115. this.addEvents({alladded: true});//items加载完
  116. this.callParent(arguments);
  117. this.addKeyBoardEvents();//监听Ctrl+Alt+S事件
  118. },
  119. upexcel: function(field){
  120. this.getForm().submit({
  121. url: basePath + 'common/update/batchUpdate.action',
  122. waitMsg: "正在解析Excel",
  123. success: function(fp, o){
  124. Ext.Msg.alert('提示','更新成功');
  125. field.reset();
  126. Ext.getCmp('html').setValue(o.result.data);
  127. },
  128. failure: function(fp, o){
  129. if(o.result.size){
  130. showError(o.result.error + "&nbsp;" + Ext.util.Format.fileSize(o.result.size));
  131. field.reset();
  132. } else {
  133. showError(o.result.error);
  134. field.reset();
  135. }
  136. }
  137. });
  138. },
  139. onQuery: function(select){
  140. var grid = Ext.getCmp('batchDealGridPanel'),sel = [];
  141. if(!grid){
  142. grid = Ext.getCmp('grid');
  143. }
  144. grid.multiselected = new Array();
  145. if(select == true) {
  146. sel = grid.selModel.getSelection();
  147. }
  148. var form = this;
  149. var cond = form.getCondition();
  150. if(Ext.isEmpty(cond)) {
  151. cond = '1=1';
  152. }
  153. form.beforeQuery(caller, cond);//执行查询前逻辑
  154. var gridParam = {caller: caller, condition: cond + form.getOrderBy(grid), start: 1, end: 1000};
  155. if(grid.getGridColumnsAndStore){
  156. grid.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', gridParam, "");
  157. } else {
  158. //grid.GridUtil.getGridColumnsAndStore(grid, 'common/singleGridPanel.action', gridParam, "");
  159. grid.GridUtil.loadNewStore(grid, gridParam);
  160. }
  161. if(select == true) {
  162. Ext.each(sel, function(){
  163. grid.selModel.select(this.index);
  164. });
  165. }
  166. },
  167. getCondition: function(grid){
  168. grid = grid || Ext.getCmp('batchDealGridPanel');
  169. if(!grid){
  170. grid = Ext.getCmp('grid');
  171. }
  172. var form = this;
  173. var condition = Ext.isEmpty(grid.defaultCondition) ? '' : ('(' + grid.defaultCondition + ')');
  174. Ext.each(form.items.items, function(f){
  175. if(f.logic != null && f.logic != ''){
  176. if((f.xtype == 'checkbox' || f.xtype == 'radio')){
  177. if(f.value == true) {
  178. if(condition == ''){
  179. condition += f.logic;
  180. } else {
  181. condition += ' AND ' + f.logic;
  182. }
  183. }
  184. } else if(f.xtype == 'datefield' && f.value != null){
  185. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  186. if(condition == ''){
  187. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  188. } else {
  189. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  190. }
  191. } else if(f.xtype == 'datetimefield' && f.value != null){
  192. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  193. if(condition == ''){
  194. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  195. } else {
  196. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  197. }
  198. } else if(f.xtype == 'numberfield' && f.value != null && f.value != ''){
  199. if(condition == ''){
  200. condition += f.logic + '=' + f.value;
  201. } else {
  202. condition += ' AND ' + f.logic + '=' + f.value;
  203. }
  204. } else if(f.xtype == 'combo' && f.value == '$ALL'){
  205. if(f.store.data.length > 1) {
  206. if(condition == ''){
  207. condition += '(';
  208. } else {
  209. condition += ' AND (';
  210. }
  211. f.store.each(function(d, idx){
  212. if(d.data.value != '$ALL') {
  213. if(idx == 0){
  214. condition += f.logic + "='" + d.data.value + "'";
  215. } else {
  216. condition += ' OR ' + f.logic + "='" + d.data.value + "'";
  217. }
  218. }
  219. });
  220. condition += ')';
  221. }
  222. } else {
  223. //一般情况下,在执行批量处理时,是不需要把form的数据传回去,
  224. //但某些情况下,需要将form的某些字段的值也传回去
  225. //例如 请购批量转采购,如果指定了采购单号,就要把采购单号传回去
  226. if(contains(f.logic, 'to:', true)){
  227. if(!grid.toField){
  228. grid.toField = new Array();
  229. }
  230. grid.toField.push(f.logic.split(':')[1]);
  231. } else {
  232. if(!Ext.isEmpty(f.value)){
  233. if(contains(f.value.toString(), 'BETWEEN', true) && contains(f.value.toString(), 'AND', true)){
  234. if(condition == ''){
  235. condition += f.logic + " " + f.value;
  236. } else {
  237. condition += ' AND (' + f.logic + " " + f.value + ")";
  238. }
  239. } else if(contains(f.value.toString(), '||', true)){
  240. var str = '';
  241. Ext.each(f.value.split('||'), function(v){
  242. if(v != null && v != ''){
  243. if(str == ''){
  244. str += f.logic + "='" + v + "'";
  245. } else {
  246. str += ' OR ' + f.logic + "='" + v + "'";
  247. }
  248. }
  249. });
  250. if(condition == ''){
  251. condition += "(" + str + ")";
  252. } else {
  253. condition += ' AND (' + str + ")";
  254. }
  255. } else if(f.value.toString().charAt(0) == '!'){
  256. if(condition == ''){
  257. condition += 'nvl(' + f.logic + ",' ')<>'" + f.value.substr(1) + "'";
  258. } else {
  259. condition += ' AND (nvl(' + f.logic + ",' ')<>'" + f.value.substr(1) + "')";
  260. }
  261. } else {
  262. if(condition == ''){
  263. condition += f.logic + "='" + f.value + "'";
  264. } else {
  265. condition += ' AND (' + f.logic + "='" + f.value + "')";
  266. }
  267. }
  268. }
  269. }
  270. }
  271. }
  272. });
  273. /*if(urlcondition !=null || urlcondition !=''){
  274. condition =condition+urlcondition;
  275. }*/
  276. return condition;
  277. },
  278. getOrderBy: function(grid){
  279. var ob = new Array();
  280. if(grid.mainField) {
  281. ob.push(grid.mainField + ' desc');
  282. }
  283. if(grid.detno) {
  284. ob.push(grid.detno + ' asc');
  285. }
  286. if(grid.keyField) {
  287. ob.push(grid.keyField + ' desc');
  288. }
  289. var order = '';
  290. if(ob.length > 0) {
  291. order = ' order by ' + ob.join(',');
  292. }
  293. return order;
  294. },
  295. /**
  296. * 监听一些事件
  297. * <br>
  298. * Ctrl+Alt+S 单据配置维护
  299. * Ctrl+Alt+P 参数、逻辑配置维护
  300. */
  301. addKeyBoardEvents: function(){
  302. var me = this;
  303. Ext.EventManager.addListener(document.body, 'keydown', function(e){
  304. if(e.altKey && e.ctrlKey) {
  305. if(e.keyCode == Ext.EventObject.S) {
  306. var url = "jsps/ma/form.jsp?formCondition=fo_idIS" + me.fo_id + "&gridCondition=fd_foidIS" + me.fo_id,
  307. forms = Ext.ComponentQuery.query('form'),
  308. grids = Ext.ComponentQuery.query('gridpanel'),
  309. formSet = [], gridSet = [];
  310. if(forms.length > 0) {
  311. Ext.Array.each(forms, function(f){
  312. f.fo_id && (formSet.push(f.fo_id));
  313. });
  314. }
  315. if(grids.length > 0) {
  316. Ext.Array.each(grids, function(g){
  317. if(g.xtype.indexOf('erpGridPanel') > -1)
  318. gridSet.push(window.caller);
  319. else if(g.caller)
  320. gridSet.push(g.caller);
  321. });
  322. }
  323. if(formSet.length > 0 || gridSet.length > 0) {
  324. url = "jsps/ma/multiform.jsp?formParam=" + formSet.join(',') + '&gridParam=' + gridSet.join(',');
  325. }
  326. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', url);
  327. } else if(e.keyCode == Ext.EventObject.P) {
  328. me.FormUtil.onAdd('configs-' + caller, '逻辑配置维护(' + caller + ')', "jsps/ma/logic/config.jsp?whoami=" + caller);
  329. }
  330. }
  331. });
  332. },
  333. beforeQuery: function(call, cond) {
  334. Ext.Ajax.request({
  335. url: basePath + 'common/form/beforeQuery.action',
  336. params: {
  337. caller: call,
  338. condition: cond
  339. },
  340. async: false,
  341. callback: function(opt, s, r) {
  342. var rs = Ext.decode(r.responseText);
  343. if(rs.exceptionInfo) {
  344. showError(rs.exceptionInfo);
  345. }
  346. }
  347. });
  348. }
  349. });