WCPlanResult.js 12 KB

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