Explorar o código

Merge branch 'yunxing_record' of shuzhihua/pms-app into master

yanghao hai 1 semana
pai
achega
5c084ed17f
Modificáronse 2 ficheiros con 73 adicións e 41 borrados
  1. 2 2
      config/env.dev.js
  2. 71 39
      pages/recordFilling/detail.vue

+ 2 - 2
config/env.dev.js

@@ -1,7 +1,7 @@
 // 开发环境配置
 export default {
-	// apiUrl: 'http://192.168.1.63:8888',  
-	apiUrl: 'https://iot.deepoil.cc',
+	apiUrl: 'http://192.168.188.16:48080',
+	// apiUrl: 'https://iot.deepoil.cc',
 	// apiUrl: 'https://aims.deepoil.cc', //正式
 	apiUrlSuffix: '/admin-api',
 	// 其他开发环境配置...  

+ 71 - 39
pages/recordFilling/detail.vue

@@ -106,7 +106,7 @@
                     ? checkThreshold(nosum)
                     : checkLessThreshold(nosum)
                 "
-                @change="handleFillContentChange(nosum, item)"
+                @input="handleRealTimeUpdate(nosum, item)"
               ></uni-easyinput>
             </view>
             <!-- type为textarea时,输入框为文本类型 -->
@@ -281,65 +281,97 @@ const handleFillContentChange = (nosum, deviceItem) => {
   }
 };
 
+// 防抖函数
+function debounce(func, delay) {
+  let timer;
+  return function (...args) {
+    clearTimeout(timer);
+    timer = setTimeout(() => func.apply(this, args), delay);
+  };
+}
+
+//防抖
+const debouncedCalculateTotalRunTime = debounce(calculateTotalRunTime, 100);
+
+const handleRealTimeUpdate = (nosum, deviceItem) => {
+  console.log("🚀 实时更新 ~ nosum, deviceItem:", nosum, deviceItem);
+
+  // 当日运转时间累加
+  if (
+    deviceItem.deviceName.includes("增压机") &&
+    nosum.name === "当日运转时间"
+  ) {
+    debouncedCalculateTotalRunTime("增压机", "当日运转时间", "当日运转时间H");
+  }
+
+  // 当日注气量累加
+  if (deviceItem.deviceName.includes("提纯撬") && nosum.name === "当日注气量") {
+    debouncedCalculateTotalRunTime("提纯撬", "当日注气量", "当日注气量-方");
+  }
+
+  // 当日注水量累加
+  if (deviceItem.deviceName.includes("注水泵") && nosum.name === "当日注水量") {
+    debouncedCalculateTotalRunTime("注水泵", "当日注水量", "当日注水量-方");
+  }
+
+  // 当日用电量累加
+  if (
+    deviceItem.deviceName.includes("箱式变电站") &&
+    nosum.name === "当日用电量"
+  ) {
+    debouncedCalculateTotalRunTime("箱式变电站", "当日用电量", "当日用电量kWh");
+  }
+};
+
 /**
  * 计算所有deviceName中包含deviceNameToMatch的对象中对应的reportName的fillContent总和并更新到reportName的fillContent中
  * @param deviceNameToMatch {string} 设备名称包含的字符串
  * @param reportName {string} 填写项名称
  */
-const calculateTotalRunTime = (deviceNameToMatch, reportName) => {
-  console.log(
-    "🚀calculateTotalRunTime ~ deviceNameToMatch, reportName:",
-    deviceNameToMatch,
-    12
+function calculateTotalRunTime(
+  deviceNameToMatch,
+  sourceFieldName,
+  targetFieldName
+) {
+  const reportItem = dataList.value.find(
+    (item) => item.deviceName === "生产日报"
   );
-  // 查找isReport为1的对象
-  const reportItem = dataList.value.find((item) => item.isReport === 1);
-  console.log("🚀calculateTotalRunTime ~ reportItem:", reportItem);
-
-  if (!reportItem) return;
-  /**
-   * @param deviceNameToMatch {string} 设备名称包含的字符串
-   * @param deviceName {string} 设备名称
-   * @param reportName {string} 填写项名称
-   * 查找[生产日报]中对应的填写项
-   * reportName -> deviceName:reportName
-   * 当日运转时间 -> 增压机:当日运转时间
-   * 当日注气量 -> 提纯撬:当日注气量
-   * 当日注水量 -> 注水泵:当日注水量
-   * 当日用电量 -> 箱式变电站:当日用电量
-   */
+
+  if (!reportItem) {
+    console.warn("⚠️ 未找到生产日报");
+    return;
+  }
+
   const targetItem = reportItem.nonSumList.find(
-    (item) => item.name === reportName
+    (item) => item.name === targetFieldName
   );
 
-  if (!targetItem) return;
+  if (!targetItem) {
+    console.warn(`⚠️ 未找到目标字段:${targetFieldName}`);
+    return;
+  }
+
+  let total = 0;
 
-  // 计算所有deviceName中包含deviceNameToMatch的对象中对应的reportName的fillContent总和
-  let total = null;
   dataList.value.forEach((item) => {
     if (item.deviceName.includes(deviceNameToMatch) && item.nonSumList) {
       item.nonSumList.forEach((nonSum) => {
-        // 只累加数字类型的值
         if (
           nonSum.type === "double" &&
-          nonSum.fillContent &&
-          nonSum.name === reportName
+          nonSum.name === sourceFieldName &&
+          nonSum.fillContent !== null &&
+          nonSum.fillContent !== ""
         ) {
-          console.log("🚀 ~ nonSum.fillContent:", nonSum.fillContent);
-          console.log("🚀 ~ nonSum:", nonSum);
-          const value = Number(nonSum.fillContent) || 0;
+          const value = parseFloat(nonSum.fillContent) || 0;
           total += value;
         }
       });
     }
   });
-  console.log("🚀 ~ total:", total);
-  if (total !== null) {
-    // 更新目标值,保留两位小数
-    targetItem.fillContent = toFixed(total);
-    console.log("🚀 ~ targetItem.fillContent:", targetItem.fillContent);
-  }
-};
+
+  console.log(`📊 累计值 (${sourceFieldName} -> ${targetFieldName}):`, total);
+  targetItem.fillContent = toFixed(total);
+}
 
 // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可
 const queryList = (pageNo, pageSize) => {