Showapply.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.oa.meeting.Showapply', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.FormUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil', 'erp.util.RenderUtil'],
  5. views:[
  6. 'common.batchDeal.Viewport','common.batchDeal.Form','oa.meeting.Showapply',
  7. 'core.trigger.DbfindTrigger','core.form.FtField','core.form.FtFindField','core.form.ConDateField',
  8. 'core.trigger.TextAreaTrigger','core.form.YnField', 'core.form.MonthDateField','core.button.Import','core.button.ImportAll'
  9. ],
  10. init:function(){
  11. var me = this;
  12. me.resized = false;
  13. this.control({
  14. 'erpBatchDealFormPanel': {
  15. alladded: function(form){
  16. var grid = Ext.getCmp('batchDealGridPanel');
  17. me.resize(form, grid);
  18. }
  19. },
  20. 'erpBatchDealGridPanel': {
  21. afterrender: function(grid){
  22. var form = Ext.getCmp('dealform');
  23. me.resize(form, grid);
  24. }
  25. },
  26. 'triggerfield[id=ma_date]':{
  27. afterrender:function(){
  28. var date=Ext.getCmp('ma_date').getValue();
  29. var weekday = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  30. Ext.getCmp('ma_weekday').setValue(weekday[date.getDay()]);
  31. },
  32. change:function(){
  33. var date=Ext.getCmp('ma_date').getValue();
  34. var weekday = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  35. Ext.getCmp('ma_weekday').setValue(weekday[date.getDay()]);
  36. }
  37. },
  38. /*'erpVastDealButton':{},*/
  39. 'button[id=query]':{
  40. beforerender:function(btn){
  41. btn.handler=function(select){
  42. var grid = Ext.getCmp('batchDealGridPanel'),sel = [];
  43. if(!grid){
  44. grid = Ext.getCmp('grid');
  45. }
  46. grid.multiselected = new Array();
  47. if(select == true) {
  48. sel = grid.selModel.getSelection();
  49. }
  50. var form = Ext.getCmp('dealform');
  51. var cond = me.getCondition(grid);
  52. if(Ext.isEmpty(cond)) {
  53. cond = '1=1';
  54. }
  55. form.beforeQuery(caller, cond);//执行查询前逻辑
  56. var gridParam = {caller: caller, condition: cond + form.getOrderBy(grid)};
  57. if(grid.getGridColumnsAndStore){
  58. grid.loadNewStore(grid, 'oa/meeting/singleGridPanel.action', gridParam, "");
  59. }
  60. if(select == true) {
  61. Ext.each(sel, function(){
  62. grid.selModel.select(this.index);
  63. });
  64. }
  65. };
  66. }
  67. },
  68. 'erpImportButton':{
  69. click:function(btn){
  70. me.vastDeal(btn.ownerCt.ownerCt.dealUrl);
  71. }
  72. },
  73. 'erpImportAllButton':{
  74. click:function(btn){
  75. me.vastDeal(btn.ownerCt.ownerCt.dealUrl,'all');
  76. }
  77. }
  78. });
  79. },
  80. resize: function(form, grid){
  81. if(!this.resized && form && grid && form.items.items.length > 0){
  82. var height = window.innerHeight;
  83. if(Ext.isIE){
  84. height = screen.height*0.75;
  85. }
  86. var cw = 0;
  87. Ext.each(form.items.items, function(){
  88. if(!this.hidden && this.xtype != 'hidden') {
  89. cw += this.columnWidth;
  90. }
  91. });
  92. cw = Math.ceil(cw);
  93. if(cw == 0){
  94. cw = 5;
  95. } else if(cw > 2 && cw <= 5){
  96. cw -= 1;
  97. } else if(cw > 5 && cw < 8){
  98. cw = 4;
  99. }
  100. cw = Math.min(cw, 5);
  101. form.setHeight(height*cw/10 + 10);
  102. grid.setHeight(height*(10 - cw)/10 - 10);
  103. this.resized = true;
  104. }
  105. },
  106. countGrid: function(){
  107. //重新计算合计栏值
  108. var grid = Ext.getCmp('batchDealGridPanel');
  109. Ext.each(grid.columns, function(column){
  110. if(column.summary){
  111. var sum = 0;
  112. Ext.each(grid.store.data.items, function(item){
  113. if(item.value != null && item.value != ''){
  114. sum += Number(item.value);
  115. }
  116. });
  117. Ext.getCmp(column.dataIndex + '_sum').setText(column.text + '(sum):' + sum);
  118. } else if(column.average) {
  119. var average = 0;
  120. Ext.each(grid.store.data.items, function(item){
  121. if(item.value != null && item.value != ''){
  122. average += Number(item.value);
  123. }
  124. });
  125. average = average/grid.store.data.items.length;
  126. Ext.getCmp(column.dataIndex + '_average').setText(column.text + '(average):' + average);
  127. } else if(column.count) {
  128. var count = 0;
  129. Ext.each(grid.store.data.items, function(item){
  130. if(item.value != null && item.value != ''){
  131. count++;
  132. }
  133. });
  134. Ext.getCmp(column.dataIndex + '_count').setText(column.text + '(count):' + count);
  135. }
  136. });
  137. },
  138. getCondition:function(grid){
  139. grid = grid || Ext.getCmp('batchDealGridPanel');
  140. if(!grid){
  141. grid = Ext.getCmp('grid');
  142. }
  143. var form = Ext.getCmp('dealform');
  144. var condition = Ext.isEmpty(grid.defaultCondition) ? '' : ('(' + grid.defaultCondition + ')');
  145. Ext.each(form.items.items, function(f){
  146. if(f.name=='ml_kind'){
  147. if(f.value!=null&&f.value!=''){
  148. if(condition == ''){
  149. condition += f.value;
  150. } else {
  151. condition += ' AND ' + f.value;
  152. }
  153. }
  154. }else {
  155. if(f.logic != null && f.logic != ''){
  156. if(f.xtype == 'checkbox' && f.value == true){
  157. if(condition == ''){
  158. condition += f.logic;
  159. } else {
  160. condition += ' AND ' + f.logic;
  161. }
  162. } else if(f.xtype == 'datefield' && f.value != null){
  163. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  164. if(condition == ''){
  165. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  166. } else {
  167. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  168. }
  169. } else if(f.xtype == 'datetimefield' && f.value != null){
  170. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  171. if(condition == ''){
  172. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  173. } else {
  174. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  175. }
  176. } else if(f.xtype == 'numberfield' && f.value != null && f.value != ''){
  177. if(condition == ''){
  178. condition += f.logic + '=' + f.value;
  179. } else {
  180. condition += ' AND ' + f.logic + '=' + f.value;
  181. }
  182. } else if(f.xtype == 'combo' && f.value == '$ALL'){
  183. if(f.store.data.length > 1) {
  184. if(condition == ''){
  185. condition += '(';
  186. } else {
  187. condition += ' AND (';
  188. }
  189. f.store.each(function(d, idx){
  190. if(d.data.value != '$ALL') {
  191. if(idx == 0){
  192. condition += f.logic + "='" + d.data.value + "'";
  193. } else {
  194. condition += ' OR ' + f.logic + "='" + d.data.value + "'";
  195. }
  196. }
  197. });
  198. condition += ')';
  199. }
  200. } else {
  201. //一般情况下,在执行批量处理时,是不需要把form的数据传回去,
  202. //但某些情况下,需要将form的某些字段的值也传回去
  203. //例如 请购批量转采购,如果指定了采购单号,就要把采购单号传回去
  204. if(contains(f.logic, 'to:', true)){
  205. if(!grid.toField){
  206. grid.toField = new Array();
  207. }
  208. grid.toField.push(f.logic.split(':')[1]);
  209. } else {
  210. if(!Ext.isEmpty(f.value)){
  211. if(contains(f.value.toString(), 'BETWEEN', true) && contains(f.value.toString(), 'AND', true)){
  212. if(condition == ''){
  213. condition += f.logic + " " + f.value;
  214. } else {
  215. condition += ' AND (' + f.logic + " " + f.value + ")";
  216. }
  217. } else if(contains(f.value.toString(), '||', true)){
  218. var str = '';
  219. Ext.each(f.value.split('||'), function(v){
  220. if(v != null && v != ''){
  221. if(str == ''){
  222. str += f.logic + "='" + v + "'";
  223. } else {
  224. str += ' OR ' + f.logic + "='" + v + "'";
  225. }
  226. }
  227. });
  228. if(condition == ''){
  229. condition += "(" + str + ")";
  230. } else {
  231. condition += ' AND (' + str + ")";
  232. }
  233. } else if(f.value.toString().charAt(0) == '!'){
  234. if(condition == ''){
  235. condition += 'nvl(' + f.logic + ",' ')<>'" + f.value.substr(1) + "'";
  236. } else {
  237. condition += ' AND (nvl(' + f.logic + ",' ')<>'" + f.value.substr(1) + "')";
  238. }
  239. } else {
  240. if(condition == ''){
  241. condition += f.logic + "='" + f.value + "'";
  242. } else {
  243. condition += ' AND (' + f.logic + "='" + f.value + "')";
  244. }
  245. }
  246. }
  247. }
  248. }
  249. }
  250. }
  251. });
  252. return condition;
  253. },
  254. vastDeal: function(url,type){
  255. var grid = Ext.getCmp('batchDealGridPanel');
  256. var form = Ext.getCmp('dealform');
  257. var wc_id=getUrlParam('keyValue');
  258. var panelId=getUrlParam('panelId');
  259. var records =null;
  260. if(type&&type=='all'){
  261. records=Ext.Array.unique(grid.getStore().data.items);
  262. }else {
  263. var items = grid.selModel.getSelection();
  264. Ext.each(items, function(item, index){
  265. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  266. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  267. item.index = this.data[grid.keyField];
  268. grid.multiselected.push(item);
  269. }
  270. });
  271. records = Ext.Array.unique(grid.multiselected);
  272. }
  273. if(records.length > 0){
  274. var params = new Object();
  275. params.caller = caller;
  276. var data = new Array();
  277. var bool = false;
  278. Ext.each(records, function(record, index){
  279. var f = form.fo_detailMainKeyField;
  280. if((grid.keyField && this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  281. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0)
  282. ||(f && this.data[f] != null && this.data[f] != ''
  283. && this.data[f] != '0' && this.data[f] != 0)){
  284. bool = true;
  285. var o = new Object();
  286. if(grid.keyField){
  287. o[grid.keyField] = record.data[grid.keyField];
  288. } else {
  289. params.id[index] = record.data[form.fo_detailMainKeyField];
  290. }
  291. if(grid.toField){
  292. Ext.each(grid.toField, function(f, index){
  293. var v = Ext.getCmp(f).value;
  294. if(v != null && v.toString().trim() != '' && v.toString().trim() != 'null'){
  295. o[f] = v;
  296. }
  297. });
  298. }
  299. if(grid.necessaryFields){
  300. Ext.each(grid.necessaryFields, function(f, index){
  301. var v = record.data[f];
  302. if(Ext.isDate(v)){
  303. v = Ext.Date.toString(v);
  304. }
  305. o[f] = v;
  306. });
  307. }
  308. data.push(o);
  309. }
  310. });
  311. if(bool){
  312. params.data = unescape(Ext.JSON.encode(data).replace(/\\/g,"%"));
  313. params.wc_id=wc_id;
  314. var main = parent.Ext.getCmp("content-panel");
  315. main.getActiveTab().setLoading(true);//loading...
  316. Ext.Ajax.request({
  317. url : basePath + url,
  318. params: params,
  319. method : 'post',
  320. callback : function(options,success,response){
  321. main.getActiveTab().setLoading(false);
  322. var localJson = new Ext.decode(response.responseText);
  323. if(localJson.exceptionInfo){
  324. var str = localJson.exceptionInfo;
  325. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){
  326. str = str.replace('AFTERSUCCESS', '');
  327. grid.multiselected = new Array();
  328. Ext.getCmp('dealform').onQuery();
  329. }
  330. showError(str);return;
  331. }
  332. if(localJson.success){
  333. if(localJson.log){
  334. showMessage("提示", localJson.log);
  335. }
  336. Ext.Msg.alert("提示", "处理成功!", function(){
  337. var panel=parent.Ext.getCmp(panelId);
  338. main.getActiveTab().close();
  339. var loadgrid=panel.currentGrid;
  340. loadgrid.getGridColumnsAndStore(grid,'common/singleGridPanel.action',{caller:'WCPlan',condition:'wd_wcid='+wc_id});
  341. main.setActiveTab(panel);
  342. });
  343. }
  344. }
  345. });
  346. } else {
  347. showError("没有需要处理的数据!");
  348. }
  349. }
  350. },
  351. });