LineTrend.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div v-loading="loading">
  3. <div ref="echartDom" style="height: 200px"></div>
  4. </div>
  5. </template>
  6. <script setup>
  7. import * as echarts from "echarts";
  8. const props = defineProps({
  9. customerId: {
  10. type: String,
  11. },
  12. });
  13. const { proxy } = getCurrentInstance();
  14. const echartDom = ref(null);
  15. const loading = ref(false);
  16. let myChart = null;
  17. const option = reactive({
  18. data: {
  19. tooltip: {
  20. trigger: "axis",
  21. },
  22. grid: {
  23. left: "4%",
  24. right: "4%",
  25. bottom: "0%",
  26. top: "15px",
  27. containLabel: true,
  28. },
  29. xAxis: {
  30. type: "category",
  31. boundaryGap: false,
  32. data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  33. splitLine: {
  34. lineStyle: {
  35. type: "dashed",
  36. // 设置背景横线
  37. color: "#ccc",
  38. },
  39. },
  40. },
  41. yAxis: {
  42. type: "value",
  43. splitLine: {
  44. lineStyle: {
  45. type: "dashed",
  46. // 设置背景横线
  47. color: "#ccc",
  48. },
  49. },
  50. },
  51. series: [
  52. {
  53. data: [820, 932, 901, 934, 1290, 1330, 1320],
  54. type: "line",
  55. smooth: true,
  56. areaStyle: {
  57. color: "#FCE5CA",
  58. opacity: 0.4,
  59. },
  60. emphasis: {
  61. focus: "series",
  62. },
  63. itemStyle: {
  64. normal: {
  65. color: "#FF9315", //改变折线点的颜色
  66. lineStyle: {
  67. color: "#FF9315", //改变折线颜色
  68. },
  69. },
  70. },
  71. },
  72. {
  73. data: [210, 885, 644, 934, 1290, 1330, 1320],
  74. type: "line",
  75. smooth: true,
  76. areaStyle: {
  77. color: "#D9EDFF",
  78. opacity: 0.4,
  79. },
  80. emphasis: {
  81. focus: "series",
  82. },
  83. itemStyle: {
  84. normal: {
  85. color: "#0084FF", //改变折线点的颜色
  86. lineStyle: {
  87. color: "#0084FF", //改变折线颜色
  88. },
  89. },
  90. },
  91. },
  92. ],
  93. },
  94. });
  95. const getData = () => {
  96. loading.value = true;
  97. proxy
  98. .post("/saleQuotation/salesTrend", { id: props.customerId })
  99. .then((res) => {
  100. let months = res.contractList.map((x) => x.month);
  101. let dataOne = res.contractList.map((x) => x.contractAmount);
  102. let dataTwo = res.saleQuotationList.map((x) => x.saleAmount);
  103. option.data.xAxis.data = months;
  104. option.data.series[0].data = dataOne;
  105. option.data.series[1].data = dataTwo;
  106. myChart.setOption(option.data);
  107. setTimeout(() => {
  108. loading.value = false;
  109. }, 200);
  110. });
  111. };
  112. onMounted(() => {
  113. myChart = echarts.init(echartDom.value);
  114. if (props.customerId) {
  115. getData();
  116. }
  117. window.addEventListener("resize", () => {
  118. myChart.resize();
  119. });
  120. });
  121. </script>
  122. <style lang="scss" scoped>
  123. // .dom {
  124. // height: calc(100% - 50px);
  125. // }
  126. </style>