businessEcharts.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div class="businessOpportunityStage box mt-4">
  3. <div class="box-title">
  4. <div class="box-title-left text-size-in">{{ businessLabel }}阶段</div>
  5. <div class="box-title-right text-size-small" @click="showPopUpLayer()">
  6. {{ scopeText }}/{{ dateText }}
  7. <van-icon name="play" class="ml-2 rotate-90" color="#747474" />
  8. </div>
  9. </div>
  10. <div class="content w-full overflow-hidden transitionEffect"
  11. :style="`height: ${expandAndCollapse ? usePxToVwView(echartsHeight) : '0'}`">
  12. <ReRcharts :option="echartsOption" />
  13. </div>
  14. <div class="w-full flex justify-center mt-2" @click="expandAndCollapseSwitch()">
  15. <van-icon name="arrow-up" color="#AFAFAF" :class="`${!expandAndCollapse && 'rotate-180'} transitionEffect`" />
  16. </div>
  17. <van-popup v-model:show="filterCriteriaPopUpLayerFlag" position="bottom" :style="{ height: '100%' }" closeable>
  18. <FilterItem :dataFilters="filterCriteria" @submit="FilterItemSubmit" />
  19. </van-popup>
  20. </div>
  21. </template>
  22. <script setup>
  23. import { ref, computed } from 'vue';
  24. import { useLifecycle } from '@hooks/useCommon.js';
  25. import { STAGE_OF_OBTAINING_BUSINESS_OPPORTUNITIES } from '@hooks/useApi.js';
  26. import { fixedFieldPermissionOptions, fixedFieldDateOptions } from '@utility/defaultData.js';
  27. import requests from "@common/requests"
  28. import usePxToVwView from "@hooks/usePxTransform.js";
  29. import ReRcharts from '@components/dataView/reRcharts.vue';
  30. import FilterItem from './filterItem.vue';
  31. const filterCriteriaPopUpLayerFlag = ref(false);
  32. const filterCriteria = ref({
  33. scopeSelection: 0,
  34. dateSelection: 0,
  35. customTime: []
  36. })
  37. const expandAndCollapse = ref(true);
  38. const echartsHeight = ref(140)
  39. const echartsOption = ref({})
  40. const scopeText = computed(() => {
  41. return fixedFieldPermissionOptions[filterCriteria.value.scopeSelection].label
  42. })
  43. const isExistBusiness = sessionStorage.getItem("isExistBusiness");
  44. const businessLabel = isExistBusiness === "1" ? "商机" : "项目";
  45. const dateText = computed(() => {
  46. if(filterCriteria.value.dateSelection == -1) {
  47. const { customTime = [] } = filterCriteria.value
  48. return ` ${customTime[0]} 至 ${customTime[1]}`
  49. }
  50. return fixedFieldDateOptions[filterCriteria.value.dateSelection].label
  51. })
  52. function FilterItemSubmit(val) {
  53. filterCriteria.value = val
  54. filterCriteriaPopUpLayerFlag.value = false;
  55. getEchartsData()
  56. }
  57. function showPopUpLayer() {
  58. filterCriteriaPopUpLayerFlag.value = true;
  59. }
  60. function expandAndCollapseSwitch() {
  61. expandAndCollapse.value = !expandAndCollapse.value;
  62. }
  63. function processChartData(yAxisData = [], seriesData = []) {
  64. const dataLength = yAxisData.length
  65. if(dataLength > 3) {
  66. echartsHeight.value = dataLength * 38
  67. }
  68. echartsOption.value = {
  69. tooltip: {
  70. // trigger: 'axis',
  71. // axisPointer: {
  72. // type: 'shadow'
  73. // }
  74. trigger: 'item',
  75. formatter: function (params) {
  76. return `
  77. <div class="tooltip-content">
  78. <div>${params.name}</div>
  79. <div>${params.data} 个</div>
  80. </div>
  81. `;
  82. }
  83. },
  84. legend: {
  85. show: false
  86. },
  87. grid: {
  88. top: usePxToVwView(60),
  89. left: usePxToVwView(250),
  90. right: usePxToVwView(60),
  91. bottom: usePxToVwView(100),
  92. },
  93. xAxis: {
  94. type: 'value',
  95. axisLabel: {
  96. fontSize: usePxToVwView(12),
  97. }
  98. },
  99. yAxis: {
  100. type: 'category',
  101. data: yAxisData,
  102. axisLabel: {
  103. fontSize: usePxToVwView(14),
  104. }
  105. },
  106. series: [
  107. {
  108. name: '2011',
  109. type: 'bar',
  110. data: seriesData,
  111. barWidth: usePxToVwView(80),
  112. },
  113. ]
  114. }
  115. }
  116. function getEchartsData() {
  117. const { scopeSelection = 0, dateSelection = 0, customTime = [] } = filterCriteria.value
  118. const formVal = {
  119. queryType: scopeSelection,
  120. ...(dateSelection !== -1 ? { dateType: dateSelection } : { startDate: customTime[0], endDate: customTime[1] })
  121. }
  122. requests.post(STAGE_OF_OBTAINING_BUSINESS_OPPORTUNITIES, {
  123. ...formVal
  124. }).then((res) => {
  125. const yAxisData = (res.data?.dataMap || []).map(item => item.stageName);
  126. const seriesData = (res.data?.dataMap || []).map(item => item.num);
  127. processChartData(yAxisData, seriesData)
  128. })
  129. }
  130. useLifecycle({
  131. load: () => {
  132. getEchartsData()
  133. },
  134. init: () => {
  135. getEchartsData()
  136. }
  137. });
  138. </script>
  139. <style lang='scss' scoped>
  140. /* 样式代码 */
  141. </style>