Form.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. Ext.define('erp.view.fa.ars.ProdToARBill.Form',{
  2. extend: 'Ext.form.Panel',
  3. alias: 'widget.erpProdToARBillFormPanel',
  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: 'erpVastPrintButton',
  45. id: 'erpVastPrintButton',
  46. hidden: true
  47. },{
  48. xtype: 'erpByAmountButton',
  49. id: 'erpByAmountButton',
  50. hidden: true
  51. },{
  52. xtype: 'erpVastDealButton',
  53. id: 'erpVastDealButton',
  54. hidden: true
  55. },{
  56. xtype: 'erpVastTurnARAPCheckButton',
  57. id: 'erpVastTurnARAPCheckButton',
  58. hidden: true
  59. },'-',{
  60. name: 'export',
  61. text: $I18N.common.button.erpExportButton,
  62. iconCls: 'x-button-icon-excel',
  63. cls: 'x-btn-gray',
  64. handler: function(){
  65. var grid = Ext.getCmp('batchDealGridPanel');
  66. grid.BaseUtil.exportGrid(grid);
  67. }
  68. },'-',{
  69. text: $I18N.common.button.erpCloseButton,
  70. iconCls: 'x-button-icon-close',
  71. cls: 'x-btn-gray',
  72. handler: function(){
  73. var main = parent.Ext.getCmp("content-panel");
  74. main.getActiveTab().close();
  75. }
  76. }],
  77. initComponent : function(){
  78. this.getItemsAndButtons();
  79. this.callParent(arguments);
  80. this.addKeyBoardEvents();//监听Ctrl+Alt+S事件
  81. },
  82. getItemsAndButtons: function(){
  83. var me = this;
  84. me.FormUtil.getActiveTab().setLoading(true);
  85. Ext.Ajax.request({//拿到form的items
  86. url : basePath + 'common/singleFormItems.action',
  87. params: {
  88. caller: caller,
  89. condition: ''
  90. },
  91. method : 'post',
  92. callback : function(options,success,response){
  93. me.FormUtil.getActiveTab().setLoading(false);
  94. var res = new Ext.decode(response.responseText);
  95. if(res.exceptionInfo != null){
  96. showError(res.exceptionInfo);return;
  97. }
  98. me.fo_keyField = res.fo_keyField;
  99. me.tablename = res.tablename;
  100. me.fo_id=res.fo_id;
  101. if(res.keyField){
  102. me.keyField = res.keyField;
  103. }
  104. if(res.dealUrl){
  105. me.dealUrl = res.dealUrl;
  106. }
  107. me.fo_detailMainKeyField = res.fo_detailMainKeyField;
  108. me.fo_detailGridOrderBy = res.fo_detailGridOrderBy;
  109. Ext.each(res.items, function(item){
  110. if(screen.width < 1280){//根据屏幕宽度,调整列显示宽度
  111. if(item.columnWidth > 0 && item.columnWidth <= 0.25){
  112. item.columnWidth = 1/3;
  113. } else if(item.columnWidth > 0.25 && item.columnWidth <= 0.5){
  114. item.columnWidth = 2/3;
  115. } else if(item.columnWidth >= 1){
  116. item.columnWidth = 1;
  117. }
  118. } else {
  119. if(item.columnWidth > 0.25 && item.columnWidth < 0.5){
  120. item.columnWidth = 2/3;
  121. }
  122. }
  123. if(item.xtype == 'hidden') {
  124. item.columnWidth = 0;
  125. }
  126. });
  127. me.add(res.items);
  128. me.fireEvent('alladded', me);
  129. //解析buttons字符串,并拼成json格式
  130. var buttonString = res.buttons;
  131. if(buttonString != null && buttonString != ''){
  132. if(contains(buttonString, '#', true)){
  133. Ext.each(buttonString.split('#'), function(b, index){
  134. if(!Ext.getCmp(b)){
  135. var btn = Ext.getCmp('erpVastDealButton');
  136. if(btn){
  137. btn.ownerCt.insert(2, {
  138. xtype: b
  139. });
  140. Ext.getCmp(b).show();
  141. }
  142. } else {
  143. Ext.getCmp(b).show();
  144. }
  145. });
  146. } else {
  147. if(Ext.getCmp(buttonString)){
  148. Ext.getCmp(buttonString).show();
  149. } else {
  150. var btn = Ext.getCmp('erpVastDealButton');//Ext.getCmp(buttonString);
  151. if(btn){
  152. btn.setText($I18N.common.button[buttonString]);
  153. btn.show();
  154. }
  155. }
  156. }
  157. }
  158. }
  159. });
  160. },
  161. onQuery: function(){
  162. var grid = Ext.getCmp('batchDealGridPanel');
  163. var check=grid.headerCt.items.items[0];
  164. if(check && check.isCheckerHd){
  165. check.el.removeCls(Ext.baseCSSPrefix + 'grid-hd-checker-on');
  166. }
  167. grid.multiselected = new Array();
  168. var form = this;
  169. var ab_date_str = Ext.getCmp('ab_date')?(Ext.getCmp('ab_date').rawValue!=''?Ext.getCmp('ab_date').rawValue:null):null;
  170. var condition = (grid.defaultCondition && grid.defaultCondition!=''&&grid.defaultCondition!=null)?' 1=1 and '+grid.defaultCondition:' 1=1 ';
  171. Ext.each(form.items.items, function(f){
  172. if(f.logic != null && f.logic != ''){
  173. //一般情况下,在执行批量处理时,是不需要把form的数据传回去,
  174. //但某些情况下,需要将form的某些字段的值也传回去
  175. //例如 请购批量转采购,如果指定了采购单号,就要把采购单号传回去
  176. if(contains(f.logic, 'to:', true)){
  177. if(!grid.toField){
  178. grid.toField = new Array();
  179. }
  180. grid.toField.push(f.logic.split(':')[1]);
  181. } else {
  182. if(f.xtype == 'checkbox' || f.xtype == 'radio'){
  183. if(condition == ''){
  184. condition += f.logic;
  185. } else {
  186. condition += ' AND ' + f.logic;
  187. }
  188. } else if(f.xtype == 'datefield' && f.value != null&&!contains(f.logic, 'to:', true)){
  189. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  190. if(condition == ''){
  191. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  192. } else {
  193. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  194. }
  195. } else if(f.xtype == 'datetimefield' && f.value != null){
  196. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  197. if(condition == ''){
  198. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  199. } else {
  200. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  201. }
  202. } else if(f.xtype == 'numberfield' && f.value != null && f.value != ''){
  203. if(condition == ''){
  204. condition += f.logic + '=' + f.value;
  205. } else {
  206. condition += ' AND ' + f.logic + '=' + f.value;
  207. }
  208. } else if(f.xtype=='adddbfindtrigger' && f.value != null && f.value != ''){
  209. if(condition == ''){
  210. condition += f.logic + ' in (' ;
  211. } else {
  212. condition += ' AND ' + f.logic + ' in (';
  213. }
  214. var str=f.value,constr="";
  215. for(var i=0;i<str.split("#").length;i++){
  216. if(i<str.split("#").length-1){
  217. constr+="'"+str.split("#")[i]+"',";
  218. }else constr+="'"+str.split("#")[i]+"'";
  219. }
  220. condition +=constr+")";
  221. } else if(f.xtype == 'combo' && f.value == '$ALL'){
  222. if(f.store.data.length > 1) {
  223. if(condition == ''){
  224. condition += '(';
  225. } else {
  226. condition += ' AND (';
  227. }
  228. var _a = '';
  229. f.store.each(function(d, idx){
  230. if(d.data.value != '$ALL') {
  231. if(_a == ''){
  232. _a += f.logic + "='" + d.data.value + "'";
  233. } else {
  234. _a += ' OR ' + f.logic + "='" + d.data.value + "'";
  235. }
  236. }
  237. });
  238. condition += _a + ')';
  239. }
  240. } else {
  241. if(!Ext.isEmpty(f.value)){
  242. if(contains(f.value.toString(), 'BETWEEN', true) && contains(f.value.toString(), 'AND', true)){
  243. if(condition == ''){
  244. condition += f.logic + " " + f.value;
  245. } else {
  246. condition += ' AND (' + f.logic + " " + f.value + ")";
  247. }
  248. } else if(contains(f.value.toString(), '||', true)){
  249. var str = '';
  250. Ext.each(f.value.split('||'), function(v){
  251. if(v != null && v != ''){
  252. if(str == ''){
  253. str += f.logic + "='" + v + "'";
  254. } else {
  255. str += ' OR ' + f.logic + "='" + v + "'";
  256. }
  257. }
  258. });
  259. if(condition == ''){
  260. condition += "(" + str + ")";
  261. } else {
  262. condition += ' AND (' + str + ")";
  263. }
  264. } else if(f.value.toString().charAt(0) == '!'){
  265. if(condition == ''){
  266. condition += 'nvl(' + f.logic + ",' ')<>'" + f.value.substr(1) + "'";
  267. } else {
  268. condition += ' AND (nvl(' + f.logic + ",' ')<>'" + f.value.substr(1) + "')";
  269. }
  270. } else {
  271. if(f.value.indexOf('%') >= 0) {
  272. if(condition == ''){
  273. condition += f.logic + " like '" + f.value + "'";
  274. } else {
  275. condition += ' AND (' + f.logic + " like '" + f.value + "')";
  276. }
  277. } else {
  278. if(condition == ''){
  279. condition += f.logic + "='" + f.value + "'";
  280. } else {
  281. condition += ' AND (' + f.logic + "='" + f.value + "')";
  282. }
  283. }
  284. }
  285. }
  286. }
  287. }
  288. }
  289. });//ab_date_str
  290. Ext.Ajax.request({
  291. url : basePath + 'common/getFieldData.action',
  292. async: false,
  293. params: {
  294. caller: "USER_OBJECTS",
  295. field: "COUNT(*)",
  296. condition: "OBJECT_TYPE='PACKAGE' AND OBJECT_NAME='FA_BATCH_VIEW_PARAM'"
  297. },
  298. method : 'post',
  299. callback : function(options,success,response){
  300. var localJson = new Ext.decode(response.responseText);
  301. if(localJson.exceptionInfo){
  302. showError(localJson.exceptionInfo);return;
  303. }
  304. if(localJson.success){
  305. if(localJson.data != null){
  306. if(localJson.data=='1'||localJson.data==1){
  307. if(ab_date_str != null){
  308. if (condition == ''){
  309. condition += " fa_batch_view_param.set_param('"+ab_date_str+"')='"+ab_date_str+"'";
  310. } else {
  311. condition += " AND fa_batch_view_param.set_param('"+ab_date_str+"')='"+ab_date_str+"'";
  312. }
  313. }else{
  314. if (condition == ''){
  315. condition += " fa_batch_view_param.set_param(null) is null";
  316. } else {
  317. condition += " AND fa_batch_view_param.set_param(null) is null";
  318. }
  319. }
  320. }
  321. }
  322. }
  323. var orderStr = form.getOrderBy(grid);
  324. if(form.fo_detailGridOrderBy){
  325. orderStr = (form.fo_detailGridOrderBy!=null && form.fo_detailGridOrderBy!='')?form.fo_detailGridOrderBy:orderStr;
  326. }
  327. var gridParam = {caller: caller, condition: condition +' '+ orderStr};
  328. if(!grid.bigVolume) {
  329. gridParam.start = 1;
  330. gridParam.end = 1000;
  331. }
  332. grid.store.each(function(){
  333. this.modified = null;
  334. });
  335. grid.GridUtil.loadNewStore(grid, gridParam);
  336. if(Ext.getCmp('pi_counttotal'))
  337. Ext.getCmp('pi_counttotal').setValue('0');
  338. if(Ext.getCmp('pi_amounttotal'))
  339. Ext.getCmp('pi_amounttotal').setValue('0');
  340. }
  341. });
  342. },
  343. addKeyBoardEvents: function(){
  344. var me = this;
  345. if(Ext.isIE){
  346. document.body.attachEvent('onkeydown', function(){//ie的事件名称不同,也不支持addEventListener
  347. if(window.event.altKey && window.event.ctrlKey && window.event.keyCode == 83){
  348. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  349. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  350. }
  351. });
  352. } else {
  353. document.body.addEventListener("keydown", function(e){
  354. if(Ext.isFF5){//firefox不支持window.event
  355. e = e || window.event;
  356. }
  357. if(e.altKey && e.ctrlKey && e.keyCode == 83){
  358. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  359. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  360. }
  361. });
  362. }
  363. },
  364. getOrderBy: function(grid){
  365. var ob = new Array();
  366. if(grid.mainField) {
  367. ob.push(grid.mainField + ' desc');
  368. }
  369. if(grid.detno) {
  370. ob.push(grid.detno + ' asc');
  371. }
  372. if(grid.keyField) {
  373. ob.push(grid.keyField + ' desc');
  374. }
  375. var order = '';
  376. if(ob.length > 0) {
  377. order = ' order by ' + ob.join(',');
  378. }
  379. return order;
  380. }
  381. });