statistics.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'echarts', 'echarts-theme'], function ($, undefined, Backend, Table, Form, Echarts, undefined) {
  2. var Controller = {
  3. index: function () {
  4. // 基于准备好的dom,初始化echarts实例
  5. var myChart = Echarts.init(document.getElementById('echart'), 'walden');
  6. // 指定图表的配置项和数据
  7. var option = {
  8. title: {
  9. text: '',
  10. subtext: ''
  11. },
  12. tooltip: {
  13. trigger: 'axis'
  14. },
  15. legend: {},
  16. toolbox: {
  17. show: false,
  18. feature: {
  19. magicType: {show: true, type: ['stack', 'tiled']},
  20. saveAsImage: {show: true}
  21. }
  22. },
  23. xAxis: {
  24. type: 'category',
  25. boundaryGap: false,
  26. data: Config.statistics.columns
  27. },
  28. yAxis: {},
  29. grid: [{
  30. left: 'left',
  31. top: 'top',
  32. right: '10',
  33. bottom: 30
  34. }],
  35. series: [
  36. {
  37. name: __('Orders'),
  38. type: 'line',
  39. smooth: true,
  40. areaStyle: {
  41. normal: {}
  42. },
  43. lineStyle: {
  44. normal: {
  45. width: 1.5
  46. }
  47. },
  48. data: Config.statistics.data
  49. }]
  50. };
  51. // 使用刚指定的配置项和数据显示图表。
  52. myChart.setOption(option);
  53. $(window).resize(function () {
  54. myChart.resize();
  55. });
  56. Form.api.bindevent($("form[role=form]"));
  57. $(document).on("click", ".btn-filter", function () {
  58. var label = $(this).text();
  59. var obj = $(".datetimerange").data("daterangepicker");
  60. var dates = obj.ranges[label];
  61. obj.startDate = dates[0];
  62. obj.endDate = dates[1];
  63. obj.clickApply();
  64. });
  65. $(".datetimerange").on("blur", function () {
  66. Fast.api.ajax({
  67. url: 'ask/statistics/index',
  68. data: {date: $(this).val()}
  69. }, function (data) {
  70. myChart.setOption({
  71. xAxis: {
  72. data: data.columns
  73. },
  74. series: [{
  75. name: __('Orders'),
  76. data: data.data
  77. }]
  78. });
  79. $(".btn-amount span").text(data.amount);
  80. $.each(data, function (i, j) {
  81. if ($("#" + i).size() > 0) {
  82. $("#" + i).text(j);
  83. }
  84. });
  85. return false;
  86. });
  87. });
  88. $(document).on("click", ".btn-refresh", function () {
  89. $(".datetimerange").trigger("blur");
  90. });
  91. //每隔一分钟定时刷新图表
  92. setInterval(function () {
  93. $(".btn-refresh").trigger("click");
  94. }, 60000);
  95. }
  96. };
  97. return Controller;
  98. });