special_analysis.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. $(function(){
  2. // 一级行业select控件初始化
  3. var firstIndSelect = $('select[name="firstInd"]').select2({
  4. placeholder: "请输入一级行业",
  5. allowClear: true,
  6. width:'286px',
  7. ajax:{
  8. url: _PUBLIC_ +'ad-select/top_category_by_type.do',
  9. dataType:'json',
  10. quietMillis:100,
  11. data:function(params){
  12. return {
  13. name : params.term,
  14. type : 0, //栏目管理
  15. pageNo : params.page || 1,
  16. pageSize : 20
  17. }
  18. },
  19. processResults: function (data, params) {
  20. params.page = params.page || 1;
  21. return {
  22. results: data.results,
  23. pagination: {
  24. more: (params.page * 20) < data.total
  25. }
  26. };
  27. },
  28. cache: true
  29. }
  30. });
  31. //解绑二级行业select控件初始化
  32. $('select[name="firstInd"]').live('change',function(){
  33. $('select[name="secondInd"]').html('<option value=""></option>');
  34. });
  35. // 二级行业select控件初始化
  36. var secondIndSelect = $('select[name="secondInd"]').select2({
  37. placeholder: "请输入二级行业",
  38. allowClear: true,
  39. width:'286px',
  40. ajax:{
  41. url: _PUBLIC_ +'ad-select/second_category_by_type.do',
  42. dataType:'json',
  43. quietMillis:100,
  44. data:function(params){
  45. return {
  46. name : params.term,
  47. type : 0, //栏目管理,
  48. parentName : $('#firstInd').val(),
  49. pageNo : params.page || 1,
  50. pageSize : 20
  51. }
  52. },
  53. processResults: function (data, params) {
  54. params.page = params.page || 1;
  55. return {
  56. results: data.results,
  57. pagination: {
  58. more: (params.page * 20) < data.total
  59. }
  60. };
  61. },
  62. cache: true
  63. }
  64. });
  65. $('select[name="showEnv"]').select2({
  66. placeholder: "请选择播出环境",
  67. allowClear: true,
  68. width: '286px'
  69. });
  70. // 播出媒体
  71. var mediaNameSelect = $('select[name="mediaName"]').select2({
  72. placeholder: "请输入播出媒体",
  73. allowClear: true,
  74. width:'286px',
  75. ajax:{
  76. url: _PUBLIC_ +'ad-media/select/list.do',
  77. dataType:'json',
  78. quietMillis:100,
  79. data:function(params){
  80. return {
  81. name : params.term,
  82. pageNo : params.page || 1,
  83. pageSize : 20
  84. }
  85. },
  86. processResults: function (data, params) {
  87. params.page = params.page || 1;
  88. return {
  89. results: data.results,
  90. pagination: {
  91. more: (params.page * 20) < data.total
  92. }
  93. };
  94. },
  95. cache: true
  96. }
  97. });
  98. $('select[name="type"]').select2({
  99. placeholder: "请选择类型",
  100. allowClear: true,
  101. width: '100px'
  102. });
  103. });
  104. var cur_brand = '',cur_secondInd = '',cur_type = '' , cur_type_name= '';
  105. function getBrandDetail(){
  106. // 媒体分布
  107. getMediaChartsData();
  108. // 广告分布
  109. getTVChartsData();
  110. // 二级行业品牌频次分布
  111. getSecondIndChartsFrequencyData();
  112. // 二级行业品牌时长分布
  113. getSecondIndChartsDurationData();
  114. // 产品T30排序分布
  115. getProductRankList();
  116. // 栏目T30排序分布
  117. getPlatformRankList();
  118. // 修改产品名称
  119. changeTagName();
  120. }
  121. // 获取对标对象
  122. function itemCheck(o){
  123. var item = $("input[name='item']:checked"), ids = [] , productNameList = [],productTypeList = [];
  124. if(item.length > 3){
  125. alert("最多选择三个对标产品。");
  126. $(o).attr("checked", false);
  127. $.checkbox();
  128. return false;
  129. }
  130. item.each(function(){
  131. var type = $(this).attr('data-type');
  132. var data = $(this).val().split("_");
  133. ids.push(data[0]);
  134. productTypeList.push(type);
  135. productNameList.push(data[1]);
  136. });
  137. if(productTypeList.length > 0 && (new Set(productTypeList)).size != 1){
  138. alert("请选择同是产品或栏目对标分析。");
  139. $(o).attr("checked", false);
  140. $.checkbox();
  141. return false;
  142. }
  143. if((new Set(productNameList)).size != productNameList.length){
  144. alert("已存在,请选择不同的对标产品。");
  145. $(o).attr("checked", false);
  146. $.checkbox();
  147. return false;
  148. }
  149. $.cookie.set("benchCheckNum",ids.join(","));
  150. }
  151. // 对标
  152. function setBenchmark(){
  153. var item = $("input[name='item']:checked"), ids = [], productNameList = [], productTypeList = [];
  154. if(item.length <= 0){
  155. alert("请至少选择一个对标的产品。");
  156. return false;
  157. }
  158. if(item.length > 3){
  159. alert("最多选择三个对标的产品。");
  160. return false;
  161. }
  162. item.each(function(){
  163. var type = $(this).attr('data-type');
  164. var data = $(this).val().split("_");
  165. ids.push(data[0]);
  166. productTypeList.push(type);
  167. productNameList.push(data[1]);
  168. });
  169. if(productTypeList.length > 0 && (new Set(productTypeList)).size != 1){
  170. alert("请选择同是产品或栏目对标分析。");
  171. return false;
  172. }
  173. if((new Set(productNameList)).size != productNameList.length){
  174. alert("已存在,请选择不同的对标产品。");
  175. return false;
  176. }
  177. window.open("benchmarking.do?type="+productTypeList[0]+"&ids="+encodeURIComponent(ids.join("|")),"new");
  178. }
  179. /**
  180. * 切换时间
  181. */
  182. function changeTab(day){
  183. var end_date = '', start_date = '';
  184. if(day > 0){
  185. end_date = new Date().addDate(-1).Format("yyyy-MM-dd"),
  186. start_date = new Date(end_date).addDate(-day).Format("yyyy-MM-dd");
  187. $('#start_time').val(start_date);
  188. $('#end_time').val(end_date);
  189. }else{
  190. $('#start_time').val('');
  191. $('#end_time').val('');
  192. }
  193. $(".text").input();
  194. //专题广告电视投放一览
  195. getBrandAnalysisList(1);
  196. }
  197. // 获取选中产品--并显示分析
  198. function changeBrand(brand,secondInd,type){
  199. cur_brand = brand;
  200. cur_secondInd = secondInd;
  201. cur_type = type;
  202. cur_type_name = (type == '0' ? "产品" : "栏目");
  203. getBrandDetail();
  204. }
  205. // 一级行业select控件初始化
  206. var firstIndSelect = $('select[name="firstInd"]').select2({
  207. placeholder: "请输入一级行业",
  208. allowClear: true,
  209. width:'286px',
  210. ajax:{
  211. url: _PUBLIC_ +'ad-select/top_category_by_type.do',
  212. dataType:'json',
  213. quietMillis:100,
  214. data:function(params){
  215. return {
  216. name : params.term,
  217. type : 0, //栏目管理
  218. pageNo : params.page || 1,
  219. pageSize : 20
  220. }
  221. },
  222. processResults: function (data, params) {
  223. params.page = params.page || 1;
  224. return {
  225. results: data.results,
  226. pagination: {
  227. more: (params.page * 20) < data.total
  228. }
  229. };
  230. },
  231. cache: true
  232. }
  233. });
  234. //解绑二级行业select控件初始化
  235. $('select[name="firstInd"]').live('change',function(){
  236. $('select[name="secondInd"]').html('<option value=""></option>');
  237. });
  238. // 二级行业select控件初始化
  239. var secondIndSelect = $('select[name="secondInd"]').select2({
  240. placeholder: "请输入二级行业",
  241. allowClear: true,
  242. width:'286px',
  243. ajax:{
  244. url: _PUBLIC_ +'ad-select/second_category_by_type.do',
  245. dataType:'json',
  246. quietMillis:100,
  247. data:function(params){
  248. return {
  249. name : params.term,
  250. type : 0, //栏目管理,
  251. parentName : $('#firstInd').val(),
  252. pageNo : params.page || 1,
  253. pageSize : 20
  254. }
  255. },
  256. processResults: function (data, params) {
  257. params.page = params.page || 1;
  258. return {
  259. results: data.results,
  260. pagination: {
  261. more: (params.page * 20) < data.total
  262. }
  263. };
  264. },
  265. cache: true
  266. }
  267. });
  268. // 专题广告电视投放一览
  269. function getBrandAnalysisList(page){
  270. page = page || 1;
  271. var pageSize = "20", data = {
  272. "pageNo": page,
  273. "pageSize": pageSize,
  274. "startDate": $("#start_time").val(),
  275. "endDate": $("#end_time").val(),
  276. "type": $("#type").val(),
  277. "keyword": $.trim($("#keyword").val()),
  278. "mediaName": $("#mediaName").val(),
  279. "showEnv": $("#showEnv").val(),
  280. "firstInd":$("#firstInd").val(),
  281. "secondInd":$("#secondInd").val(),
  282. }, html = "";
  283. $("#brand_analysis_page, #brand_analysis_list").empty();
  284. ajax("ajax_list.do",data,function(res){
  285. if(res.code == 1 && res.data.records.length > 0){
  286. $.each(res.data.records, function(index, item){
  287. if(index == 0){
  288. cur_brand = item.productName;
  289. cur_secondInd = item.secondInd;
  290. cur_type = item.type;
  291. }
  292. html += "<tr data-brand='"+item.productName+"' data-second_ind='"+item.secondInd+"' data-type='"+item.type+"'>"+
  293. "<td>"+$.orderNum(page,pageSize,index)+"</td>"+
  294. "<td>"+item.mediaName+"</td>"+
  295. "<td>"+item.showTime+"</td>"+
  296. "<td>"+item.showDate+"</td>"+
  297. "<td>"+item.showEnvMsg+"</td>"+
  298. "<td><a class='blue' href=javascript:void(0); onclick=toTheatreAnalysis('"+item.tvName+"') >"+item.tvName+"</a></td>"+
  299. "<td>"+item.showDuration+"</td>"+
  300. "<td>"+item.productName+"</td>"+
  301. "<td>"+item.brandName+"</td>"+
  302. "<td>"+item.firstInd+"</td>"+
  303. "<td>"+item.secondInd+"</td>"+
  304. "<td>"+item.advMaster+"</td>"+
  305. "<td>"+item.phone+"</td>"+
  306. "<td>"+item.price+"</td>"+
  307. "<td><input type='checkbox' class='checkbox {click:itemCheck}' name='item' "+($.cookie.get("benchCheckNum").indexOf(item.id) != -1 ? 'checked':'')+" value='"+item.id+"_"+item.productName+"' data-type='"+item.type+"' /><label></label></td>"+
  308. "</tr>";
  309. });
  310. $("#brand_analysis_list").html(html);
  311. $('#brand_analysis_count').html(res.data.total);
  312. $.radio();
  313. $.checkbox();
  314. var newpage = new createPage(res.data.total,page,pageSize,3,"getBrandAnalysisList");
  315. $("#brand_analysis_page").html(newpage.pageHtml);
  316. $('#brand_analysis_count').html(res.data.count);
  317. /**
  318. * 产品名称点击事件
  319. */
  320. $("#brand_analysis_list>tr>td:not(td:last-child)").on("click",function(){
  321. $(this).closest("tr").addClass("active").siblings().removeClass("active");
  322. changeBrand($(this).closest("tr").data("brand"),$(this).closest("tr").data("second_ind"),$(this).closest("tr").data("type"));
  323. });
  324. $("#brand_analysis_list>tr:eq(0)>td:eq(1)").click();
  325. }else{
  326. $("#brand_analysis_list").info("暂无数据。");
  327. $("#frequency_pie,#length_pie").info("暂无数据。", true);
  328. $("#rating_35,#rating_29").info("暂无数据。", true);
  329. $("#net_chart,#douban_chart").info("暂无数据。", true);
  330. $("span[name='brand_tag']").html('“”');
  331. $("span[name='secondInd_tag']").html('“”');
  332. $('#brand_analysis_count').html(0);
  333. // 产品T30排序分布
  334. getProductRankList();
  335. // 栏目T30排序分布
  336. getPlatformRankList();
  337. }
  338. });
  339. }
  340. // 媒体分布
  341. function getMediaChartsData(){
  342. var data = {
  343. "type" : cur_type,
  344. "productName": cur_brand,
  345. "startDate": $("#start_time").val(),
  346. "endDate": $("#end_time").val()
  347. };
  348. ajax("media_dist.do",data,function(res){
  349. if(res.code == 1 && res.data.length > 0){
  350. var legend= [], series = [],xdata = [],ydata = [];
  351. var xOther = 0, yOther = 0;
  352. data1 = res.data.sort(function(a,b){
  353. return b.duration-a.duration;
  354. });
  355. $.each(data1, function(index, item){
  356. if (index >= 10){
  357. yOther += item.duration;
  358. return true;
  359. }
  360. legend.push(item.name);
  361. // 时长
  362. var lv2 = {
  363. value: item.duration,
  364. name : item.name
  365. };
  366. ydata.push(lv2);
  367. });
  368. data2 = res.data.sort(function(a,b){
  369. return b.total-a.total;
  370. });
  371. $.each(data2, function(index, item){
  372. if (index >= 10){
  373. xOther += item.total;
  374. return true;
  375. }
  376. legend.push(item.name);
  377. // 频次
  378. var lv1 = {
  379. value: item.total,
  380. name : item.name
  381. };
  382. xdata.push(lv1);
  383. });
  384. // 其它
  385. if (xOther > 0){
  386. var temp = {
  387. value: xOther,
  388. name : '其它'
  389. };
  390. xdata.push(temp);
  391. }
  392. if (yOther > 0){
  393. var temp = {
  394. value: yOther,
  395. name : '其它'
  396. };
  397. ydata.push(temp);
  398. }
  399. drawPie("频次分布",xdata,'frequency_pie');
  400. drawPie("时长分布",ydata,'length_pie');
  401. }else{
  402. $("#frequency_pie,#length_pie").info("暂无数据。", true);
  403. }
  404. },false);
  405. }
  406. //电视剧分布
  407. function getTVChartsData(){
  408. var data = {
  409. "type" : cur_type,
  410. "productName": cur_brand,
  411. "startDate": $("#start_time").val(),
  412. "endDate": $("#end_time").val()
  413. };
  414. ajax("tv_dist.do",data,function(res){
  415. if(res.code == 1 && res.data.length > 0){
  416. var legend= [], series = [],xdata = [],ydata = [];
  417. var xOther = 0, yOther = 0;
  418. data1 = res.data.sort(function(a,b){
  419. return b.duration-a.duration;
  420. });
  421. $.each(data1, function(index, item){
  422. if (index >= 10){
  423. yOther += item.duration;
  424. return true;
  425. }
  426. legend.push(item.name);
  427. // 时长
  428. var lv2 = {
  429. value: item.duration,
  430. name : item.name
  431. };
  432. ydata.push(lv2);
  433. });
  434. data2 = res.data.sort(function(a,b){
  435. return b.total-a.total;
  436. });
  437. $.each(data2, function(index, item){
  438. if (index >= 10){
  439. xOther += item.total;
  440. return true;
  441. }
  442. legend.push(item.name);
  443. // 频次
  444. var lv1 = {
  445. value: item.total,
  446. name : item.name
  447. };
  448. xdata.push(lv1);
  449. });
  450. // 其它
  451. if (xOther > 0){
  452. var temp = {
  453. value: xOther,
  454. name : '其它'
  455. };
  456. xdata.push(temp);
  457. }
  458. if (yOther > 0){
  459. var temp = {
  460. value: yOther,
  461. name : '其它'
  462. };
  463. ydata.push(temp);
  464. }
  465. drawPie("频次分布",xdata,'rating_35');
  466. drawPie("时长分布",ydata,'rating_29');
  467. }else{
  468. $("#rating_35,#rating_29").info("暂无数据。", true);
  469. }
  470. },false);
  471. }
  472. //二级行业品牌频次分布TOP10
  473. function getSecondIndChartsFrequencyData(){
  474. var data = {
  475. "type" : cur_type,
  476. "launch": 0, // 频次
  477. "secondInd": cur_secondInd,
  478. "startDate": $("#start_time").val(),
  479. "endDate": $("#end_time").val()
  480. };
  481. ajax("second_ind_dist.do",data,function(res){
  482. if(res.code == 1 && res.data.length > 0){
  483. var series_frequency = [], xOther = 0;
  484. $.each(res.data, function(index, item){
  485. if (index >= 10){
  486. xOther += item.total;
  487. return true;
  488. }
  489. var lv1 = {
  490. value: item.total,
  491. name : item.name
  492. };
  493. series_frequency.push(lv1);
  494. });
  495. // 其它
  496. if (xOther > 0){
  497. var temp = {
  498. value: xOther,
  499. name : '其它'
  500. };
  501. series_frequency.push(temp);
  502. }
  503. drawPie("频次分布",series_frequency,'net_chart');
  504. }else{
  505. $("#net_chart").info("暂无数据。", true);
  506. }
  507. },false);
  508. }
  509. //二级行业品牌时长分布TOP10
  510. function getSecondIndChartsDurationData(){
  511. var data = {
  512. "type" : cur_type,
  513. "launch": 1, // 时长
  514. "secondInd": cur_secondInd,
  515. "startDate": $("#start_time").val(),
  516. "endDate": $("#end_time").val()
  517. };
  518. ajax("second_ind_dist.do",data,function(res){
  519. if(res.code == 1 && res.data.length > 0){
  520. var series_length = [], xOther = 0;
  521. $.each(res.data, function(index, item){
  522. if (index >= 10){
  523. xOther += item.duration;
  524. return true;
  525. }
  526. var lv2 = {
  527. value:item.duration,
  528. name:item.name
  529. };
  530. series_length.push(lv2);
  531. });
  532. // 其它
  533. if (xOther > 0){
  534. var temp = {
  535. value: xOther,
  536. name : '其它'
  537. };
  538. series_length.push(temp);
  539. }
  540. drawPie("时长分布",series_length,'douban_chart');
  541. }else{
  542. $("#douban_chart").info("暂无数据。", true);
  543. }
  544. },false);
  545. }
  546. /**
  547. * 产品专题广告投放排名
  548. */
  549. function getProductRankList(){
  550. var data = {
  551. "type" : 0,
  552. "startDate": $("#start_time").val(),
  553. "endDate": $("#end_time").val()
  554. },html="";
  555. ajax("product_rank.do",data,function(res){
  556. if(res.code == 1 && res.data){
  557. if(res.data.length > 0){
  558. $.each(res.data, function(index, item){
  559. html += "<tr class='"+(cur_brand == item.productName && cur_secondInd == item.secondInd ? 'trHover':'')+"'>"+
  560. "<td>"+(index+1)+"</td>"+
  561. "<td>"+item.productName+"</td>"+
  562. "<td>"+item.secondInd+"</td>"+
  563. "<td>"+item.frequency+"</td>"+
  564. "<td>"+item.duration+"</td>"+
  565. "</tr>";
  566. });
  567. $("#program_rank_list").html(html);
  568. }else{
  569. $("#program_rank_list").info("暂无数据。");
  570. }
  571. }
  572. },false);
  573. }
  574. /**
  575. * 栏目专题广告投放排名
  576. */
  577. function getPlatformRankList(){
  578. var data = {
  579. "type" : 1,
  580. "startDate": $("#start_time").val(),
  581. "endDate": $("#end_time").val()
  582. },html="";
  583. ajax("product_rank.do",data,function(res){
  584. if(res.code == 1 && res.data){
  585. if(res.data.length > 0){
  586. $.each(res.data, function(index, item){
  587. html += "<tr class='"+(cur_brand == item.productName && cur_secondInd == item.secondInd ? 'trHover':'')+"'>"+
  588. "<td>"+(index+1)+"</td>"+
  589. "<td>"+item.productName+"</td>"+
  590. "<td>"+item.secondInd+"</td>"+
  591. "<td>"+item.frequency+"</td>"+
  592. "<td>"+item.duration+"</td>"+
  593. "</tr>";
  594. });
  595. $("#brand_rank_list").html(html);
  596. }else{
  597. $("#brand_rank_list").info("暂无数据。");
  598. }
  599. }
  600. },false);
  601. }
  602. // 扇形图显示
  603. function drawPie(title,series, divId){
  604. option = {
  605. tooltip: {
  606. trigger: 'item',
  607. formatter: '{a} <br/>{b} : {c} ({d}%)'
  608. },
  609. series: [
  610. {
  611. color: ['#1890FF','#F6BD16','#E8684A','#6DC8EC','#9270CA','#FF9D4D','#269A99','#73A0FA','#5AD8A6','#5D7092','#6DC8EC','#9270CA','#FF9D4D','#269A99'],
  612. name:title,
  613. type: 'pie',
  614. radius: '75%',
  615. center: ['50%', '50%'],
  616. data: series,
  617. emphasis: {
  618. itemStyle: {
  619. shadowBlur: 10,
  620. shadowOffsetX: 0,
  621. shadowColor: 'rgba(0, 0, 0, 0.5)'
  622. }
  623. }
  624. }
  625. ]
  626. };
  627. var myChart = echarts.init(document.getElementById(divId));
  628. document.getElementById(divId).setAttribute('_echarts_instance_', '')
  629. myChart.clear();
  630. myChart.setOption(option);
  631. }
  632. // 修改产品名称
  633. function changeTagName(){
  634. $("span[name='type_tag']").html(cur_type_name);
  635. $("span[name='brand_tag']").html('“'+cur_brand+'”');
  636. $("span[name='secondInd_tag']").html('“'+cur_secondInd+'”');
  637. }