From fa281e483a5fef9de01d8e08f258ebd8a7fca8eb Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期一, 23 三月 2026 13:47:28 +0800
Subject: [PATCH] 优化标准/实际成本对比分析页面的样式和功能,增加背景元素,改进KPI展示,支持自定义排序功能

---
 src/views/costAccounting/energyCosts/index.vue |  128 ++++++++++++++++++++++++++----------------
 1 files changed, 79 insertions(+), 49 deletions(-)

diff --git a/src/views/costAccounting/energyCosts/index.vue b/src/views/costAccounting/energyCosts/index.vue
index 63a1b48..89e1a2a 100644
--- a/src/views/costAccounting/energyCosts/index.vue
+++ b/src/views/costAccounting/energyCosts/index.vue
@@ -465,23 +465,23 @@
                   </div>
                 </el-card>
               </el-col>
-              <!-- <el-col :xs="24" :lg="12">
+              <el-col :xs="24" :lg="12">
                 <el-card class="chart-card" shadow="never">
                   <template #header>
                     <div class="chart-head">
-                      <span class="chart-title">鑳借�楀崟浠峰姣�</span>
+                      <span class="chart-title">鑳借�楃敤閲忓姣�</span>
                       <div class="chart-tools" @click.stop>
                         <button
                           class="chart-tool"
                           type="button"
-                          @click="downloadChart('price', '鑳借�楀崟浠峰姣�')"
+                          @click="downloadChart('unit', '鑳借�楃敤閲忓姣�')"
                         >
                           涓嬭浇
                         </button>
                         <button
                           class="chart-tool"
                           type="button"
-                          @click="openBigChart('price', '鑳借�楀崟浠峰姣�')"
+                          @click="openBigChart('unit', '鑳借�楃敤閲忓姣�')"
                         >
                           澶у浘
                         </button>
@@ -489,13 +489,13 @@
                     </div>
                   </template>
                   <div
-                    ref="priceChartWrap"
+                    ref="unitChartWrap"
                     class="chart-wrap"
                     v-loading="tableLoading"
                   >
                     <div
-                      ref="priceChart"
-                      class="chart-content"
+                      ref="unitChart"
+                      class="chart-content" 
                       v-show="hasTableData"
                     ></div>
                     <div class="chart-empty" v-show="!hasTableData">
@@ -503,7 +503,7 @@
                     </div>
                   </div>
                 </el-card>
-              </el-col> -->
+              </el-col>
             </el-row>
           </div>
         </transition>
@@ -605,10 +605,10 @@
         </el-table-column>
         <el-table-column prop="dosage" label="鐢ㄩ噺" align="right">
           <template #default="scope">
