开封利通水务前端

huTotal.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. var token = $.cookie("token");
  2. var date; //初始日期
  3. var myChart;
  4. var tabIndex = 0;
  5. $(document).ready(function() {
  6. var nowY = helper.DateFormat.getNowYear();
  7. $('#chooseTime').val(nowY);
  8. layui.use('laydate', function() {
  9. var laydate = layui.laydate;
  10. //日期
  11. laydate.render({
  12. elem: '#chooseTime',
  13. format: 'yyyy',
  14. type: 'year',
  15. //value: nowY,
  16. theme: '#1ab394',
  17. });
  18. });
  19. //tab切换
  20. $('.hu-tab li').click(function() {
  21. $(this).addClass('active')
  22. .siblings().removeClass('active');
  23. tabIndex = $(this).index();
  24. $('.hu-content >div').eq(tabIndex).show()
  25. .siblings().hide();
  26. loadDatas();
  27. });
  28. //柱形图
  29. //基于准备好的dom,初始化echarts实例
  30. myChart = echarts.init(document.getElementById('huData'));
  31. myChart.clear();
  32. myChart.showLoading();
  33. option = {
  34. color: ['#1ab394'],
  35. tooltip: {
  36. trigger: 'axis',
  37. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  38. type: 'line' // 默认为直线,可选为:'line' | 'shadow'
  39. }
  40. },
  41. toolbox: {
  42. show: true,
  43. },
  44. calculable: true,
  45. xAxis: [{
  46. type: 'category',
  47. name: '月份',
  48. splitLine: {
  49. show: false
  50. }, //去除网格线
  51. data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  52. axisTick: {
  53. alignWithLabel: true
  54. }
  55. }],
  56. yAxis: [{
  57. type: 'value',
  58. name: '通话量',
  59. nameLocation: 'end',
  60. splitLine: {
  61. show: false
  62. } //去除网格线
  63. }],
  64. series: [{
  65. name: '通话量',
  66. type: 'bar',
  67. barWidth: '30%', //图形宽度
  68. data: [],
  69. itemStyle: {
  70. normal: {
  71. label: {
  72. show: true,
  73. textStyle: {
  74. color: '#800080' //顶部数据颜色
  75. }
  76. }
  77. }
  78. },
  79. label: {
  80. normal: {
  81. show: true,
  82. position: 'top' //顶部数据显示位置
  83. }
  84. }
  85. }
  86. ]
  87. };
  88. // 使用刚指定的配置项和数据显示图表。
  89. myChart.setOption(option);
  90. loadDatas();
  91. //搜索事件
  92. $(".sear").click(function() {
  93. $(".huTable tbody").html('');
  94. date = $("#chooseTime").val();
  95. loadDatas();
  96. });
  97. })
  98. function getDataList() {
  99. layui.use('table', function() {
  100. var table = layui.table;
  101. //方法级渲染
  102. table.render({
  103. elem: '#t_callTotal',
  104. url: huayi.config.callcenter_url + "TotalCall/GetDataList",
  105. method: 'get', //如果无需自定义HTTP类型,可不加该参数
  106. skin: 'row', //line (行边框风格) row (列边框风格) nob (无边框风格)
  107. even: true, //开启隔行背景
  108. size: 'md', //sm,lg,md尺寸的表格
  109. where: {
  110. years: date,
  111. token: token
  112. }, //如果无需传递额外参数,可不加该参数
  113. //request: {}, //如果无需自定义请求参数,可不加该参数
  114. response: {
  115. statusName: 'state', //数据状态的字段名称,默认:code
  116. statusCode: 'success', //成功的状态码,默认:0
  117. msgName: 'message', //状态信息的字段名称,默认:msg
  118. //countName: 'total', //数据总数的字段名称,默认:count
  119. //dataName: 'rows', //数据列表的字段名称,默认:data
  120. }, //如果无需自定义数据响应名称,可不加该参数
  121. cols: [
  122. [{
  123. field: '月份',
  124. title: '月份',
  125. fixed: true,
  126. align: 'center',
  127. width: 200,
  128. }, {
  129. field: '日期',
  130. title: '日期',
  131. align: 'center',
  132. sort: true,
  133. //width: '30%',
  134. }, {
  135. field: '总数',
  136. title: '总数(次)',
  137. align: 'center',
  138. //width: '30%',
  139. }]
  140. ],
  141. //height: 'full-230'
  142. });
  143. });
  144. }
  145. //获取图形数据
  146. function tu() {
  147. $.ajax({
  148. type: "get",
  149. url: huayi.config.callcenter_url + "TotalCall/GetChartData",
  150. async: true,
  151. dataType: 'json',
  152. data: {
  153. token: token,
  154. years: date
  155. },
  156. success: function(data) {
  157. myChart.hideLoading();
  158. if(data.data) {
  159. myChart.setOption({
  160. series: [{
  161. data: data.data
  162. }]
  163. });
  164. }
  165. }
  166. });
  167. }
  168. //导出
  169. $('.export').click(function() {
  170. dcexcel(this);
  171. })
  172. function dcexcel(obj) {
  173. var url = huayi.config.callcenter_url + "TotalCall/ExptList?token=" + $.cookie("token");
  174. url += "&years=" + $("#chooseTime").val();
  175. obj.href = url;
  176. }
  177. function loadDatas() {
  178. if(tabIndex == 0) {
  179. tu(); //加载图形
  180. } else if(tabIndex == 1) {
  181. getDataList(); //加载表格
  182. }
  183. }