order.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. let ordersChart = null
  2. const ordersChartOption = {
  3. tooltip: {
  4. trigger: 'axis'
  5. },
  6. xAxis: {
  7. type: 'category',
  8. data: [],
  9. },
  10. grid: {
  11. right: 0,
  12. bottom: 25
  13. },
  14. yAxis: {
  15. type: 'value',
  16. splitLine: {
  17. show: true,
  18. lineStyle: {
  19. type: 'dashed',
  20. color: "#f0f3f6",
  21. opacity: 1
  22. }
  23. }
  24. },
  25. series: []
  26. }
  27. let transcationChart = null;
  28. const transcationChartOption = {
  29. title: {
  30. text: '',
  31. subtext: '注:下单转化率=支付人数/下单人数 ,支付转化率=支付人数/访客人数',
  32. top: 20,
  33. left: 'right',
  34. align: 'left'
  35. },
  36. tooltip: {
  37. trigger: 'axis',
  38. },
  39. grid: {
  40. top: 100,
  41. left: 50,
  42. right: 50
  43. },
  44. legend: {
  45. right: 0
  46. },
  47. xAxis: {
  48. type: 'category',
  49. data: [],
  50. },
  51. yAxis: {
  52. type: 'value',
  53. name: "转化率:%",
  54. splitLine: {
  55. show: true,
  56. lineStyle: {
  57. type: 'dashed',
  58. color: "#f0f3f6",
  59. opacity: 1
  60. }
  61. }
  62. },
  63. series: [{
  64. data: [],
  65. type: 'line'
  66. }]
  67. }
  68. let orderDistributedChart = null;
  69. const orderDistributedChartOption = {
  70. tooltip: {
  71. trigger: 'item'
  72. },
  73. geo: [
  74. {
  75. map: 'China',
  76. zoom: 1.2, //默认显示级别
  77. aspectScale: 0.9, //设置1:1的显示比例
  78. label: {
  79. show: false
  80. },
  81. select: { //设置选中样式
  82. itemStyle: {
  83. areaColor: "white" //自定义选中区域颜色
  84. }
  85. },
  86. emphasis: {
  87. label: {
  88. show: true
  89. }
  90. },
  91. itemStyle: {
  92. normal: {
  93. areaColor: '#e6e6e6',
  94. borderWidth: 0.7,
  95. borderColor: 'rgba(0,0,0,0.2)',
  96. }
  97. }
  98. }
  99. ],
  100. visualMap: {
  101. min: 0,
  102. max: 1000,
  103. text: ['高', '低'],
  104. realtime: false,
  105. calculable: true,
  106. inRange: {
  107. color: ['#ebfcf1', '#c6f7d7', '#90f0ad', '#5be986', '#33e36d']
  108. }
  109. },
  110. series: []
  111. };
  112. const mixin = {
  113. mounted() {
  114. this.getBaseData();
  115. },
  116. data() {
  117. return {
  118. order: {
  119. search: {
  120. timeRange: null,
  121. timeRangeType: "day"
  122. },
  123. statistics: []
  124. },
  125. orderDistributed: {
  126. search: {
  127. timeRange: null,
  128. timeRangeType: "day"
  129. },
  130. data: []
  131. },
  132. transcation: {
  133. search: {
  134. timeRange: null,
  135. timeRangeType: "day"
  136. },
  137. visitors: 0,
  138. orders: 0,
  139. pays: 0
  140. },
  141. overall: {
  142. cumulative_turnover: 0,
  143. pay_order_count: 0,
  144. member_count: 0,
  145. pay_member_count: 0,
  146. wait_pay: 0,
  147. wait_pay_price: 0,
  148. wait_send: 0,
  149. refund_success_price: 0
  150. },
  151. footPrintPluginTurnedon: false
  152. }
  153. },
  154. methods: {
  155. getBaseData() {
  156. this.fetchData(GetOrderDataUrl).then(res => {
  157. this.overall = res.cumulative_data
  158. this.footPrintPluginTurnedon = Boolean(res.browse_footprint);
  159. ordersChart = echarts.init(this.$refs['ordersChart']);
  160. ordersChart.setOption(ordersChartOption);
  161. this.getOrderStaisticsData();
  162. orderDistributedChart = echarts.init(this.$refs['orderDistributedChart']);
  163. this.$http.get(chinaJsonUrl).then(async res => {
  164. echarts.registerMap("China", res.data);
  165. orderDistributedChart.setOption(orderDistributedChartOption);
  166. this.getOrderDistributedData();
  167. });
  168. if (this.footPrintPluginTurnedon) {
  169. this.$nextTick(() => {
  170. transcationChart = echarts.init(this.$refs['transcationChart']);
  171. transcationChart.setOption(transcationChartOption);
  172. this.getOrderTranscationData();
  173. })
  174. }
  175. });
  176. },
  177. getOrderStaisticsData() {
  178. ordersChart.showLoading();
  179. this.fetchData(GetOrderChartDataUrl, {
  180. time_type: this.order.search.timeRangeType,
  181. time: this.order.search.timeRange
  182. }).then(data => {
  183. let statistics = [];
  184. const series = [];
  185. let legendData = [];
  186. data.forEach(item => {
  187. legendData.push(item.name);
  188. statistics.push({
  189. name: item.name,
  190. count: item.search,
  191. tip: item.tips,
  192. decimals: this.getDecimals(item.search)
  193. });
  194. series.push({
  195. name: item.name,
  196. type: "line",
  197. data: item.series,
  198. })
  199. });
  200. ordersChart.setOption({
  201. legend: {
  202. data: legendData,
  203. },
  204. xAxis: {
  205. data: data[0]['x_axis']
  206. },
  207. series
  208. });
  209. this.order.statistics = statistics;
  210. ordersChart.hideLoading();
  211. });
  212. },
  213. orderSearchTimeRange(timeRange) {
  214. this.order.search = timeRange;
  215. timeRange.timeRange = timeRange.timeRange ? timeRange.timeRange / 1000 : null;
  216. this.getOrderStaisticsData();
  217. },
  218. orderDistributedSearchTimeRange(timeRange) {
  219. this.orderDistributed.search = timeRange;
  220. timeRange.timeRange = timeRange.timeRange ? timeRange.timeRange / 1000 : null;
  221. this.getOrderDistributedData();
  222. },
  223. getOrderDistributedData() {
  224. orderDistributedChart.showLoading();
  225. this.fetchData(GetOrderDistributionUrl, {
  226. time_type: this.orderDistributed.search.timeRangeType,
  227. time: this.orderDistributed.search.timeRange
  228. }).then(res => {
  229. this.orderDistributed.data = res.distribution;
  230. let maxValue = res.area[0] ? res.area[0]['value'] : 1000;
  231. res.area.forEach(item => {
  232. if (item.value > maxValue) {
  233. maxValue = item.value;
  234. }
  235. })
  236. orderDistributedChart.setOption({
  237. visualMap: {
  238. max: maxValue,
  239. },
  240. series: [
  241. {
  242. name: '',
  243. type: 'map',
  244. geoIndex: 0,
  245. map: 'China',
  246. data: [
  247. ...res.area
  248. ],
  249. showLegendSymbol: true,
  250. },
  251. // {
  252. // name: '南海诸岛',
  253. // type: 'map',
  254. // geoIndex: 1,
  255. // zoom: 0.3,
  256. // top: 255,
  257. // left: 700,
  258. // map: 'ChinaNanhaiIslands',
  259. // data: [],
  260. // }
  261. ]
  262. })
  263. orderDistributedChart.hideLoading();
  264. });
  265. },
  266. transcationSearchTimeRange(timeRange) {
  267. this.transcation.search = timeRange;
  268. timeRange.timeRange = timeRange.timeRange ? timeRange.timeRange / 1000 : null;
  269. this.getOrderTranscationData();
  270. },
  271. getOrderTranscationData() {
  272. transcationChart.showLoading();
  273. this.fetchData(GetTranscationDataUrl, {
  274. time_type: this.transcation.search.timeRangeType,
  275. time: this.transcation.search.timeRange
  276. }).then(res => {
  277. this.transcation.orders = res.order_count;
  278. this.transcation.visitors = res.cookie_count;
  279. this.transcation.pays = res.pay_order_count;
  280. let chart = res.chart;
  281. let legend = [];
  282. let XAxis = chart[0]['x_axis'];
  283. let series = [];
  284. chart.forEach(item => {
  285. series.push({
  286. name: item['name'],
  287. type: 'line',
  288. data: item['series']
  289. });
  290. legend.push(item['name']);
  291. })
  292. transcationChart.setOption({
  293. legend: {
  294. data: legend
  295. },
  296. xAxis: {
  297. data: XAxis
  298. },
  299. series
  300. })
  301. transcationChart.hideLoading();
  302. });
  303. }
  304. }
  305. }