zhangwencui
6 小时以前 897524d4918c407dbaa32fc98e5c5867c70e4064
src/views/costAccounting/energyCosts/index.vue
@@ -1080,6 +1080,33 @@
  // 更新能耗成本趋势图
  const updateCostChart = () => {
    const data = tableData.value;
    // 按日期分组并合并数据
    const groupedData = {};
    data.forEach(item => {
      const date = item.meterReadingDate;
      if (!groupedData[date]) {
        groupedData[date] = {
          productionCost: 0,
          officeCost: 0,
        };
      }
      if (item.type === "生产") {
        groupedData[date].productionCost += parseFloat(item.cost) || 0;
      } else if (item.type === "办公") {
        groupedData[date].officeCost += parseFloat(item.cost) || 0;
      }
    });
    // 转换为数组并按日期排序
    const mergedData = Object.entries(groupedData)
      .map(([date, costs]) => ({
        date,
        productionCost: costs.productionCost,
        officeCost: costs.officeCost,
      }))
      .sort((a, b) => new Date(a.date) - new Date(b.date));
    const option = {
      tooltip: {
        trigger: "axis",
@@ -1106,7 +1133,7 @@
      },
      xAxis: {
        type: "category",
        data: data.map(item => item.meterReadingDate),
        data: mergedData.map(item => item.date),
        axisLabel: {
          rotate: statisticsType.value === "day" ? 45 : 0,
          color: "rgba(15, 23, 42, 0.62)",
@@ -1126,7 +1153,7 @@
        {
          name: "生产能耗成本",
          type: "bar",
          data: data.map(item => (item.type === "生产" ? item.cost : 0)),
          data: mergedData.map(item => item.productionCost),
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: "#409EFF" },
@@ -1141,7 +1168,7 @@
        {
          name: "办公能耗成本",
          type: "bar",
          data: data.map(item => (item.type === "办公" ? item.cost : 0)),
          data: mergedData.map(item => item.officeCost),
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: "#67C23A" },