Răsfoiți Sursa

pms 瑞都日报 车辆油耗 填报 详情 审批模式下显示逻辑调整

zhangcl 4 zile în urmă
părinte
comite
0034fee8c0
1 a modificat fișierele cu 112 adăugiri și 28 ștergeri
  1. 112 28
      src/views/pms/iotrddailyreport/FillDailyReportForm.vue

+ 112 - 28
src/views/pms/iotrddailyreport/FillDailyReportForm.vue

@@ -460,12 +460,12 @@
     </ContentWrap>
 
     <!-- 油耗信息区域 - 当有油耗数据时显示 -->
-    <ContentWrap class="fuel-consumption-section" v-if="formData.reportFuels && formData.reportFuels.length > 0">
+    <ContentWrap class="fuel-consumption-section" v-if="showFuelConsumption">
       <h2 class="text-lg font-semibold mb-4">油耗信息</h2>
 
       <div class="fuel-consumption-table">
         <el-table
-          :data="formData.reportFuels"
+          :data="fuelConsumptionData"
           border
           style="width: 100%"
           class="fuel-consumption-el-table"
@@ -1804,7 +1804,7 @@ const initFormData = (reportData: any) => {
   }
 
   // 计算当日油耗默认值
-  const dailyFuelDefault = calculateDailyFuel(reportData)
+  // const dailyFuelDefault = calculateDailyFuel(reportData)
 
   formData.value = {
     ...formData.value,
@@ -1814,7 +1814,7 @@ const initFormData = (reportData: any) => {
     platformWell: reportData.platformWell,
     rdStatus: reportData.rdStatus || '',
     techniqueIds: techniqueIds,
-    dailyFuel: dailyFuelDefault, // 设置当日油耗默认值
+    dailyFuel: reportData.dailyFuel, // 当日油耗默认值
     productionStatus: reportData.productionStatus || '',
     nextPlan: reportData.nextPlan || '',
     externalRental: reportData.externalRental || '',
@@ -1853,34 +1853,72 @@ const initFormData = (reportData: any) => {
   // 初始化设备数据
   initDeviceData(reportData)
 
-  // 初始化油耗数据
-  if (reportData.reportFuels && Array.isArray(reportData.reportFuels)) {
-    // 处理每个油耗数据项,设置 customFuel 的默认值并确保格式正确
-    const processedFuels = reportData.reportFuels.map((fuel: any) => {
-      let customFuelValue;
-
-      // 如果 customFuel 不为空,确保它是字符串格式并已正确格式化
-      if (fuel.customFuel !== null && fuel.customFuel !== undefined) {
-        const numValue = parseFloat(fuel.customFuel);
-        customFuelValue = !isNaN(numValue) ? formatNumber(numValue, 2) : '0.00';
-      } else {
-        // 如果 customFuel 为空,则使用 zhbdFuel 的值
-        const zhbdValue = parseFloat(fuel.zhbdFuel);
-        customFuelValue = !isNaN(zhbdValue) ? formatNumber(zhbdValue, 2) : '0.00';
-      }
+  // 初始化油耗数据 - 根据模式选择数据源
+  if (isDetailMode.value || isApprovalMode.value) {
+    // 详情或审批模式:优先使用 reportedFuels
+    let fuelSource = reportData.reportedFuels;
+
+    if (fuelSource && Array.isArray(fuelSource) && fuelSource.length > 0) {
+      // 处理每个油耗数据项,设置 customFuel 的默认值并确保格式正确
+      const processedFuels = fuelSource.map((fuel: any) => {
+        let customFuelValue;
+
+        // 如果 customFuel 不为空,确保它是字符串格式并已正确格式化
+        if (fuel.customFuel !== null && fuel.customFuel !== undefined) {
+          const numValue = parseFloat(fuel.customFuel);
+          customFuelValue = !isNaN(numValue) ? formatNumber(numValue, 2) : '0.00';
+        } else {
+          // 如果 customFuel 为空,则使用 zhbdFuel 的值
+          const zhbdValue = parseFloat(fuel.zhbdFuel);
+          customFuelValue = !isNaN(zhbdValue) ? formatNumber(zhbdValue, 2) : '0.00';
+        }
 
-      return {
-        ...fuel,
-        customFuel: customFuelValue
-      };
-    });
+        return {
+          ...fuel,
+          customFuel: customFuelValue
+        };
+      });
 
-    formData.value.reportFuels = processedFuels;
+      formData.value.reportFuels = processedFuels;
 
-    // 计算初始的当日油耗
-    calculateTotalDailyFuel();
+      // 计算初始的当日油耗
+      calculateTotalDailyFuel();
+    } else {
+      // 如果 reportedFuels 不存在或为空,设置空数组
+      formData.value.reportFuels = [];
+    }
   } else {
-    formData.value.reportFuels = []
+    // 编辑模式:优先使用 reportedFuels,不存在则使用 reportFuels
+    let fuelSource = reportData.reportedFuels || reportData.reportFuels || [];
+
+    if (fuelSource && Array.isArray(fuelSource) && fuelSource.length > 0) {
+      // 处理每个油耗数据项,设置 customFuel 的默认值并确保格式正确
+      const processedFuels = fuelSource.map((fuel: any) => {
+        let customFuelValue;
+
+        // 如果 customFuel 不为空,确保它是字符串格式并已正确格式化
+        if (fuel.customFuel !== null && fuel.customFuel !== undefined) {
+          const numValue = parseFloat(fuel.customFuel);
+          customFuelValue = !isNaN(numValue) ? formatNumber(numValue, 2) : '0.00';
+        } else {
+          // 如果 customFuel 为空,则使用 zhbdFuel 的值
+          const zhbdValue = parseFloat(fuel.zhbdFuel);
+          customFuelValue = !isNaN(zhbdValue) ? formatNumber(zhbdValue, 2) : '0.00';
+        }
+
+        return {
+          ...fuel,
+          customFuel: customFuelValue
+        };
+      });
+
+      formData.value.reportFuels = processedFuels;
+
+      // 计算初始的当日油耗
+      calculateTotalDailyFuel();
+    } else {
+      formData.value.reportFuels = [];
+    }
   }
 
 }
@@ -2015,6 +2053,42 @@ const calculateAndUpdateDailyFuel = () => {
   }
 }
 
+// 添加计算属性:获取油耗数据显示数据源
+const fuelConsumptionData = computed(() => {
+  // 如果是详情或审批模式
+  if (isDetailMode.value || isApprovalMode.value) {
+    // 如果 reportedFuels 存在且有值,则使用 reportedFuels
+    if (dailyReportData.value.reportedFuels &&
+      Array.isArray(dailyReportData.value.reportedFuels) &&
+      dailyReportData.value.reportedFuels.length > 0) {
+      return dailyReportData.value.reportedFuels;
+    }
+    // 否则返回空数组(隐藏区域)
+    return [];
+  }
+
+  // 如果是编辑模式
+  if (isEditMode.value) {
+    // 如果 reportedFuels 存在且有值,则使用 reportedFuels
+    if (dailyReportData.value.reportedFuels &&
+      Array.isArray(dailyReportData.value.reportedFuels) &&
+      dailyReportData.value.reportedFuels.length > 0) {
+      return dailyReportData.value.reportedFuels;
+    }
+    // 否则使用 reportFuels
+    return dailyReportData.value.reportFuels || [];
+  }
+
+  // 默认返回空数组
+  return [];
+});
+
+// 添加计算属性:判断是否显示油耗信息区域
+const showFuelConsumption = computed(() => {
+  const data = fuelConsumptionData.value;
+  return data && Array.isArray(data) && data.length > 0;
+});
+
 // 重新计算当日油耗const formatNumber
 const calculateTotalDailyFuel = () => {
   if (!formData.value.reportFuels || !Array.isArray(formData.value.reportFuels)) {
@@ -2066,6 +2140,16 @@ const handleCustomFuelChange = (fuelItem: any) => {
 
   // 手动触发当日油耗的重新计算
   calculateAndUpdateDailyFuel();
+
+  // 同步更新 formData.reportFuels 中的数据
+  if (formData.value.reportFuels) {
+    const index = formData.value.reportFuels.findIndex(
+      item => item.id === fuelItem.id || item.deviceId === fuelItem.deviceId
+    );
+    if (index !== -1) {
+      formData.value.reportFuels[index] = { ...fuelItem };
+    }
+  }
 }
 
 // 详情 审批 平台井 获取工作量值