orderEchart.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <Card :title="title||'订单数据统计'">
  3. <template #extra>
  4. <div class="condition">
  5. <div class="selct" style="display: inline-block;">
  6. <span style="margin-right:15px">颗粒度</span>
  7. <Select
  8. v-model:value="value"
  9. style="width: 100px;margin-right:30px"
  10. placeholder="请选择颗粒度"
  11. :options="options"
  12. @change="handleChange"
  13. ></Select>
  14. </div>
  15. <a-button type="primary" @click="handleExport">导出</a-button>
  16. </div>
  17. </template>
  18. <div ref="chartRef" :style="{ height, width }"></div>
  19. </Card>
  20. </template>
  21. <script lang="ts" setup>
  22. import { basicProps } from './props';
  23. import type { SelectProps } from 'ant-design-vue';
  24. import { Card, DatePicker, Select } from 'ant-design-vue';
  25. import { ref, Ref, watch, defineEmits } from 'vue';
  26. import { useECharts } from '/@/hooks/web/useECharts';
  27. import { exportElsxFile, } from '/@/utils/file/download';
  28. const props = defineProps({
  29. loading: Boolean,
  30. ...basicProps,
  31. });
  32. const value = ref('2');
  33. const options = ref<SelectProps['options']>([
  34. {
  35. value: '0',
  36. label: '日',
  37. },
  38. {
  39. value: '1',
  40. label: '周',
  41. },
  42. {
  43. value: '2',
  44. label: '月',
  45. },
  46. ]);
  47. const emit = defineEmits(["alertSome"])
  48. const kjList = ref<number[]>([]);
  49. const kkList = ref<number[]>([]);
  50. const ssList = ref<number[]>([]);
  51. const ssobjList = ref<number[]>([]);
  52. const yixStringData = ref<string[]>([]);
  53. const echartTypr = ref('line')
  54. const nameList = ref<string[]>(['看见场景','看看场景','深时场景','深时obj']);
  55. const maxSize = ref(0);
  56. const chartRef = ref<HTMLDivElement | null>(null);
  57. const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>)
  58. function handleChange(val){
  59. emit('change',{type:'scene',value:val})
  60. }
  61. function handleExport(){
  62. let fields = {
  63. 'time':'日期',
  64. 'kj':'看见场景',
  65. 'kk':'看看场景',
  66. 'ss':'深时场景',
  67. 'dy':'深时obj',
  68. }
  69. let data = yixStringData.value.map((ele,index) => {
  70. return {
  71. 'time':ele,
  72. 'kj':kjList.value && kjList.value[index] || 0,
  73. 'kk':kkList.value && kkList.value[index] || 0,
  74. 'ss':ssList.value && ssList.value[index] || 0,
  75. 'dy':ssobjList.value && ssobjList.value[index] || 0,
  76. }
  77. })
  78. exportElsxFile(data,fields,'场景趋势')
  79. }
  80. function handlesetOptions() {
  81. setOptions({
  82. tooltip: {
  83. trigger: 'axis',
  84. axisPointer: {
  85. lineStyle: {
  86. width: 1,
  87. color: '#019680',
  88. },
  89. },
  90. },
  91. legend: {
  92. orient: 'horizontal',
  93. bottom: 0,
  94. },
  95. // grid: { left: '2%', right: '2%', top: '10%', bottom: '10%', containLabel: true },
  96. xAxis: {
  97. type: 'category',
  98. // data: [...new Array(30)].map((_item, index) => `${index + 1}日`),
  99. data: yixStringData.value,
  100. },
  101. yAxis: {
  102. type: 'value',
  103. // max: maxSize.value,
  104. splitNumber: 4,
  105. },
  106. series: [
  107. {
  108. data: kjList.value,
  109. type: echartTypr.value,
  110. itemStyle: { color: '#38a0ff' },
  111. barMaxWidth: 80,
  112. name: nameList.value[0],
  113. },
  114. {
  115. data: kkList.value,
  116. type: echartTypr.value,
  117. itemStyle: { color: '#4cca73' },
  118. barMaxWidth: 80,
  119. name: nameList.value[1],
  120. },
  121. {
  122. data: ssList.value,
  123. type: echartTypr.value,
  124. itemStyle: { color: '#FDD56A' },
  125. barMaxWidth: 80,
  126. name: nameList.value[2],
  127. },
  128. {
  129. data: ssobjList.value,
  130. type: echartTypr.value,
  131. itemStyle: { color: '#d58b55' },
  132. barMaxWidth: 80,
  133. name: nameList.value[3],
  134. },
  135. ],
  136. });
  137. }
  138. watch(
  139. () => props.echartData,
  140. (echartData) => {
  141. kjList.value = echartData.kjList ||[]
  142. kkList.value = echartData.kkList ||[]
  143. ssList.value = echartData.ssList ||[]
  144. ssobjList.value = echartData.ssobjList ||[]
  145. yixStringData.value = echartData.xdata ||[]
  146. if(echartData.nameList){
  147. nameList.value = echartData.nameList
  148. }
  149. if(echartData.echartTypr){
  150. echartTypr.value = echartData.echartTypr
  151. }
  152. // const maxNumber = Math.max(...echartData.downOrder.concat(echartData.incrementOrder));
  153. // const pow = Math.pow(10, maxNumber.toString().length - 1);
  154. // maxSize.value = maxNumber > 10 ? Math.floor(maxNumber / 10) * 10 + pow * 2 : 10;
  155. handlesetOptions();
  156. },
  157. {
  158. immediate: true,
  159. deep: true,
  160. },
  161. );
  162. </script>