Form.js 12 KB

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