WXL (wul)
4 天以前 bc9538a9e071259ca8bbb6de52c60c9d7a55a03b
src/views/Satisfaction/sfstatistics/components/DataOverview.vue
@@ -445,8 +445,13 @@
    const details = pickDetails(item);
    let node = map.get(title);
    if (!node) {
      node = { title, type: "", options: new Map() };
      node = { title, type: "", options: new Map(), avgScore: null };
      map.set(title, node);
    }
    // 综合得分:后端返回的题目级 avgScore(与题目同级)
    if (node.avgScore == null) {
      const rawAvg = Number(item && item.avgScore);
      node.avgScore = isNaN(rawAvg) ? null : rawAvg;
    }
    details.forEach((d) => {
@@ -480,7 +485,7 @@
  return Array.from(map.values()).map((n) => {
    const options = Array.from(n.options.values());
    const item = { title: n.title, type: n.type, options };
    const item = { title: n.title, type: n.type, options, avgScore: n.avgScore };
    // 多选题:用各选项数量之和作为填报总量(接口未单独提供人次)
    if (n.type === "multiple")
      item.total = options.reduce((s, o) => s + o.count, 0);
@@ -595,7 +600,8 @@
          veryBadRate: this.rateOf(veryBad.count, total),
          naCount: na.count,
          naRate: this.rateOf(na.count, total),
          score: this.scoreOfItems(items),
          total,
          score: this.formatScore(q.avgScore),
        };
      });
@@ -609,6 +615,17 @@
        });
      });
      const total = sum.reduce((s, it) => s + it.count, 0);
      // 总计综合得分:按各题填报量加权平均各题 avgScore
      let totalScoreNum = 0;
      let totalScoreDen = 0;
      this.satisfactionQuestions.forEach((q, i) => {
        const avg = Number(q.avgScore);
        const qTotal = rows[i] ? rows[i].total : 0;
        if (!isNaN(avg) && qTotal) {
          totalScoreNum += avg * qTotal;
          totalScoreDen += qTotal;
        }
      });
      rows.push({
        category: "总计",
        veryGoodCount: sum[0].count,
@@ -623,7 +640,7 @@
        veryBadRate: this.rateOf(sum[4].count, total),
        naCount: sum[5].count,
        naRate: this.rateOf(sum[5].count, total),
        score: this.scoreOfItems(sum),
        score: totalScoreDen ? (totalScoreNum / totalScoreDen).toFixed(2) : "0.00",
      });
      return rows;
    },
@@ -772,6 +789,11 @@
      if (!denominator) return "0.00";
      return (numerator / denominator).toFixed(2);
    },
    // 综合得分展示:直接使用后端 avgScore,格式化为两位小数
    formatScore(val) {
      const n = Number(val);
      return isNaN(n) ? "0.00" : n.toFixed(2);
    },
    defaultRange() {
      const end = new Date();
      const start = new Date();