-            <span class="consumption-value">{{
+            <span class="unit-value">{{
               formatNumber(scope.row.dosage, 2)
             }}</span>
-            <span class="consumption-unit">{{ scope.row.unit }}</span>
+            <span class="unit-unit">{{ scope.row.unit }}</span>
           </template>
         </el-table-column>
         <el-table-column
@@ -875,13 +875,13 @@
   if (key === "cost") return costChartInstance;
   if (key === "type") return typeChartInstance;
   if (key === "purpose") return purposeChartInstance;
-  if (key === "price") return priceChartInstance;
+  if (key === "unit") return unitChartInstance;
   return null;
 };
 
 const ensurePanelForChart = (key) => {
   if (key === "cost" || key === "type") chartPanel.value = "core";
-  if (key === "purpose" || key === "price") chartPanel.value = "advanced";
+  if (key === "purpose" || key === "unit") chartPanel.value = "advanced";
 };
 
 const downloadChart = (key, title) => {
@@ -967,7 +967,7 @@
 
   const prop = sortState.prop;
   const direction = sortState.order === "ascending" ? 1 : -1;
-  const numFields = new Set(["price", "cost", "consumption"]);
+  const numFields = new Set(["price", "cost", "unit"]);
 
   return data.sort((a, b) => {
     const av = a?.[prop];
@@ -1011,12 +1011,12 @@
 const costChart = ref(null);
 const typeChart = ref(null);
 const purposeChart = ref(null);
-const priceChart = ref(null);
+const unitChart = ref(null);
 
 const costChartWrap = ref(null);
 const typeChartWrap = ref(null);
 const purposeChartWrap = ref(null);
-const priceChartWrap = ref(null);
+const unitChartWrap = ref(null);
 
 const tableAnchor = ref(null);
 
@@ -1044,28 +1044,32 @@
 let costChartInstance = null;
 let typeChartInstance = null;
 let purposeChartInstance = null;
-let priceChartInstance = null;
+let unitChartInstance = null;
 
 // 鍥捐〃鍖哄垏鎹細core | advanced | none锛堢偣鍑诲綋鍓嶉�変腑鍙敹璧凤級
 const chartPanel = ref("core");
 
 const ensureChartsReady = (panel) => {
   if (panel === "core") {
-    if (costChart.value && !costChartInstance)
+    if (costChart.value && !costChartInstance) {
       costChartInstance = echarts.init(costChart.value);
-    if (typeChart.value && !typeChartInstance)
+      setTimeout(() => costChartInstance?.resize(), 50);
+    }
+    if (typeChart.value && !typeChartInstance) {
       typeChartInstance = echarts.init(typeChart.value);
-    if (costChartInstance) updateCostChart();
-    if (typeChartInstance) updateTypeChart();
+      setTimeout(() => typeChartInstance?.resize(), 50);
+    }
     return;
   }
   if (panel === "advanced") {
-    if (purposeChart.value && !purposeChartInstance)
+    if (purposeChart.value && !purposeChartInstance) {
       purposeChartInstance = echarts.init(purposeChart.value);
-    if (priceChart.value && !priceChartInstance)
-      priceChartInstance = echarts.init(priceChart.value);
-    if (purposeChartInstance) updatePurposeChart();
-    if (priceChartInstance) updatePriceChart();
+      setTimeout(() => purposeChartInstance?.resize(), 50);
+    }
+    if (unitChart.value && !unitChartInstance) {
+      unitChartInstance = echarts.init(unitChart.value);
+      setTimeout(() => unitChartInstance?.resize(), 50);
+    }
   }
 };
 
@@ -1089,6 +1093,16 @@
 watch(chartPanel, (val) => {
   if (val !== "none") resizeChartsAfterExpand();
 });
+
+// 鐩戝惉琛ㄦ牸鏁版嵁鍙樺寲锛岀‘淇濇暟鎹姞杞藉悗鍥捐〃姝g‘娓叉煋
+watch(tableData, () => {
+  nextTick(() => {
+    updateCharts();
+    nextTick(() => {
+      handleResize();
+    });
+  });
+}, { deep: true });
 
 // 鑾峰彇鑳借�楃被鍨嬫爣绛剧被鍨�
 const getEnergyTypeType = (type) => {
@@ -1199,10 +1213,10 @@
   const typeCosts = {};
 
   data.forEach((item) => {
-    if (!typeCosts[item.energyType]) {
-      typeCosts[item.energyType] = 0;
+    if (!typeCosts[item.energyTyep]) {
+      typeCosts[item.energyTyep] = 0;
     }
-    typeCosts[item.energyType] += parseFloat(item.cost);
+    typeCosts[item.energyTyep] += parseFloat(item.cost);
   });
 
   const chartData = Object.entries(typeCosts).map(([name, value]) => ({
@@ -1331,26 +1345,32 @@
   purposeChartInstance.setOption(option);
 };
 
-// 鏇存柊鑳借�楀崟浠峰姣斿浘
-const updatePriceChart = () => {
+// 鏇存柊鑳借�楃敤閲忓姣斿浘
+const updateConsumptionChart = () => {
   const data = tableData.value;
-  const priceData = {};
+  const unitData = {};
 
   data.forEach((item) => {
-    if (!priceData[item.energyType]) {
-      priceData[item.energyType] = {
+    if (!unitData[item.energyTyep]) {
+      unitData[item.energyTyep] = {
         鐢熶骇: 0,
         鍔炲叕: 0,
       };
     }
-    if (priceData[item.energyType].hasOwnProperty(item.type)) {
-      priceData[item.energyType][item.type] = parseFloat(item.price);
+    if (unitData[item.energyTyep].hasOwnProperty(item.type)) {
+      unitData[item.energyTyep][item.type] += parseFloat(
+        item.dosage || 0
+      );
     }
   });
 
-  const energyTypes = Object.keys(priceData);
-  const productionPrices = energyTypes.map((type) => priceData[type].鐢熶骇);
-  const officePrices = energyTypes.map((type) => priceData[type].鍔炲叕);
+  const energyTypes = Object.keys(unitData);
+  const productionConsumptions = energyTypes.map(
+    (type) => unitData[type].鐢熶骇
+  );
+  const officeConsumptions = energyTypes.map(
+    (type) => unitData[type].鍔炲叕
+  );
 
   const option = {
     tooltip: {
@@ -1364,7 +1384,7 @@
         "box-shadow: 0 14px 40px rgba(15,23,42,.14); border-radius: 12px;",
     },
     legend: {
-      data: ["鐢熶骇鑳借�楀崟浠�", "鍔炲叕鑳借�楀崟浠�"],
+      data: ["鐢熶骇鑳借�楃敤閲�", "鍔炲叕鑳借�楃敤閲�"],
       top: 0,
       right: 10,
       textStyle: { color: "rgba(15, 23, 42, 0.62)" },
@@ -1385,7 +1405,7 @@
     },
     yAxis: {
       type: "value",
-      name: "鍗曚环(鍏�)",
+      name: "鐢ㄩ噺",
       nameTextStyle: { color: "rgba(15, 23, 42, 0.58)" },
       axisLabel: { color: "rgba(15, 23, 42, 0.58)" },
       axisLine: { show: false },
@@ -1393,9 +1413,9 @@
     },
     series: [
       {
-        name: "鐢熶骇鑳借�楀崟浠�",
+        name: "鐢熶骇鑳借�楃敤閲�",
         type: "bar",
-        data: productionPrices,
+        data: productionConsumptions,
         itemStyle: {
           color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
             { offset: 0, color: "#2f6fed" },
@@ -1405,9 +1425,9 @@
         },
       },
       {
-        name: "鍔炲叕鑳借�楀崟浠�",
+        name: "鍔炲叕鑳借�楃敤閲�",
         type: "bar",
-        data: officePrices,
+        data: officeConsumptions,
         itemStyle: {
           color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
             { offset: 0, color: "#16a34a" },
@@ -1418,7 +1438,7 @@
       },
     ],
   };
-  priceChartInstance.setOption(option);
+  unitChartInstance.setOption(option);
 };
 
 // 缁熻缁村害鍒囨崲
@@ -1447,6 +1467,7 @@
 
 // 鏌ヨ
 const handleQuery = () => {
+  
   queryPulse.value = true;
   window.setTimeout(() => {
     queryPulse.value = false;
@@ -1545,10 +1566,19 @@
 // 鏇存柊鎵�鏈夊浘琛�
 const updateCharts = () => {
   nextTick(() => {
+    // 纭繚 core 闈㈡澘鐨勫浘琛ㄥ缁堝垵濮嬪寲锛堝洜涓洪粯璁ゆ樉绀虹殑鏄� core锛�
+    ensureChartsReady("core");
+    
+    // 鍚屾椂涔熷垵濮嬪寲褰撳墠鍙闈㈡澘鐨勫浘琛�
+    if (chartPanel.value === "advanced") {
+      ensureChartsReady("advanced");
+    }
+    
+    // 鏇存柊鎵�鏈夊凡鍒濆鍖栫殑鍥捐〃
     if (costChartInstance) updateCostChart();
     if (typeChartInstance) updateTypeChart();
     if (purposeChartInstance) updatePurposeChart();
-    if (priceChartInstance) updatePriceChart();
+    if (unitChartInstance) updateConsumptionChart();
   });
 };
 
@@ -1600,7 +1630,7 @@
   costChartInstance && costChartInstance.resize();
   typeChartInstance && typeChartInstance.resize();
   purposeChartInstance && purposeChartInstance.resize();
-  priceChartInstance && priceChartInstance.resize();
+  unitChartInstance && unitChartInstance.resize();
 };
 
 onMounted(() => {
@@ -2607,12 +2637,12 @@
   width: 100%;
 }
 
-.consumption-value {
+.unit-value {
   font-weight: bold;
   color: var(--lux-primary);
 }
 
-.consumption-unit {
+.unit-unit {
   font-size: 12px;
   color: var(--lux-muted);
   margin-left: 2px;

--
Gitblit v1.9.3