statistics.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'echarts', 'echarts-theme'], function ($, undefined, Backend, Table, Form, Echarts) {
  2. var Controller = {
  3. index: function () {
  4. var option1 = {
  5. title: {
  6. text: '订单统计',
  7. subtext: ''
  8. },
  9. tooltip: {
  10. trigger: 'axis',
  11. formatter: "{b}<br>{a0} : {c0} 个 <br>{a1} : {c1} 元"
  12. },
  13. legend: {
  14. data: ['订单额', '订单数']
  15. },
  16. toolbox: {
  17. show: true,
  18. feature: {
  19. dataView: {show: true, readOnly: false},
  20. magicType: {show: true, type: ['line', 'bar']},
  21. restore: {show: true},
  22. saveAsImage: {show: true}
  23. }
  24. },
  25. calculable: true,
  26. xAxis: [
  27. {
  28. type: 'category',
  29. data: Config.orderSaleCategory
  30. }
  31. ],
  32. yAxis: [
  33. {
  34. type: 'value'
  35. }
  36. ],
  37. series: [
  38. {
  39. name: '订单数',
  40. type: 'line',
  41. data: Config.orderSaleNums,
  42. markPoint: {
  43. data: [
  44. {type: 'max', name: '最大值'},
  45. {type: 'min', name: '最小值'}
  46. ]
  47. },
  48. markLine: {
  49. data: [
  50. {type: 'average', name: '平均值'}
  51. ]
  52. }
  53. },
  54. {
  55. name: '订单额',
  56. type: 'bar',
  57. smooth: true,
  58. symbol: 'none',
  59. data: Config.orderSaleAmount,
  60. markPoint: {
  61. data: [
  62. {type: 'max', name: '最大值'},
  63. {type: 'min', name: '最小值'}
  64. ]
  65. },
  66. markLine: {
  67. data: [
  68. {type: 'average', name: '平均值'}
  69. ]
  70. }
  71. }
  72. ]
  73. };
  74. var myChart1 = Echarts.init($('#echarts1')[0], 'walden');
  75. myChart1.setOption(option1);
  76. var option2 = {
  77. title: {
  78. text: '付费占比',
  79. subtext: '各模型付费占比',
  80. x: 'center'
  81. },
  82. tooltip: {
  83. trigger: 'item',
  84. formatter: "{a} <br/>{b} : {c} ({d}%)"
  85. },
  86. legend: {
  87. orient: 'vertical',
  88. left: 'left',
  89. data: Config.orderPercentCategory
  90. },
  91. series: [
  92. {
  93. name: '订单数',
  94. type: 'pie',
  95. center: ['50%', '50%'],
  96. data: Config.orderPercentNums,
  97. radius: [0, '30%'],
  98. label: {
  99. position: 'inner'
  100. },
  101. itemStyle: {
  102. emphasis: {
  103. shadowBlur: 10,
  104. shadowOffsetX: 0,
  105. shadowColor: 'rgba(0, 0, 0, 0.5)'
  106. }
  107. }
  108. },
  109. {
  110. name: '订单额',
  111. type: 'pie',
  112. radius: ['40%', '55%'],
  113. label2: {
  114. formatter: '{a|{a}}{abg|}\n{hr|}\n {b|{b}:}{c} 元 {per|{d}%} ',
  115. backgroundColor: '#eee',
  116. borderColor: '#aaa',
  117. borderWidth: 1,
  118. borderRadius: 4,
  119. rich: {
  120. a: {
  121. color: '#999',
  122. lineHeight: 22,
  123. align: 'center'
  124. },
  125. hr: {
  126. borderColor: '#aaa',
  127. width: '100%',
  128. borderWidth: 0.5,
  129. height: 0
  130. },
  131. b: {
  132. fontSize: 12,
  133. lineHeight: 33
  134. },
  135. per: {
  136. color: '#eee',
  137. backgroundColor: '#334455',
  138. padding: [2, 4],
  139. borderRadius: 2
  140. }
  141. }
  142. },
  143. data: Config.orderPercentAmount
  144. }
  145. ]
  146. };
  147. var myChart2 = Echarts.init($('#echarts2')[0], 'walden');
  148. myChart2.setOption(option2);
  149. $(window).on("resize", function () {
  150. myChart1.resize();
  151. myChart2.resize();
  152. });
  153. // 基于准备好的dom,初始化echarts实例
  154. var myChart3 = Echarts.init($('#echarts3')[0], 'walden');
  155. // 指定图表的配置项和数据
  156. var option3 = {
  157. title: {
  158. text: '',
  159. subtext: ''
  160. },
  161. tooltip: {
  162. trigger: 'axis'
  163. },
  164. legend: {},
  165. toolbox: {
  166. show: true,
  167. feature: {
  168. dataView: {show: true, readOnly: false},
  169. magicType: {show: true, type: ['line', 'bar']},
  170. restore: {show: true},
  171. saveAsImage: {show: true}
  172. }
  173. },
  174. calculable: true,
  175. xAxis: {
  176. type: 'category',
  177. boundaryGap: false,
  178. data: Config.orderSaleCategory
  179. },
  180. yAxis: {},
  181. grid: [{
  182. left: 'left',
  183. top: 'top',
  184. right: '10',
  185. bottom: 30
  186. }],
  187. series: [
  188. {
  189. name: "交易额",
  190. type: 'line',
  191. smooth: true,
  192. areaStyle: {
  193. normal: {}
  194. },
  195. lineStyle: {
  196. normal: {
  197. width: 1.5
  198. }
  199. },
  200. data: Config.orderSaleAmount
  201. }]
  202. };
  203. // 使用刚指定的配置项和数据显示图表。
  204. myChart3.setOption(option3);
  205. $(window).resize(function () {
  206. myChart3.resize();
  207. });
  208. if ($("#echarts4").length > 0) {
  209. // 基于准备好的dom,初始化echarts实例
  210. var myChart4 = Echarts.init($('#echarts4')[0], 'walden');
  211. // 指定图表的配置项和数据
  212. var option4 = {
  213. title: {
  214. text: '',
  215. subtext: ''
  216. },
  217. tooltip: {
  218. trigger: 'axis'
  219. },
  220. legend: {},
  221. toolbox: {
  222. show: true,
  223. feature: {
  224. dataView: {show: true, readOnly: false},
  225. magicType: {show: true, type: ['line', 'bar']},
  226. restore: {show: true},
  227. saveAsImage: {show: true}
  228. }
  229. },
  230. calculable: true,
  231. xAxis: {
  232. type: 'category',
  233. boundaryGap: false,
  234. data: Config.adminArchivesListCategory
  235. },
  236. yAxis: {},
  237. grid: [{
  238. left: 'left',
  239. top: 'top',
  240. right: '10',
  241. bottom: 30
  242. }],
  243. series: Config.adminArchivesListData
  244. };
  245. // 使用刚指定的配置项和数据显示图表。
  246. myChart4.setOption(option4);
  247. $(window).resize(function () {
  248. myChart4.resize();
  249. });
  250. }
  251. $(".datetimerange").data("callback", function (start, end) {
  252. var date = start.format(this.locale.format) + " - " + end.format(this.locale.format);
  253. $(this.element).val(date);
  254. var model_id = $(this.element).closest("form").find(".model_id").val();
  255. refresh_echart($(this.element).data("type"), date, model_id);
  256. });
  257. $(".model_id").on("change", function () {
  258. var input = $(this).closest("form").find(".datetimerange");
  259. var type = $(input).data("type");
  260. var date = $(input).val();
  261. var model_id = $(this).val();
  262. refresh_echart(type, date, model_id);
  263. });
  264. Form.api.bindevent($("#form1"));
  265. Form.api.bindevent($("#form2"));
  266. var si = {};
  267. var refresh_echart = function (type, date, model_id) {
  268. si[type] && clearTimeout(si[type]);
  269. si[type] = setTimeout(function () {
  270. Fast.api.ajax({
  271. url: 'cms/statistics/index',
  272. data: {date: date, type: type, model_id: model_id},
  273. loading: false
  274. }, function (data) {
  275. if (type == 'sale') {
  276. option1.xAxis.data = data.orderSaleCategory;
  277. option1.series[0].data = data.orderSaleNums;
  278. option1.series[1].data = data.orderSaleAmount;
  279. myChart1.clear();
  280. myChart1.setOption(option1, true);
  281. } else if (type == 'percent') {
  282. option2.legend.data = data.orderPercentCategory;
  283. option2.series[0].data = data.orderPercentNums;
  284. option2.series[1].data = data.orderPercentAmount;
  285. myChart2.clear();
  286. myChart2.setOption(option2, true);
  287. } else if (type == 'order') {
  288. option3.xAxis.data = data.category;
  289. option3.series[0].data = data.data;
  290. myChart3.clear();
  291. myChart3.setOption(option3, true);
  292. } else if (type == 'archives') {
  293. option4.xAxis.data = data.category;
  294. option4.series = data.data;
  295. myChart4.clear();
  296. myChart4.setOption(option4, true);
  297. }
  298. return false;
  299. });
  300. }, 50);
  301. };
  302. //点击按钮
  303. $(document).on("click", ".btn-filter", function () {
  304. var label = $(this).text();
  305. var obj = $(this).closest("form").find(".datetimerange").data("daterangepicker");
  306. var dates = obj.ranges[label];
  307. obj.startDate = dates[0];
  308. obj.endDate = dates[1];
  309. obj.clickApply();
  310. });
  311. //点击刷新
  312. $(document).on("click", "a.btn-refresh", function () {
  313. if ($(this).data("type")) {
  314. refresh_echart($(this).data("type"), "");
  315. } else {
  316. var input = $(this).closest("form").find(".datetimerange");
  317. var type = $(input).data("type");
  318. var date = $(input).val();
  319. var model_id = $(this).closest("form").find(".model_id").val();
  320. refresh_echart(type, date, model_id);
  321. }
  322. });
  323. //每隔一分钟定时刷新图表
  324. setInterval(function () {
  325. $(".btn-refresh").trigger("click");
  326. }, 60000);
  327. //选项卡切入事件
  328. $(document).on("click", "#resetecharts", function () {
  329. setTimeout(function () {
  330. $(window).trigger("resize");
  331. }, 50);
  332. });
  333. },
  334. add: function () {
  335. Controller.api.bindevent();
  336. },
  337. edit: function () {
  338. Controller.api.bindevent();
  339. },
  340. api: {
  341. bindevent: function () {
  342. Form.api.bindevent($("form[role=form]"));
  343. }
  344. }
  345. };
  346. return Controller;
  347. });