Browse Source

fix(inspectionProjectReport): 移除样品不合格数模板注释并添加计算逻辑

xieyong 1 day ago
parent
commit
9b6b33544d
1 changed files with 35 additions and 2 deletions
  1. 35 2
      src/views/inspectionWork/components/inspectionProjectReport.vue

+ 35 - 2
src/views/inspectionWork/components/inspectionProjectReport.vue

@@ -57,7 +57,7 @@
           <template slot="append">{{ form.measureUnit }}</template>
         </el-input>
       </template>
-      <template v-slot:sampleNoQualifiedNumber="{ row }">
+      <!-- <template v-slot:sampleNoQualifiedNumber="{ row }">
         <el-input
           v-model="row.sampleNoQualifiedNumber"
           @input="formSampleNoQualifiedNumberChange"
@@ -67,7 +67,7 @@
         >
           <template slot="append">{{ form.measureUnit }}</template>
         </el-input>
-      </template>
+      </template> -->
     </ele-pro-table>
     <ele-pro-table
       :needPage="false"
@@ -429,6 +429,13 @@
             slot: 'sampleNoQualifiedNumber',
             align: 'center',
             label: '样品不合格数',
+            formatter: (row) => {
+              if (row.sampleNoQualifiedNumber) {
+                return (
+                  row.sampleNoQualifiedNumber + (this.form.measureUnit || '')
+                );
+              }
+            },
             showOverflowTooltip: true
           },
           {
@@ -1004,6 +1011,32 @@
           }
         }
       }
+    },
+    watch: {
+      tableData: {
+        deep: true,
+        handler(newVal) {
+          if (!newVal || !newVal.length) {
+            this.form.sampleNoQualifiedNumber = 0;
+            this.form.sampleQualifiedNumber = this.form.sampleQuantity || 0;
+            return;
+          }
+          const totalQualified = newVal.reduce((sum, item) => {
+            return sum + (Number(item.qualifiedQuantity) || 0);
+          }, 0);
+          const totalNoQualified = newVal.reduce((sum, item) => {
+            return sum + (Number(item.noQualifiedQuantity) || 0);
+          }, 0);
+          this.$set(this.form, 'sampleNoQualifiedNumber', totalNoQualified);
+          const qualifiedNumber = totalQualified - totalNoQualified;
+          if (qualifiedNumber < 0) {
+            this.$message.warning('样品合格数不能小于0');
+            this.$set(this.form, 'sampleQualifiedNumber', 0);
+          } else {
+            this.$set(this.form, 'sampleQualifiedNumber', qualifiedNumber);
+          }
+        }
+      }
     }
   };
 </script>