wlzboy
2025-09-21 b5b16a26de0d84d7b5fb69b584377bdc3582e3ab
ruoyi-ui/src/views/evaluation/statistics/index.vue
@@ -185,7 +185,7 @@
</template>
<script>
import { listCustomerEvaluation, getCustomerEvaluation } from "@/api/evaluation";
import { listCustomerEvaluation, getCustomerEvaluation, getEvaluationStatistics } from "@/api/evaluation";
import * as echarts from 'echarts';
export default {
@@ -227,7 +227,11 @@
        averageScore: 0,
        goodRate: 0,
        vehicleCount: 0
      }
      },
      // 图表实例
      scoreChart: null,
      trendChart: null,
      dimensionChart: null
    };
  },
  created() {
@@ -251,13 +255,26 @@
    },
    /** 获取统计数据 */
    getStatistics() {
      // 这里应该调用统计接口,暂时使用模拟数据
      this.statisticsData = {
        totalEvaluations: 156,
        averageScore: 4.2,
        goodRate: 85.6,
        vehicleCount: 23
      };
      getEvaluationStatistics(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        const data = response.data;
        this.statisticsData = {
          totalEvaluations: data.totalEvaluations || 0,
          averageScore: data.averageScore || 0,
          goodRate: data.goodRate || 0,
          vehicleCount: data.vehicleCount || 0
        };
        // 更新图表数据
        this.updateCharts(data);
      }).catch(() => {
        // 如果接口调用失败,使用默认数据
        this.statisticsData = {
          totalEvaluations: 0,
          averageScore: 0,
          goodRate: 0,
          vehicleCount: 0
        };
      });
    },
    /** 初始化图表 */
    initCharts() {
@@ -265,9 +282,22 @@
      this.initTrendChart();
      this.initDimensionChart();
    },
    /** 更新图表数据 */
    updateCharts(data) {
      this.updateScoreChart(data.scoreDistribution);
      this.updateTrendChart(data.monthlyTrend);
      this.updateDimensionChart(data.dimensionScores);
    },
    /** 初始化评分分布图表 */
    initScoreChart() {
      const chart = echarts.init(this.$refs.scoreChart);
      this.scoreChart = echarts.init(this.$refs.scoreChart);
      this.updateScoreChart([0, 0, 0, 0, 0]);
    },
    /** 更新评分分布图表 */
    updateScoreChart(scoreDistribution) {
      if (!this.scoreChart) {
        this.scoreChart = echarts.init(this.$refs.scoreChart);
      }
      const option = {
        title: {
          text: '评分分布',
@@ -282,11 +312,11 @@
            type: 'pie',
            radius: '50%',
            data: [
              { value: 35, name: '5星' },
              { value: 28, name: '4星' },
              { value: 20, name: '3星' },
              { value: 12, name: '2星' },
              { value: 5, name: '1星' }
              { value: scoreDistribution[4] || 0, name: '5星' },
              { value: scoreDistribution[3] || 0, name: '4星' },
              { value: scoreDistribution[2] || 0, name: '3星' },
              { value: scoreDistribution[1] || 0, name: '2星' },
              { value: scoreDistribution[0] || 0, name: '1星' }
            ],
            emphasis: {
              itemStyle: {
@@ -298,11 +328,18 @@
          }
        ]
      };
      chart.setOption(option);
      this.scoreChart.setOption(option);
    },
    /** 初始化趋势图表 */
    initTrendChart() {
      const chart = echarts.init(this.$refs.trendChart);
      this.trendChart = echarts.init(this.$refs.trendChart);
      this.updateTrendChart([0, 0, 0, 0, 0, 0]);
    },
    /** 更新趋势图表 */
    updateTrendChart(monthlyTrend) {
      if (!this.trendChart) {
        this.trendChart = echarts.init(this.$refs.trendChart);
      }
      const option = {
        title: {
          text: '月度评价趋势',
@@ -322,16 +359,23 @@
          {
            name: '评价数量',
            type: 'line',
            data: [12, 19, 23, 18, 25, 28],
            data: monthlyTrend || [0, 0, 0, 0, 0, 0],
            smooth: true
          }
        ]
      };
      chart.setOption(option);
      this.trendChart.setOption(option);
    },
    /** 初始化维度统计图表 */
    initDimensionChart() {
      const chart = echarts.init(this.$refs.dimensionChart);
      this.dimensionChart = echarts.init(this.$refs.dimensionChart);
      this.updateDimensionChart([0, 0, 0, 0, 0]);
    },
    /** 更新维度统计图表 */
    updateDimensionChart(dimensionScores) {
      if (!this.dimensionChart) {
        this.dimensionChart = echarts.init(this.$refs.dimensionChart);
      }
      const option = {
        title: {
          text: '各维度评分统计',
@@ -355,14 +399,14 @@
          {
            name: '平均评分',
            type: 'bar',
            data: [4.5, 4.2, 4.3, 4.4, 4.1],
            data: dimensionScores || [0, 0, 0, 0, 0],
            itemStyle: {
              color: '#409EFF'
            }
          }
        ]
      };
      chart.setOption(option);
      this.dimensionChart.setOption(option);
    },
    // 取消按钮
    cancel() {
@@ -390,6 +434,7 @@
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.getStatistics();
    },
    /** 重置按钮操作 */
    resetQuery() {