Bez popisu

huTotal.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. var token = $.cookie("token");
  2. var seriesData = []; //柱形图数据
  3. var date; //初始日期
  4. var arrNum = [];
  5. var myChart;
  6. var aa = true;
  7. //日期
  8. laydate.render({
  9. elem: "#chooseTime",
  10. format: "yyyy-MM",
  11. type: "month",
  12. theme: "#00a1cb",
  13. // value: new Date()
  14. });
  15. //tab切换
  16. $(".hu-tab li").click(function () {
  17. $(this).addClass("active").siblings().removeClass("active");
  18. var index = $(this).index();
  19. $(".hu-content >div").eq(index).show().siblings().hide();
  20. });
  21. $(document).ready(function () {
  22. //柱形图
  23. // 基于准备好的dom,初始化echarts实例
  24. myChart = echarts.init(document.getElementById("huData"));
  25. option = {
  26. color: ["#1ab394"],
  27. tooltip: {
  28. trigger: "axis",
  29. axisPointer: {
  30. // 坐标轴指示器,坐标轴触发有效
  31. type: "line", // 默认为直线,可选为:'line' | 'shadow'
  32. },
  33. },
  34. toolbox: {
  35. show: true,
  36. },
  37. calculable: true,
  38. xAxis: [
  39. {
  40. type: "category",
  41. name: "月份",
  42. splitLine: {
  43. show: false,
  44. }, //去除网格线
  45. data: [
  46. "1月",
  47. "2月",
  48. "3月",
  49. "4月",
  50. "5月",
  51. "6月",
  52. "7月",
  53. "8月",
  54. "9月",
  55. "10月",
  56. "11月",
  57. "12月",
  58. ],
  59. axisTick: {
  60. alignWithLabel: true,
  61. },
  62. },
  63. ],
  64. yAxis: [
  65. {
  66. type: "value",
  67. name: "通话量",
  68. nameLocation: "end",
  69. splitLine: {
  70. show: false,
  71. }, //去除网格线
  72. },
  73. ],
  74. series: [
  75. {
  76. name: "通话量",
  77. type: "bar",
  78. barWidth: "30%", //图形宽度
  79. data: arrNum,
  80. itemStyle: {
  81. normal: {
  82. label: {
  83. show: true,
  84. textStyle: {
  85. color: "#800080", //顶部数据颜色
  86. },
  87. },
  88. },
  89. },
  90. label: {
  91. normal: {
  92. show: true,
  93. position: "top", //顶部数据显示位置
  94. },
  95. },
  96. },
  97. ],
  98. };
  99. // 使用刚指定的配置项和数据显示图表。
  100. tu(date);
  101. myChart.setOption(option);
  102. // myChart.on('click', function(params) {
  103. // console.log(params);
  104. // if(params.componentType === 'series') {
  105. // if(params.dataIndex) {
  106. // console.log(params.data)
  107. // var month = params.name;
  108. // console.log(month);
  109. // }
  110. // }
  111. // });
  112. });
  113. Ajax(date);
  114. //搜索事件
  115. $(".sear").click(function () {
  116. $(".huTable tbody").html("");
  117. date = $("#chooseTime").val();
  118. Ajax(date);
  119. tu(date);
  120. myChart.setOption(option);
  121. });
  122. function Ajax(date) {
  123. $(".huTable tbody").html("");
  124. $.ajax({
  125. type: "get",
  126. url: huayi.config.callcenter_url + "TotalCall/GetDataList",
  127. async: true,
  128. dataType: "json",
  129. data: {
  130. token: token,
  131. years: date,
  132. },
  133. success: function (data) {
  134. var con = data.data;
  135. if (con == null) {
  136. // $(".huTable tbody").html('');
  137. $('<tr><td colspan="3">暂无数据</td></tr>').appendTo(
  138. ".huTable tbody"
  139. );
  140. } else {
  141. for (var i = 0; i < con.length; i++) {
  142. $(
  143. "<tr><td>" +
  144. con[i].月份 +
  145. "</td><td>" +
  146. con[i].日期 +
  147. "</td><td>" +
  148. con[i].总数 +
  149. "</td></tr>"
  150. ).appendTo(".huTable tbody");
  151. }
  152. }
  153. },
  154. });
  155. }
  156. function tu(date) {
  157. var arr = [];
  158. $.ajax({
  159. type: "get",
  160. url: huayi.config.callcenter_url + "TotalCall/GetChartData",
  161. async: false,
  162. dataType: "json",
  163. data: {
  164. token: token,
  165. years: date,
  166. },
  167. success: function (data) {
  168. //console.log(data.data)
  169. arr = data.data;
  170. console.log(arr);
  171. },
  172. });
  173. arrNum = arr;
  174. console.log(arrNum);
  175. option.series[0].data = arrNum;
  176. }
  177. //导出
  178. $(".export").click(function () {
  179. dcexcel(this);
  180. });
  181. function dcexcel(obj) {
  182. var url =
  183. huayi.config.callcenter_url +
  184. "TotalCall/ExptList?token=" +
  185. $.cookie("token");
  186. url += "&years=" + $("#chooseTime").val();
  187. obj.href = url;
  188. }