Form.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. grid.multiselected = new Array();
  164. var form = this;
  165. var ab_date_str = Ext.getCmp('ab_date')?(Ext.getCmp('ab_date').rawValue!=''?Ext.getCmp('ab_date').rawValue:null):null;
  166. var condition = (grid.defaultCondition && grid.defaultCondition!=''&&grid.defaultCondition!=null)?' 1=1 and '+grid.defaultCondition:' 1=1 ';
  167. // var condition = grid.defaultCondition||'';
  168. Ext.each(form.items.items, function(f){
  169. if(f.logic != null && f.logic != ''){
  170. //一般情况下,在执行批量处理时,是不需要把form的数据传回去,
  171. //但某些情况下,需要将form的某些字段的值也传回去
  172. //例如 请购批量转采购,如果指定了采购单号,就要把采购单号传回去
  173. if(contains(f.logic, 'to:', true)){
  174. if(!grid.toField){
  175. grid.toField = new Array();
  176. }
  177. grid.toField.push(f.logic.split(':')[1]);
  178. } else {
  179. if(f.xtype == 'checkbox' && f.value == true){
  180. if(condition == ''){
  181. condition += f.logic;
  182. } else {
  183. condition += ' AND ' + f.logic;
  184. }
  185. } else if(f.xtype == 'datefield' && f.value != null&&!contains(f.logic, 'to:', true)){
  186. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  187. if(condition == ''){
  188. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  189. } else {
  190. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  191. }
  192. } else if(f.xtype == 'datetimefield' && f.value != null){
  193. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  194. if(condition == ''){
  195. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  196. } else {
  197. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  198. }
  199. } else if(f.xtype == 'numberfield' && f.value != null && f.value != ''){
  200. if(condition == ''){
  201. condition += f.logic + '=' + f.value;
  202. } else {
  203. condition += ' AND ' + f.logic + '=' + f.value;
  204. }
  205. } else if(f.xtype=='adddbfindtrigger' && f.value != null && f.value != ''){
  206. if(condition == ''){
  207. condition += f.logic + ' in (' ;
  208. } else {
  209. condition += ' AND ' + f.logic + ' in (';
  210. }
  211. var str=f.value,constr="";
  212. for(var i=0;i<str.split("#").length;i++){
  213. if(i<str.split("#").length-1){
  214. constr+="'"+str.split("#")[i]+"',";
  215. }else constr+="'"+str.split("#")[i]+"'";
  216. }
  217. condition +=constr+")";
  218. } else if(f.xtype == 'combo' && f.value == '$ALL'){
  219. if(f.store.data.length > 1) {
  220. if(condition == ''){
  221. condition += '(';
  222. } else {
  223. condition += ' AND (';
  224. }
  225. var _a = '';
  226. f.store.each(function(d, idx){
  227. if(d.data.value != '$ALL') {
  228. if(_a == ''){
  229. _a += f.logic + "='" + d.data.value + "'";
  230. } else {
  231. _a += ' OR ' + f.logic + "='" + d.data.value + "'";
  232. }
  233. }
  234. });
  235. condition += _a + ')';
  236. }
  237. } else {
  238. if(!Ext.isEmpty(f.value)){
  239. if(contains(f.value.toString(), 'BETWEEN', true) && contains(f.value.toString(), 'AND', true)){
  240. if(condition == ''){
  241. condition += f.logic + " " + f.value;
  242. } else {
  243. condition += ' AND (' + f.logic + " " + f.value + ")";
  244. }
  245. } else if(contains(f.value.toString(), '||', true)){
  246. var str = '';
  247. Ext.each(f.value.split('||'), function(v){
  248. if(v != null && v != ''){
  249. if(str == ''){
  250. str += f.logic + "='" + v + "'";
  251. } else {
  252. str += ' OR ' + f.logic + "='" + v + "'";
  253. }
  254. }
  255. });
  256. if(condition == ''){
  257. condition += "(" + str + ")";
  258. } else {
  259. condition += ' AND (' + str + ")";
  260. }
  261. } else if(f.value.toString().charAt(0) == '!'){
  262. if(condition == ''){
  263. condition += 'nvl(' + f.logic + ",' ')<>'" + f.value.substr(1) + "'";
  264. } else {
  265. condition += ' AND (nvl(' + f.logic + ",' ')<>'" + f.value.substr(1) + "')";
  266. }
  267. } else {
  268. if(f.value.indexOf('%') >= 0) {
  269. if(condition == ''){
  270. condition += f.logic + " like '" + f.value + "'";
  271. } else {
  272. condition += ' AND (' + f.logic + " like '" + f.value + "')";
  273. }
  274. } else {
  275. if(condition == ''){
  276. condition += f.logic + "='" + f.value + "'";
  277. } else {
  278. condition += ' AND (' + f.logic + "='" + f.value + "')";
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. }
  286. });//ab_date_str
  287. Ext.Ajax.request({
  288. url : basePath + 'common/getFieldData.action',
  289. async: false,
  290. params: {
  291. caller: "USER_OBJECTS",
  292. field: "COUNT(*)",
  293. condition: "OBJECT_TYPE='PACKAGE' AND OBJECT_NAME='FA_BATCH_VIEW_PARAM'"
  294. },
  295. method : 'post',
  296. callback : function(options,success,response){
  297. var localJson = new Ext.decode(response.responseText);
  298. if(localJson.exceptionInfo){
  299. showError(localJson.exceptionInfo);return;
  300. }
  301. if(localJson.success){
  302. if(localJson.data != null){
  303. if(localJson.data=='1'||localJson.data==1){
  304. if(ab_date_str != null){
  305. if (condition == ''){
  306. condition += " fa_batch_view_param.set_param('"+ab_date_str+"')='"+ab_date_str+"'";
  307. } else {
  308. condition += " AND fa_batch_view_param.set_param('"+ab_date_str+"')='"+ab_date_str+"'";
  309. }
  310. }else{
  311. if (condition == ''){
  312. condition += " fa_batch_view_param.set_param(null) is null";
  313. } else {
  314. condition += " AND fa_batch_view_param.set_param(null) is null";
  315. }
  316. }
  317. }
  318. }
  319. }
  320. var orderStr = form.getOrderBy(grid);
  321. if(form.fo_detailGridOrderBy){
  322. orderStr = (form.fo_detailGridOrderBy!=null && form.fo_detailGridOrderBy!='')?form.fo_detailGridOrderBy:orderStr;
  323. }
  324. var gridParam = {caller: caller, condition: condition +' '+ orderStr};
  325. if(!grid.bigVolume) {
  326. gridParam.start = 1;
  327. gridParam.end = 1000;
  328. }
  329. grid.store.each(function(){
  330. this.modified = null;
  331. });
  332. grid.GridUtil.loadNewStore(grid, gridParam);
  333. if(Ext.getCmp('pi_counttotal'))
  334. Ext.getCmp('pi_counttotal').setValue('0');
  335. if(Ext.getCmp('pi_amounttotal'))
  336. Ext.getCmp('pi_amounttotal').setValue('0');
  337. }
  338. });
  339. },
  340. addKeyBoardEvents: function(){
  341. var me = this;
  342. if(Ext.isIE){
  343. document.body.attachEvent('onkeydown', function(){//ie的事件名称不同,也不支持addEventListener
  344. if(window.event.altKey && window.event.ctrlKey && window.event.keyCode == 83){
  345. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  346. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  347. }
  348. });
  349. } else {
  350. document.body.addEventListener("keydown", function(e){
  351. if(Ext.isFF5){//firefox不支持window.event
  352. e = e || window.event;
  353. }
  354. if(e.altKey && e.ctrlKey && e.keyCode == 83){
  355. me.FormUtil.onAdd('form' + caller, 'Form配置维护(' + caller + ')', "jsps/ma/multiform.jsp?formCondition=fo_idIS" + me.fo_id +
  356. "&gridCondition=fd_foidIS" + me.fo_id + "&whoami=" + caller);
  357. }
  358. });
  359. }
  360. },
  361. getOrderBy: function(grid){
  362. var ob = new Array();
  363. if(grid.mainField) {
  364. ob.push(grid.mainField + ' desc');
  365. }
  366. if(grid.detno) {
  367. ob.push(grid.detno + ' asc');
  368. }
  369. if(grid.keyField) {
  370. ob.push(grid.keyField + ' desc');
  371. }
  372. var order = '';
  373. if(ob.length > 0) {
  374. order = ' order by ' + ob.join(',');
  375. }
  376. return order;
  377. }
  378. });