report.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'echarts', 'echarts-theme'], function ($, undefined, Backend, Table, Form, Echarts, undefined) {
  2. var areaObj = {};
  3. var Controller = {
  4. common: function (obj) {
  5. $(window).resize(function () {
  6. for (let i in obj) {
  7. obj[i].chart.resize();
  8. }
  9. });
  10. //点击刷新
  11. $(document).on("click", "a.btn-refresh", function () {
  12. let val = $(this).data('chart');
  13. obj[val].chart.resize();
  14. obj[val].refresh();
  15. });
  16. //每隔60s定时刷新图表
  17. setInterval(function () {
  18. $(".btn-refresh").trigger("click");
  19. }, 60000);
  20. //点击按钮
  21. $(document).on("click", ".btn-filter", function () {
  22. var label = $(this).text();
  23. var obj = $(this).closest("form").find(".datetimerange").data("daterangepicker");
  24. var dates = obj.ranges[label];
  25. obj.startDate = dates[0];
  26. obj.endDate = dates[1];
  27. obj.clickApply();
  28. });
  29. //选项卡切入事件
  30. $(document).on("click", "#resetecharts", function () {
  31. setTimeout(function () {
  32. $(window).trigger("resize");
  33. }, 50);
  34. });
  35. },
  36. index: function () {
  37. let obj = {}
  38. obj.chart1 = this.api.index.myChart1();
  39. obj.chart2 = this.api.index.myChart2();
  40. obj.chart4 = this.api.index.myChart4();
  41. this.common(obj);
  42. Form.api.bindevent($("#form1"));
  43. Form.api.bindevent($("#form2"));
  44. Form.api.bindevent($("#form4"));
  45. },
  46. areas: function () {
  47. areaObj.chart1 = this.api.areas.myChart1();
  48. areaObj.chart2 = this.api.areas.myChart2();
  49. areaObj.chart1.refresh();
  50. this.common(areaObj);
  51. //绑定事件
  52. Form.api.bindevent($("#form1"));
  53. Form.api.bindevent($("#form2"));
  54. },
  55. api: {
  56. bindevent: function () {
  57. Form.api.bindevent($("form[role=form]"));
  58. },
  59. index: {
  60. myChart1: function () {
  61. // 基于准备好的dom,初始化echarts实例
  62. let myChart = Echarts.init($('#echarts1')[0], 'walden');
  63. // 指定图表的配置项和数据
  64. let option = {
  65. title: {
  66. text: '订单金额趋势',
  67. subtext: ''
  68. },
  69. tooltip: {
  70. trigger: 'axis'
  71. },
  72. legend: {
  73. data: ['订单金额', '退款金额']
  74. },
  75. toolbox: {
  76. show: true,
  77. feature: {
  78. dataView: {
  79. show: true,
  80. readOnly: false
  81. },
  82. magicType: {
  83. show: true,
  84. type: ['line', 'bar']
  85. },
  86. restore: {
  87. show: true
  88. },
  89. saveAsImage: {
  90. show: true
  91. }
  92. }
  93. },
  94. calculable: true,
  95. xAxis: {
  96. type: 'category',
  97. boundaryGap: false,
  98. data: Config.orderSaleCategory
  99. },
  100. yAxis: {},
  101. grid: {
  102. left: '3%',
  103. right: '4%',
  104. bottom: '3%',
  105. containLabel: true
  106. },
  107. series: [{
  108. name: "订单金额",
  109. type: 'line',
  110. smooth: true,
  111. areaStyle: {
  112. normal: {}
  113. },
  114. lineStyle: {
  115. normal: {
  116. width: 1.5
  117. }
  118. },
  119. data: Config.orderSaleAmount
  120. }, {
  121. name: '退款金额',
  122. type: 'line',
  123. data: Config.afterSaleAmount,
  124. markPoint: {
  125. data: [{
  126. type: 'max',
  127. name: '最大值'
  128. },
  129. {
  130. type: 'min',
  131. name: '最小值'
  132. }
  133. ]
  134. },
  135. markLine: {
  136. data: [{
  137. type: 'average',
  138. name: '平均值'
  139. }]
  140. }
  141. }]
  142. };
  143. // 使用刚指定的配置项和数据显示图表。
  144. myChart.setOption(option);
  145. var date = '';
  146. $("#form1 .datetimerange").data("callback", function (start, end) {
  147. date = start.format(this.locale.format) + " - " + end.format(this.locale.format);
  148. $(this.element).val(date);
  149. refresh();
  150. });
  151. //点击按钮
  152. $(document).on("click", ".btn-type", function () {
  153. refresh();
  154. });
  155. var si = null;
  156. function refresh() {
  157. si && clearTimeout(si);
  158. si = setTimeout(function () {
  159. Fast.api.ajax({
  160. url: 'shop/report/index',
  161. data: {
  162. date: date
  163. },
  164. loading: false
  165. }, function (res) {
  166. option.xAxis.data = res.orderSaleCategory;
  167. option.series[0].data = res.orderSaleAmount;
  168. option.series[1].data = res.afterSaleAmount;
  169. myChart.clear();
  170. myChart.setOption(option, true);
  171. if (res.totalOrderAmount != undefined) {
  172. $('#totalOrderAmount').html(res.totalOrderAmount)
  173. }
  174. if (res.todayOrderAmount != undefined) {
  175. $('#todayOrderAmount').html(res.todayOrderAmount)
  176. }
  177. if (res.totalProfitAmount != undefined) {
  178. $('#totalProfitAmount').html(res.totalProfitAmount)
  179. }
  180. if (res.totalRefundAmount != undefined) {
  181. $('#totalRefundAmount').html(res.totalRefundAmount)
  182. }
  183. if (res.todayRefundAmount != undefined) {
  184. $('#todayRefundAmount').html(res.todayRefundAmount)
  185. }
  186. if (res.yesterdayRefundAmount != undefined) {
  187. $('#yesterdayRefundAmount').html(res.yesterdayRefundAmount)
  188. }
  189. if (res.todayOrderRatio != undefined) {
  190. let dom = $('#todayOrderRatio');
  191. dom.html((res.todayOrderRatio > 0 ? '+' : '') + res.todayOrderRatio + '%');
  192. dom.attr('title', '昨天:' + res.yesterdayOrderAmount);
  193. if (res.todayOrderRatio >= 0) {
  194. dom.removeClass('text-danger').addClass('text-success');
  195. } else {
  196. dom.removeClass('text-success').addClass('text-danger');
  197. }
  198. }
  199. return false;
  200. });
  201. }, 50);
  202. }
  203. return {
  204. chart: myChart,
  205. refresh: refresh
  206. };
  207. },
  208. myChart2: function () {
  209. // 基于准备好的dom,初始化echarts实例
  210. let myChart = Echarts.init($('#echarts2')[0], 'walden');
  211. // 指定图表的配置项和数据
  212. let option = {
  213. title: {
  214. text: '订单数量趋势',
  215. subtext: ''
  216. },
  217. tooltip: {
  218. trigger: 'axis'
  219. },
  220. legend: {
  221. data: ['订单数量', '退款数量']
  222. },
  223. toolbox: {
  224. show: true,
  225. feature: {
  226. dataView: {
  227. show: true,
  228. readOnly: false
  229. },
  230. magicType: {
  231. show: true,
  232. type: ['line', 'bar']
  233. },
  234. restore: {
  235. show: true
  236. },
  237. saveAsImage: {
  238. show: true
  239. }
  240. }
  241. },
  242. calculable: true,
  243. xAxis: {
  244. type: 'category',
  245. boundaryGap: false,
  246. data: Config.afterSaleCategory
  247. },
  248. yAxis: {},
  249. grid: {
  250. left: '3%',
  251. right: '4%',
  252. bottom: '3%',
  253. containLabel: true
  254. },
  255. series: [{
  256. name: "订单数量",
  257. type: 'line',
  258. smooth: true,
  259. areaStyle: {
  260. normal: {}
  261. },
  262. lineStyle: {
  263. normal: {
  264. width: 1.5
  265. }
  266. },
  267. data: Config.orderSaleNums
  268. }, {
  269. name: '退款数量',
  270. type: 'line',
  271. data: Config.afterSaleNums,
  272. markPoint: {
  273. data: [{
  274. type: 'max',
  275. name: '最大值'
  276. },
  277. {
  278. type: 'min',
  279. name: '最小值'
  280. }
  281. ]
  282. },
  283. markLine: {
  284. data: [{
  285. type: 'average',
  286. name: '平均值'
  287. }]
  288. }
  289. }]
  290. };
  291. // 使用刚指定的配置项和数据显示图表。
  292. myChart.setOption(option);
  293. var date = '';
  294. $("#form2 .datetimerange").data("callback", function (start, end) {
  295. date = start.format(this.locale.format) + " - " + end.format(this.locale.format);
  296. $(this.element).val(date);
  297. refresh();
  298. });
  299. //点击按钮
  300. $(document).on("click", ".btn-type", function () {
  301. refresh();
  302. });
  303. var si = null;
  304. function refresh() {
  305. si && clearTimeout(si);
  306. si = setTimeout(function () {
  307. Fast.api.ajax({
  308. url: 'shop/report/index',
  309. data: {
  310. date: date
  311. },
  312. loading: false
  313. }, function (res) {
  314. option.xAxis.data = res.afterSaleCategory;
  315. option.series[0].data = res.orderSaleNums;
  316. option.series[1].data = res.afterSaleNums;
  317. myChart.clear();
  318. myChart.setOption(option, true);
  319. return false;
  320. });
  321. }, 50);
  322. }
  323. return {
  324. chart: myChart,
  325. refresh: refresh
  326. };
  327. },
  328. myChart3: function () {
  329. return;
  330. },
  331. myChart4: function () {
  332. // 基于准备好的dom,初始化echarts实例
  333. let myChart = Echarts.init($('#echarts4')[0], 'walden');
  334. let option = {
  335. title: {
  336. text: '销售商品分类占比',
  337. // subtext: '',
  338. left: 'left'
  339. },
  340. tooltip: {
  341. trigger: 'item',
  342. formatter: function (row) {
  343. let {
  344. data
  345. } = row;
  346. let name = (data && data.name) || '';
  347. let value = (data && data.value) || 0;
  348. return `${name}:${value}%`
  349. }
  350. },
  351. legend: {
  352. type: 'scroll',
  353. orient: 'vertical',
  354. right: 10,
  355. top: 20,
  356. bottom: 20,
  357. data: Config.legendData,
  358. },
  359. series: [{
  360. name: '名称',
  361. type: 'pie',
  362. radius: '75%',
  363. center: ['40%', '50%'],
  364. data: Config.seriesData,
  365. label: {
  366. formatter: function (row) {
  367. let {
  368. data
  369. } = row;
  370. let name = (data && data.name) || '';
  371. let value = (data && data.value) || 0;
  372. return `${name} : (${value}%)`
  373. }
  374. },
  375. emphasis: {
  376. itemStyle: {
  377. shadowBlur: 10,
  378. shadowOffsetX: 0,
  379. shadowColor: 'rgba(0, 0, 0, 0.5)'
  380. }
  381. }
  382. }]
  383. };
  384. myChart.setOption(option, true);
  385. var date = '';
  386. $("#form4 .datetimerange").data("callback", function (start, end) {
  387. date = start.format(this.locale.format) + " - " + end.format(this.locale.format);
  388. $(this.element).val(date);
  389. refresh();
  390. });
  391. //点击按钮
  392. $(document).on("click", ".btn-type", function () {
  393. refresh();
  394. });
  395. var si = null;
  396. function refresh() {
  397. si && clearTimeout(si);
  398. si = setTimeout(function () {
  399. Fast.api.ajax({
  400. url: 'shop/report/index',
  401. data: {
  402. date: date
  403. },
  404. loading: false
  405. }, function (res) {
  406. option.series[0].data = res.seriesData;
  407. option.legend.data = res.legendData;
  408. myChart.clear();
  409. myChart.setOption(option, true);
  410. return false;
  411. });
  412. }, 50);
  413. }
  414. return {
  415. chart: myChart,
  416. refresh: refresh
  417. };
  418. }
  419. },
  420. areas: {
  421. myChart1: function () {
  422. let isFirst = false;
  423. // 基于准备好的dom,初始化echarts实例
  424. let myChart = Echarts.init($('#echarts1')[0], 'walden');
  425. var colors = ['#5470C6', '#91CC75', '#EE6666', '#18bc9c'];
  426. // 指定图表的配置项和数据
  427. let option = {
  428. title: {
  429. text: '',
  430. subtext: ''
  431. },
  432. color: colors,
  433. tooltip: {
  434. trigger: 'axis',
  435. axisPointer: {
  436. type: 'cross'
  437. }
  438. },
  439. grid: {
  440. left: '15',
  441. right: '4%',
  442. bottom: '3%',
  443. top: '11%',
  444. containLabel: true,
  445. y2: 120
  446. },
  447. toolbox: {
  448. show: true,
  449. feature: {
  450. dataView: {
  451. show: true,
  452. readOnly: false
  453. },
  454. magicType: {
  455. show: true,
  456. type: ['line', 'bar']
  457. },
  458. restore: {
  459. show: true
  460. },
  461. saveAsImage: {
  462. show: true
  463. }
  464. }
  465. },
  466. legend: {
  467. data: ['订单数量', '商品数量', '订单金额', '订单占比']
  468. },
  469. xAxis: [{
  470. type: 'category',
  471. axisTick: {
  472. alignWithLabel: true
  473. },
  474. axisLabel: {
  475. interval: 0,
  476. rotate: -30, //倾斜度 -90 至 90 默认为0
  477. // margin:2,
  478. // textStyle: {
  479. // color: '#7c8893',
  480. // fontSize: 12
  481. // },
  482. // formatter: function(value) {
  483. // return value.split("").join("\n");
  484. // }
  485. },
  486. offset: 10,
  487. triggerEvent:true,
  488. data: []
  489. }],
  490. yAxis: [{
  491. type: 'value',
  492. name: '订单数量',
  493. min: 0,
  494. max: 50,
  495. position: 'right',
  496. axisLine: {
  497. show: true,
  498. lineStyle: {
  499. color: colors[0]
  500. }
  501. },
  502. axisLabel: {
  503. formatter: '{value} 个'
  504. }
  505. },
  506. {
  507. type: 'value',
  508. name: '商品数量',
  509. min: 0,
  510. max: 50,
  511. position: 'right',
  512. offset: 80,
  513. axisLine: {
  514. show: true,
  515. lineStyle: {
  516. color: colors[1]
  517. }
  518. },
  519. axisLabel: {
  520. formatter: '{value} 件'
  521. }
  522. },
  523. {
  524. type: 'value',
  525. name: '订单金额',
  526. min: 0,
  527. max: 2500,
  528. position: 'left',
  529. axisLine: {
  530. show: true,
  531. lineStyle: {
  532. color: colors[2]
  533. }
  534. },
  535. axisLabel: {
  536. formatter: '{value} 元'
  537. }
  538. },
  539. {
  540. type: 'value',
  541. name: '订单占比',
  542. min: 0,
  543. max: 100,
  544. position: 'left',
  545. offset: 60,
  546. axisLine: {
  547. show: true,
  548. lineStyle: {
  549. color: colors[3]
  550. }
  551. },
  552. axisLabel: {
  553. formatter: '{value} %'
  554. }
  555. }
  556. ],
  557. series: [{
  558. name: '订单数量',
  559. type: 'bar',
  560. data: [],
  561. markPoint: {
  562. data: [{
  563. type: 'max',
  564. name: '最大值'
  565. },
  566. {
  567. type: 'min',
  568. name: '最小值'
  569. }
  570. ]
  571. }
  572. },
  573. {
  574. name: '商品数量',
  575. type: 'bar',
  576. yAxisIndex: 1,
  577. data: [],
  578. markPoint: {
  579. data: [{
  580. type: 'max',
  581. name: '最大值'
  582. },
  583. {
  584. type: 'min',
  585. name: '最小值'
  586. }
  587. ]
  588. }
  589. },
  590. {
  591. name: '订单金额',
  592. type: 'line',
  593. yAxisIndex: 2,
  594. data: [],
  595. markLine: {
  596. data: [{
  597. type: 'average',
  598. name: '平均值'
  599. }]
  600. },
  601. label: {
  602. show: true
  603. },
  604. },
  605. {
  606. name: '订单占比',
  607. type: 'line',
  608. yAxisIndex: 3,
  609. data: [],
  610. markLine: {
  611. data: [{
  612. type: 'average',
  613. name: '平均值'
  614. }]
  615. },
  616. label: {
  617. show: true
  618. },
  619. }
  620. ]
  621. };
  622. // 使用刚指定的配置项和数据显示图表。
  623. myChart.setOption(option);
  624. myChart.on('click', 'xAxis', function (res) {
  625. areaObj.chart2.refresh(res.value);
  626. });
  627. myChart.on('click', 'series', function (res) {
  628. if(!['最大值','最小值'].includes(res.name)){
  629. areaObj.chart2.refresh(res.name);
  630. }
  631. });
  632. var date = '';
  633. $("#form1 .datetimerange").data("callback", function (start, end) {
  634. date = start.format(this.locale.format) + " - " + end.format(this.locale.format);
  635. $(this.element).val(date);
  636. refresh();
  637. });
  638. //点击按钮
  639. $(document).on("click", ".btn-type", function () {
  640. refresh();
  641. });
  642. var si = null;
  643. function refresh() {
  644. si && clearTimeout(si);
  645. si = setTimeout(function () {
  646. Fast.api.ajax({
  647. url: 'shop/report/areas',
  648. data: {
  649. date: date,
  650. id: Config.area
  651. },
  652. loading: false
  653. }, function (res) {
  654. if(res.name){
  655. option.title.text = res.name;
  656. }
  657. option.xAxis[0].data = res.xAxis;
  658. option.series[0].data = res.orderNums;
  659. option.series[1].data = res.goodsNums;
  660. let max_nums = Math.max.apply(null, res.goodsNums);
  661. option.yAxis[0].max = option.yAxis[1].max = parseInt(max_nums) + 10;
  662. option.series[2].data = res.orderMoney;
  663. let max_money = Math.max.apply(null, res.orderMoney);
  664. option.yAxis[2].max = parseInt(max_money) + 100;
  665. if (!res.is_oblique) {
  666. option.xAxis[0].axisLabel.rotate = 0;
  667. }
  668. option.series[3].data = res.rate;
  669. myChart.clear();
  670. console.log(option)
  671. myChart.setOption(option, true);
  672. if(!isFirst){
  673. //渲染区域
  674. isFirst = true;
  675. res.xAxis.length && res.xAxis[0] && areaObj.chart2.refresh(res.xAxis[0])
  676. }
  677. return false;
  678. });
  679. }, 50);
  680. }
  681. return {
  682. chart: myChart,
  683. refresh: refresh
  684. };
  685. },
  686. myChart2: function () {
  687. // 基于准备好的dom,初始化echarts实例
  688. let myChart = Echarts.init($('#echarts2')[0], 'walden');
  689. // 指定图表的配置项和数据
  690. var colors = ['#5470C6', '#91CC75', '#EE6666', '#18bc9c'];
  691. var date = '',area_name='';
  692. // 指定图表的配置项和数据
  693. let option = {
  694. title: {
  695. text:'区级统计',
  696. subtext: ''
  697. },
  698. color: colors,
  699. tooltip: {
  700. trigger: 'axis',
  701. axisPointer: {
  702. type: 'cross'
  703. }
  704. },
  705. grid: {
  706. left: '15',
  707. right: '4%',
  708. bottom: '3%',
  709. top: '11%',
  710. containLabel: true,
  711. y2: 120
  712. },
  713. toolbox: {
  714. show: true,
  715. feature: {
  716. dataView: {
  717. show: true,
  718. readOnly: false
  719. },
  720. magicType: {
  721. show: true,
  722. type: ['line', 'bar']
  723. },
  724. restore: {
  725. show: true
  726. },
  727. saveAsImage: {
  728. show: true
  729. }
  730. }
  731. },
  732. legend: {
  733. data: ['订单数量', '商品数量', '订单金额', '订单占比']
  734. },
  735. xAxis: [{
  736. type: 'category',
  737. axisTick: {
  738. alignWithLabel: true
  739. },
  740. axisLabel: {
  741. interval: 0,
  742. rotate: -30, //倾斜度 -90 至 90 默认为0
  743. // margin:2,
  744. // textStyle: {
  745. // color: '#7c8893',
  746. // fontSize: 12
  747. // },
  748. // formatter: function(value) {
  749. // return value.split("").join("\n");
  750. // }
  751. },
  752. offset: 10,
  753. data: []
  754. }],
  755. yAxis: [{
  756. type: 'value',
  757. name: '订单数量',
  758. min: 0,
  759. max: 50,
  760. position: 'right',
  761. axisLine: {
  762. show: true,
  763. lineStyle: {
  764. color: colors[0]
  765. }
  766. },
  767. axisLabel: {
  768. formatter: '{value} 个'
  769. }
  770. },
  771. {
  772. type: 'value',
  773. name: '商品数量',
  774. min: 0,
  775. max: 50,
  776. position: 'right',
  777. offset: 80,
  778. axisLine: {
  779. show: true,
  780. lineStyle: {
  781. color: colors[1]
  782. }
  783. },
  784. axisLabel: {
  785. formatter: '{value} 件'
  786. }
  787. },
  788. {
  789. type: 'value',
  790. name: '订单金额',
  791. min: 0,
  792. max: 2500,
  793. position: 'left',
  794. axisLine: {
  795. show: true,
  796. lineStyle: {
  797. color: colors[2]
  798. }
  799. },
  800. axisLabel: {
  801. formatter: '{value} 元'
  802. }
  803. },
  804. {
  805. type: 'value',
  806. name: '订单占比',
  807. min: 0,
  808. max: 100,
  809. position: 'left',
  810. offset: 60,
  811. axisLine: {
  812. show: true,
  813. lineStyle: {
  814. color: colors[3]
  815. }
  816. },
  817. axisLabel: {
  818. formatter: '{value} %'
  819. }
  820. }
  821. ],
  822. series: [{
  823. name: '订单数量',
  824. type: 'bar',
  825. data: [],
  826. markPoint: {
  827. data: [{
  828. type: 'max',
  829. name: '最大值'
  830. },
  831. {
  832. type: 'min',
  833. name: '最小值'
  834. }
  835. ]
  836. }
  837. },
  838. {
  839. name: '商品数量',
  840. type: 'bar',
  841. yAxisIndex: 1,
  842. data: [],
  843. markPoint: {
  844. data: [{
  845. type: 'max',
  846. name: '最大值'
  847. },
  848. {
  849. type: 'min',
  850. name: '最小值'
  851. }
  852. ]
  853. }
  854. },
  855. {
  856. name: '订单金额',
  857. type: 'line',
  858. yAxisIndex: 2,
  859. data: [],
  860. markLine: {
  861. data: [{
  862. type: 'average',
  863. name: '平均值'
  864. }]
  865. },
  866. label: {
  867. show: true
  868. },
  869. },
  870. {
  871. name: '订单占比',
  872. type: 'line',
  873. yAxisIndex: 3,
  874. data: [],
  875. markLine: {
  876. data: [{
  877. type: 'average',
  878. name: '平均值'
  879. }]
  880. },
  881. label: {
  882. show: true
  883. },
  884. }
  885. ]
  886. };
  887. // 使用刚指定的配置项和数据显示图表。
  888. myChart.setOption(option);
  889. $("#form2 .datetimerange").data("callback", function (start, end) {
  890. date = start.format(this.locale.format) + " - " + end.format(this.locale.format);
  891. $(this.element).val(date);
  892. refresh();
  893. });
  894. //点击按钮
  895. $(document).on("click", ".btn-type", function () {
  896. refresh();
  897. });
  898. var si = null;
  899. function refresh(name='') {
  900. if(name){
  901. area_name = name;
  902. }
  903. si && clearTimeout(si);
  904. si = setTimeout(function () {
  905. Fast.api.ajax({
  906. url: 'shop/report/areas',
  907. data: {
  908. date: date,
  909. name: area_name
  910. },
  911. loading: false
  912. }, function (res) {
  913. if(res.name){
  914. option.title.text = res.name;
  915. }
  916. option.xAxis[0].data = res.xAxis;
  917. option.series[0].data = res.orderNums;
  918. option.series[1].data = res.goodsNums;
  919. //
  920. let max_nums = Math.max.apply(null, res.goodsNums);
  921. option.yAxis[0].max = option.yAxis[1].max = parseInt(max_nums) + 10;
  922. option.series[2].data = res.orderMoney;
  923. let max_money = Math.max.apply(null, res.orderMoney);
  924. option.yAxis[2].max = parseInt(max_money) + 100;
  925. option.xAxis[0].axisLabel.rotate = res.is_oblique && res.orderMoney.length>6?-30:0;
  926. console.log(option.xAxis[0].axisLabel.rotate)
  927. option.series[3].data = res.rate;
  928. myChart.clear();
  929. console.log(option)
  930. myChart.setOption(option, true);
  931. return false;
  932. });
  933. }, 50);
  934. }
  935. return {
  936. chart: myChart,
  937. refresh: refresh
  938. };
  939. },
  940. }
  941. }
  942. };
  943. return Controller;
  944. });