ChanceManage.js 11 KB

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