Procházet zdrojové kódy

merge: 合入dev分支的检测项报工逻辑调整

xieyong před 1 dnem
rodič
revize
a37f7a2e8e

+ 62 - 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"
@@ -212,6 +212,7 @@
           placeholder="请选择"
           style="width: 100%"
           :disabled="type == 'detail'"
+          @change="(val) => handleQualityResultsChange(val, row, $index)"
         >
           <el-option
             v-for="item in qualityResultsList"
@@ -428,6 +429,13 @@
             slot: 'sampleNoQualifiedNumber',
             align: 'center',
             label: '样品不合格数',
+            formatter: (row) => {
+              if (row.sampleNoQualifiedNumber) {
+                return (
+                  row.sampleNoQualifiedNumber + (this.form.measureUnit || '')
+                );
+              }
+            },
             showOverflowTooltip: true
           },
           {
@@ -976,6 +984,58 @@
         ) {
           this.setNumber(item, index, type, '留样', 'retainedSampleQuantity');
         }
+      },
+      handleQualityResultsChange(val, row, index) {
+        //切换到合格:把不合格数移到合格数
+        if (val == 1) {
+          if (
+            row.qualifiedQuantity == 0 &&
+            row.noQualifiedQuantity &&
+            row.noQualifiedQuantity != 0
+          ) {
+            this.$set(row, 'qualifiedQuantity', row.noQualifiedQuantity);
+            this.$set(row, 'noQualifiedQuantity', 0);
+            this.isQualifiedQuantity(row, index, 'qualifiedQuantity');
+          }
+        }
+        //切换到不合格:把合格数移到不合格数
+        if (val == 2) {
+          if (
+            row.noQualifiedQuantity == 0 &&
+            row.qualifiedQuantity &&
+            row.qualifiedQuantity != 0
+          ) {
+            this.$set(row, 'noQualifiedQuantity', row.qualifiedQuantity);
+            this.$set(row, 'qualifiedQuantity', 0);
+            this.isQualifiedQuantity(row, index, 'noQualifiedQuantity');
+          }
+        }
+      }
+    },
+    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);
+          }
+        }
       }
     }
   };