cyy 4 дней назад
Родитель
Сommit
b88d396b12
1 измененных файлов с 78 добавлено и 63 удалено
  1. 78 63
      src/views/component/facility/facilityData.vue

+ 78 - 63
src/views/component/facility/facilityData.vue

@@ -125,7 +125,7 @@
 
           <el-table-column v-if="isCul" label="最终值" prop="result">
             <template slot-scope="{ row }">
-              <span>{{ row.result || '/' }}</span>
+              <span>{{ formatResult(row.result) }}</span>
             </template>
           </el-table-column>
 
@@ -175,9 +175,9 @@ export default {
       isFirst: true,
       forms: [],
       multipleSelection: [],
-      baoliuxiaoshu:true,
-      config: 1,
-      isUpdatingFromParent: false  // 标记是否来自父组件的更新
+      baoliuxiaoshu: true,
+      config: 2,
+      isUpdatingFromParent: false // 标记是否来自父组件的更新
     }
   },
   computed: {},
@@ -199,18 +199,17 @@ export default {
         this.culXiuZheng()
       },
       */
-      
-      handler(val) {        
+
+      handler(val) {
         if (val.lieBiaoShuJu) {
           // 标记开始内部更新,避免无限循环调用initData导致卡死(控制forms里的this.$emit的循环调用)
-          this.isUpdatingFromParent = true  
+          this.isUpdatingFromParent = true
           //现在每一次watch到数据变化,都会执行initData方法
           if (!this.isCul) {
             this.forms = this.initData(val.lieBiaoShuJu)
           } else {
             this.forms = this.initData(val.lieBiaoShuJu)
           }
-
         }
         this.culXiuZheng()
       },
@@ -226,13 +225,13 @@ export default {
         this.$emit('change-data', 'lieBiaoShuJu', JSON.stringify(val))
       },
       */
-     handler(val) {
+      handler(val) {
         this.culXiuZheng()
         //只有非内部更新时才向父组件发送数据(避免无限循环的调用导致卡死,由formData里的方法对该变量控制)
         if (!this.isUpdatingFromParent) {
           this.$emit('change-data', 'lieBiaoShuJu', JSON.stringify(val))
         } else {
-          this.isUpdatingFromParent = false  // 重置标记
+          this.isUpdatingFromParent = false // 重置标记
         }
       },
       deep: true
@@ -319,7 +318,11 @@ export default {
         }
         // this.formData.jianCeShiJian = '2025-03-01' // 测试用
         if (
-          !item.result && item.rate && (this.formData.jianCeShiJian || this.formData.bianZhiShiJian || this.readonly)
+          !item.result &&
+          item.rate &&
+          (this.formData.jianCeShiJian ||
+            this.formData.bianZhiShiJian ||
+            this.readonly)
         ) {
           let jianCeShiJian = ''
           if (this.readonly || !this.formData.jianCeShiJian) {
@@ -409,20 +412,22 @@ export default {
       const self = this
       this.forms.forEach((item) => {
         if (item.value) {
-          if(!self.baoliuxiaoshu && self.formData.leiXing === '纯水机') { //绍兴环境,纯水机不需要保留小数
+          if (!self.baoliuxiaoshu && self.formData.leiXing === '纯水机') {
+            //绍兴环境,纯水机不需要保留小数
             if (item.fixValue) {
-              item.result = self.addStringDecimals(item.fixValue,item.value)
+              item.result = self.addStringDecimals(item.fixValue, item.value)
             } else {
-              item.result = (+item.value)
+              item.result = +item.value
             }
-          }else{ //其他环境、其他页面
+          } else {
+            //其他环境、其他页面
             if (item.fixValue) {
               item.result = (+item.fixValue + +item.value).toFixed(this.config)
             } else {
-              item.result = (+item.value)//无修正值时不处理小数位
+              item.result = +item.value //无修正值时不处理小数位
             }
           }
-          
+
           item.status = this.getStatus(item.range, item.result)
         } else {
           item.result = ''
@@ -430,6 +435,19 @@ export default {
         }
       })
     },
+    // 展示用格式化:保留两位小数(向下取值),末尾可省略的0不展示
+    formatResult(val) {
+      if (val === '' || val === null || val === undefined) return '/'
+      const num = Number(val)
+      if (Number.isNaN(num)) return val
+      // 向下取值保留两位小数
+      const floored = Math.floor(num * 100) / 100
+      let str = String(floored)
+      if (str.includes('.')) {
+        str = str.replace(/0+$/, '').replace(/\.$/, '')
+      }
+      return str
+    },
     formatData(val) {
       return JSON.stringify(val)
     },
@@ -453,55 +471,52 @@ export default {
       })
     },
     addStringDecimals(a, b) {
-    // 分割整数和小数部分
-    const [int1, dec1 = ''] = a.split('.');
-    const [int2, dec2 = ''] = b.split('.');
-    
-    // 计算最大小数位数
-    const maxDecimal = Math.max(dec1.length, dec2.length);
-    
-    // 小数部分补零对齐
-    const paddedDec1 = dec1.padEnd(maxDecimal, '0');
-    const paddedDec2 = dec2.padEnd(maxDecimal, '0');
-    
-    // 拼接完整整数(原值 × 10^maxDecimal)
-    const fullInt1 = int1 + paddedDec1;
-    const fullInt2 = int2 + paddedDec2;
-    
-    // 大整数相加
-    let carry = 0;
-    let result = '';
-    let i = fullInt1.length - 1;
-    let j = fullInt2.length - 1;
-    
-    while (i >= 0 || j >= 0 || carry) {
-        const digit1 = i >= 0 ? parseInt(fullInt1[i--], 10) : 0;
-        const digit2 = j >= 0 ? parseInt(fullInt2[j--], 10) : 0;
-        const sum = digit1 + digit2 + carry;
-        carry = Math.floor(sum / 10);
-        result = (sum % 10) + result;
-    }
-    
-    // 处理前导零
-    result = result.replace(/^0+/, '') || '0';
-    
-    // 插入小数点
-    if (maxDecimal > 0) {
-        const pos = result.length - maxDecimal;
+      // 分割整数和小数部分
+      const [int1, dec1 = ''] = a.split('.')
+      const [int2, dec2 = ''] = b.split('.')
+
+      // 计算最大小数位数
+      const maxDecimal = Math.max(dec1.length, dec2.length)
+
+      // 小数部分补零对齐
+      const paddedDec1 = dec1.padEnd(maxDecimal, '0')
+      const paddedDec2 = dec2.padEnd(maxDecimal, '0')
+
+      // 拼接完整整数(原值 × 10^maxDecimal)
+      const fullInt1 = int1 + paddedDec1
+      const fullInt2 = int2 + paddedDec2
+
+      // 大整数相加
+      let carry = 0
+      let result = ''
+      let i = fullInt1.length - 1
+      let j = fullInt2.length - 1
+
+      while (i >= 0 || j >= 0 || carry) {
+        const digit1 = i >= 0 ? parseInt(fullInt1[i--], 10) : 0
+        const digit2 = j >= 0 ? parseInt(fullInt2[j--], 10) : 0
+        const sum = digit1 + digit2 + carry
+        carry = Math.floor(sum / 10)
+        result = (sum % 10) + result
+      }
+
+      // 处理前导零
+      result = result.replace(/^0+/, '') || '0'
+
+      // 插入小数点
+      if (maxDecimal > 0) {
+        const pos = result.length - maxDecimal
         if (pos <= 0) {
-            // 整数部分为零的情况
-            result = '0.' + result.padStart(maxDecimal, '0');
+          // 整数部分为零的情况
+          result = '0.' + result.padStart(maxDecimal, '0')
         } else {
-            // 正常插入小数点
-            result = 
-                result.slice(0, pos) + 
-                '.' + 
-                result.slice(pos);
+          // 正常插入小数点
+          result = result.slice(0, pos) + '.' + result.slice(pos)
         }
-    }
-    
-    return result;
-},
+      }
+
+      return result
+    },
     goRemove() {
       this.forms = this.forms.filter(
         (item) => !this.multipleSelection.includes(item)