|
|
@@ -62,10 +62,9 @@
|
|
|
<template v-slot:sampleNoQualifiedNumber="{ row }">
|
|
|
<el-input
|
|
|
v-model="row.sampleNoQualifiedNumber"
|
|
|
- @input="formSampleNoQualifiedNumberChange"
|
|
|
- placeholder="请输入"
|
|
|
+ placeholder="自动取值(质检项中最大不合格数)"
|
|
|
type="number"
|
|
|
- :disabled="type == 'detail'"
|
|
|
+ disabled
|
|
|
>
|
|
|
<template slot="append">{{ form.measureUnit }}</template>
|
|
|
</el-input>
|
|
|
@@ -214,6 +213,7 @@
|
|
|
placeholder="请选择"
|
|
|
style="width: 100%"
|
|
|
:disabled="type == 'detail'"
|
|
|
+ @change="handleQualityResultChange(row, $index)"
|
|
|
>
|
|
|
<el-option
|
|
|
v-for="item in qualityResultsList"
|
|
|
@@ -756,6 +756,30 @@
|
|
|
return this.form.sampleQuantity;
|
|
|
}
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ // 任意质检项的不合格数变更时,自动同步最大不合格数到样品不合格数
|
|
|
+ tableData: {
|
|
|
+ deep: true,
|
|
|
+ handler(list) {
|
|
|
+ if (!Array.isArray(list) || !list.length) {
|
|
|
+ this.$set(this.form, 'sampleNoQualifiedNumber', 0);
|
|
|
+ } else {
|
|
|
+ const maxNoQualified = list.reduce(
|
|
|
+ (max, item) =>
|
|
|
+ Math.max(max, Number(item.noQualifiedQuantity) || 0),
|
|
|
+ 0
|
|
|
+ );
|
|
|
+ this.$set(this.form, 'sampleNoQualifiedNumber', maxNoQualified);
|
|
|
+ }
|
|
|
+ const total = Number(this.form.sampleQuantity) || 0;
|
|
|
+ this.$set(
|
|
|
+ this.form,
|
|
|
+ 'sampleQualifiedNumber',
|
|
|
+ Math.max(total - (Number(this.form.sampleNoQualifiedNumber) || 0), 0)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
created() {
|
|
|
this.requestDict('质检计划类型');
|
|
|
@@ -887,16 +911,14 @@
|
|
|
]);
|
|
|
});
|
|
|
}
|
|
|
- this.form.sampleQualifiedNumber = this.form.sampleQuantity;
|
|
|
- this.form.sampleNoQualifiedNumber = 0;
|
|
|
- },
|
|
|
- formSampleNoQualifiedNumberChange() {
|
|
|
- if (+this.form.sampleNoQualifiedNumber < 0) {
|
|
|
- this.form.sampleNoQualifiedNumber = 0;
|
|
|
- }
|
|
|
- if (+this.form.sampleNoQualifiedNumber > this.form.sampleQuantity) {
|
|
|
- this.form.sampleNoQualifiedNumber = this.form.sampleQuantity;
|
|
|
- }
|
|
|
+ // 样品数变化后,重新计算合格数/不合格数
|
|
|
+ this.form.sampleNoQualifiedNumber = this.tableData.length
|
|
|
+ ? this.tableData.reduce(
|
|
|
+ (max, item) =>
|
|
|
+ Math.max(max, Number(item.noQualifiedQuantity) || 0),
|
|
|
+ 0
|
|
|
+ )
|
|
|
+ : 0;
|
|
|
this.form.sampleQualifiedNumber =
|
|
|
this.form.sampleQuantity - this.form.sampleNoQualifiedNumber;
|
|
|
},
|
|
|
@@ -906,6 +928,21 @@
|
|
|
this.$set(this.tableData[index], 'qualityResults', 1);
|
|
|
});
|
|
|
},
|
|
|
+ // 切换质检结果(合格/不合格)时,若合格数与不合格数其一为 0,则互换两个数值
|
|
|
+ handleQualityResultChange(row, index) {
|
|
|
+ const qualified = Number(row.qualifiedQuantity) || 0;
|
|
|
+ const noQualified = Number(row.noQualifiedQuantity) || 0;
|
|
|
+ // 切换为合格:noQualifiedQuantity -> qualifiedQuantity
|
|
|
+ if (row.qualityResults == 1 && qualified === 0 && noQualified > 0) {
|
|
|
+ this.$set(this.tableData[index], 'qualifiedQuantity', noQualified);
|
|
|
+ this.$set(this.tableData[index], 'noQualifiedQuantity', 0);
|
|
|
+ }
|
|
|
+ // 切换为不合格:qualifiedQuantity -> noQualifiedQuantity
|
|
|
+ if (row.qualityResults == 2 && noQualified === 0 && qualified > 0) {
|
|
|
+ this.$set(this.tableData[index], 'qualifiedQuantity', 0);
|
|
|
+ this.$set(this.tableData[index], 'noQualifiedQuantity', qualified);
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
handleClose() {
|
|
|
this.visible = false;
|