ShowFunnel.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.crm.chance.ShowFunnel', {
  3. extend: 'Ext.app.Controller',
  4. GridUtil: Ext.create('erp.util.GridUtil'),
  5. views:[
  6. 'crm.chance.ShowFunnel.Viewport','crm.chance.ShowFunnel.GridPanel','core.trigger.DbfindTrigger',
  7. 'core.form.FtField','core.form.ConDateField','core.form.YnField','core.form.FtDateField',
  8. 'core.form.FtFindField','core.grid.YnColumn','core.grid.TfColumn','core.form.ConMonthDateField'
  9. ],
  10. init:function(){
  11. this.control({
  12. 'erpQueryFormPanel button[name=confirm]': {
  13. },
  14. /*'button[name=hide]':{
  15. afterrender: function(btn){
  16. var me = this;
  17. me.funnel();
  18. }
  19. },*/
  20. 'button[name=query]':{
  21. afterrender: function(btn){
  22. controller=this;
  23. var me = this;
  24. var filter = me.createFilterPanel(btn);
  25. filter.show();
  26. me.funnel();
  27. },
  28. click: function(btn){
  29. var me = this;
  30. if(Ext.getCmp(btn.getId() + '-filter')){
  31. Ext.getCmp(btn.getId() + '-filter').show();
  32. }else{
  33. var filter = me.createFilterPanel(btn);
  34. filter.show();
  35. }
  36. }
  37. }
  38. });
  39. },
  40. createFilterPanel:function(btn){
  41. var me = this;
  42. var filter = Ext.create('Ext.Window', {
  43. id: btn.getId() + '-filter',
  44. style: 'background:#f1f1f1',
  45. title: '筛选条件',
  46. width: 500,
  47. modal:true,
  48. height: 385,
  49. layout: 'column',
  50. defaults: {
  51. margin: '2 2 2 10'
  52. },
  53. items: [/*{
  54. id: 'cm_yearmonth',
  55. name: 'cm_yearmonth',
  56. xtype: 'conmonthdatefield',
  57. fieldLabel: '期间',
  58. labelWidth: 80,
  59. margin: '10 2 2 10',
  60. columnWidth: .51,
  61. getValue: function() {
  62. if(!Ext.isEmpty(this.value)) {
  63. return {begin: this.firstVal, end: this.secondVal};
  64. }
  65. return null;
  66. },
  67. listeners:{
  68. afterrender:function(cmd){
  69. me.getCurrentYearmonth(cmd);
  70. }
  71. }
  72. },*/{
  73. xtype: 'dbfindtrigger',
  74. fieldLabel: '任务执行人',
  75. height: 23,
  76. labelWidth: 80,
  77. id: 'ch_tasker',
  78. name:'ch_tasker',
  79. margin: '10 2 2 10',
  80. flex: 0.2,
  81. columnWidth: .51
  82. },{
  83. fieldLabel: '客户编码',
  84. labelWidth: 80,
  85. height: 23,
  86. layout: 'hbox',
  87. columnWidth: 1,
  88. xtype: 'fieldcontainer',
  89. id: 'chq_cucode',
  90. defaults: {
  91. fieldStyle : "background:#FFFAFA;color:#515151;"
  92. },
  93. items: [{
  94. labelWidth: 35,
  95. xtype: 'dbfindtrigger',
  96. flex: 0.32,
  97. id: 'ch_cucode',
  98. name: 'ch_cucode'
  99. },{
  100. xtype: 'textfield',
  101. id: 'ch_cuname',
  102. name: 'ch_cuname',
  103. flex:0.32,
  104. readOnly: true,
  105. fieldStyle: 'background:#f1f1f1;'
  106. }],
  107. getValue: function() {
  108. var a = Ext.getCmp('ch_cucode');
  109. if(!Ext.isEmpty(a.value)) {
  110. return {ch_cucode: a.value};
  111. }
  112. return null;
  113. }
  114. }/*,{
  115. xtype: 'checkbox',
  116. id: 'chkumio',
  117. name: 'chkumio',
  118. columnWidth: .51,
  119. boxLabel: '包含未开票未转发出商品出货'
  120. },{
  121. xtype: 'checkbox',
  122. id: 'chkzerobalance',
  123. name: 'chkzerobalance',
  124. columnWidth: .51,
  125. boxLabel: '余额为零的不显示'
  126. },{
  127. xtype: 'checkbox',
  128. id: 'chknoamount',
  129. name: 'chknoamount',
  130. columnWidth: .51,
  131. boxLabel: '无发生额的不显示'
  132. },{
  133. xtype: 'checkbox',
  134. id: 'chkstatis',
  135. name: 'chkstatis',
  136. checked:true,
  137. columnWidth: .51,
  138. boxLabel: '是否显示汇总数'
  139. }*/],
  140. buttonAlign: 'center',
  141. buttons: [{
  142. text: '确定',
  143. width: 60,
  144. cls: 'x-btn-blue',
  145. handler: function(btn) {
  146. var fl = btn.ownerCt.ownerCt;
  147. var con = me.getCondition(fl);
  148. f=fl;
  149. var grid = Ext.getCmp('crmquerygrid');
  150. //grid.chkumio = Ext.getCmp('chkumio').getValue();
  151. me.query(con);
  152. fl.hide();
  153. }
  154. },{
  155. text: '关闭',
  156. width: 60,
  157. cls: 'x-btn-blue',
  158. name:'hide',
  159. handler: function(btn) {
  160. var fl = btn.ownerCt.ownerCt;
  161. fl.hide();
  162. }
  163. }]
  164. });
  165. return filter;
  166. },
  167. // getCurrentYearmonth: function(f) {
  168. // Ext.Ajax.request({
  169. // url: basePath + 'fa/arp/getCurrentYearmonth.action',
  170. // method: 'GET',
  171. // callback: function(opt, s, r) {
  172. // var rs = Ext.decode(r.responseText);
  173. // if(rs.exceptionInfo) {
  174. // showError(rs.exceptionInfo);
  175. // } else if(rs.data) {
  176. // f.setValue(rs.data);
  177. // }
  178. // }
  179. // });
  180. // },
  181. getCondition: function(pl) {
  182. var r = new Object(),v;
  183. Ext.each(pl.items.items, function(item){
  184. if(item.getValue !== undefined) {
  185. v = item.getValue();
  186. if(!Ext.isEmpty(v)) {
  187. r[item.id] = v;
  188. }
  189. }
  190. });
  191. var tb = Ext.getCmp('gl_info_ym');
  192. if(tb)
  193. tb.updateInfo(r);
  194. return r;
  195. },
  196. funnel:function(){
  197. var funneldata=new Array();
  198. Ext.Ajax.request({
  199. url:basePath+'crm/funnel.action',
  200. params:{
  201. condition: {}
  202. },
  203. method : 'post',
  204. async:false,
  205. callback : function(options,success,response){
  206. sum=0;
  207. var res = new Ext.decode(response.responseText);
  208. if(res.exceptionInfo != null){
  209. showError(res.exceptionInfo);return;
  210. }
  211. if(res.data){
  212. var i=0;
  213. var data=res.data;
  214. Ext.each(data,function(da){
  215. Ext.each(Ext.Object.getKeys(da),function(key){
  216. sum+=da[key];
  217. var d=new Array();
  218. d[0]=key,d[1]=da[key];
  219. funneldata[i]=d;
  220. i++;
  221. });
  222. });
  223. }
  224. }
  225. });
  226. chancefunnel=new Highcharts.Chart({
  227. chart: {
  228. reflow: false,
  229. renderTo: 'panel-body',
  230. type: 'funnel',
  231. marginRight: 100,
  232. width:800,
  233. heigth:298
  234. },
  235. title: {
  236. text: '商机销售漏斗',
  237. x: -50
  238. },
  239. plotOptions: {
  240. series: {
  241. dataLabels: {
  242. enabled: true,
  243. formatter:function(){//<a href="javascript:void(0)" onclick="controller.clickfunnel(this)"></a>
  244. return '<b>'+this.key+'</b> ('+this.y +')--'+Math.round(this.y/sum*100)+'% ';
  245. },
  246. color: 'black',
  247. softConnector: true
  248. },
  249. neckWidth: '30%',
  250. neckHeight: '25%',
  251. events:{
  252. click:function(e){
  253. controller.clickfunnel(e.point.name);
  254. }
  255. }
  256. }
  257. },
  258. legend: {
  259. enabled: false
  260. },
  261. series: [{
  262. name: '数 量',
  263. data:funneldata
  264. }]
  265. });
  266. },
  267. query: function(cond) {
  268. var me = this;
  269. var grid = Ext.getCmp('crmquerygrid');
  270. grid.setLoading(true);
  271. var funneldata=new Array();
  272. Ext.Ajax.request({
  273. url:basePath+'crm/funnel.action',
  274. params:{
  275. condition: Ext.encode(cond)
  276. },
  277. method : 'post',
  278. async:false,
  279. callback : function(options,success,response){
  280. sum=0;
  281. var res = new Ext.decode(response.responseText);
  282. if(res.exceptionInfo != null){
  283. showError(res.exceptionInfo);return;
  284. }
  285. if(res.data){
  286. var i=0;
  287. var data=res.data;
  288. Ext.each(data,function(da){
  289. Ext.each(Ext.Object.getKeys(da),function(key){
  290. sum+=da[key];
  291. var d=new Array();
  292. d[0]=key,d[1]=da[key];
  293. funneldata[i]=d;
  294. i++;
  295. });
  296. });
  297. }
  298. }
  299. });
  300. chancefunnel.series[0].setData(funneldata);
  301. Ext.Ajax.request({
  302. url: basePath + 'crm/chance/getChanceQuery.action',
  303. params: {
  304. condition: Ext.encode(cond)
  305. },
  306. callback : function(options,success,response){
  307. grid.setLoading(false);
  308. var res = new Ext.decode(response.responseText);
  309. me.doQuery(grid,res);
  310. }
  311. });
  312. },
  313. clickfunnel: function(con) {
  314. var me = this;
  315. var cond=me.getCondition(f);
  316. if(con){
  317. cond['ch_stage']=con;
  318. }
  319. var grid = Ext.getCmp('crmquerygrid');
  320. grid.setLoading(true);
  321. Ext.Ajax.request({
  322. url: basePath + 'crm/chance/getChanceQuery.action',
  323. params: {
  324. condition: Ext.encode(cond)
  325. },
  326. callback : function(options,success,response){
  327. grid.setLoading(false);
  328. var res = new Ext.decode(response.responseText);
  329. me.doQuery(grid,res);
  330. }
  331. });
  332. },
  333. doQuery:function(grid,res){
  334. var me=this;
  335. if(res.exceptionInfo){
  336. showError(res.exceptionInfo);return;
  337. }
  338. if(res.columns){
  339. var limits = res.limits, limitArr = new Array();
  340. if(limits != null && limits.length > 0) {//权限外字段
  341. limitArr = Ext.Array.pluck(limits, 'lf_field');
  342. }
  343. Ext.each(res.columns, function(column, y){
  344. //power
  345. if(limitArr.length > 0 && Ext.Array.contains(limitArr, column.dataIndex)) {
  346. column.hidden = true;
  347. }
  348. //renderer
  349. me.GridUtil.setRenderer(grid, column);
  350. //logictype
  351. me.GridUtil.setLogicType(grid, column);
  352. });
  353. //data
  354. var data = [];
  355. if(!res.data || res.data.length == 2){
  356. me.GridUtil.add10EmptyData(grid.detno, data);
  357. me.GridUtil.add10EmptyData(grid.detno, data);//添加20条空白数据
  358. } else {
  359. data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  360. }
  361. if(grid.columns && grid.columns.length > 0) {
  362. grid.store.loadData(data);return;
  363. }
  364. //store
  365. var store = me.GridUtil.setStore(grid, res.fields, data, grid.groupField, grid.necessaryField);
  366. //view
  367. if(grid.selModel.views == null){
  368. grid.selModel.views = [];
  369. }
  370. //dbfind
  371. if(res.dbfinds.length > 0){
  372. grid.dbfinds = res.dbfinds;
  373. }
  374. //toolbar
  375. me.GridUtil.setToolbar(grid, res.columns, res.necessaryField);
  376. //reconfigure
  377. grid.reconfigure(store, res.columns);
  378. }
  379. }
  380. });