src/views/qualityManagement/finalInspection/components/formDia.vue
@@ -2,7 +2,7 @@
  <div>
    <el-dialog
        v-model="dialogFormVisible"
        :title="operationType === 'add' ? '新增出厂检验' : '编辑出厂检验'"
        :title="operationType === 'add' ? '新增成品检验' : '编辑成品检验'"
        width="70%"
        @close="closeDia"
    >
@@ -49,6 +49,11 @@
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="数量:" prop="quantity">
              <el-input-number :step="0.01" :min="0" style="width: 100%" v-model="form.quantity" placeholder="请输入" clearable :precision="2" :disabled="quantityDisabled"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
@@ -57,8 +62,23 @@
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="数量:" prop="quantity">
              <el-input-number :step="0.01" :min="0" style="width: 100%" v-model="form.quantity" placeholder="请输入" clearable :precision="2"/>
            <el-form-item label="不良数量:" prop="defectiveQuantity">
              <el-input v-model="form.defectiveQuantity" placeholder="请输入" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="不良原因:" prop="defectiveReason">
              <el-select v-model="form.defectiveReason" placeholder="请选择" clearable style="width: 100%">
                <el-option :label="item.label" :value="item.value" v-for="(item,index) in defective_reason" :key="index" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合格数量:" prop="qualifiedQuantity">
              <el-input-number :step="0.01" :min="0" style="width: 100%" v-model="form.qualifiedQuantity" placeholder="请输入" clearable :precision="2" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
@@ -123,7 +143,7 @@
</template>
<script setup>
import {ref, reactive, toRefs, getCurrentInstance, nextTick} from "vue";
import {ref, reactive, toRefs, computed, getCurrentInstance, nextTick} from "vue";
import {getOptions} from "@/api/procurementManagement/procurementLedger.js";
import {modelList, productTreeList} from "@/api/basicData/product.js";
import {qualityInspectAdd, qualityInspectUpdate} from "@/api/qualityManagement/rawMaterialInspection.js";
@@ -145,7 +165,9 @@
    productModelId: "",
    model: "",
    testStandardId: "",
    defectiveReason: undefined,
    unit: "",
    qualifiedQuantity: "",
    quantity: "",
    checkCompany: "",
    checkResult: "",
@@ -164,8 +186,14 @@
  },
});
const { form, rules } = toRefs(data);
// 编辑时:productMainId 或 purchaseLedgerId 任一有值则数量置灰
const quantityDisabled = computed(() => {
  const v = form.value || {};
  return !!(v.productMainId != null || v.purchaseLedgerId != null);
});
const supplierList = ref([]);
const productOptions = ref([]);
const { defective_reason } = proxy.useDict("defective_reason");
const tableColumn = ref([
   {
      label: "指标",
@@ -197,6 +225,29 @@
const testStandardOptions = ref([]); // 指标选择下拉框数据
const modelOptions = ref([]);
// 监听不良数量变化,自动更新数量
// 当 defectiveQuantity 增加时,quantity 减少;当 defectiveQuantity 减少时,quantity 增加
watch(() => form.value.defectiveQuantity, (newVal, oldVal) => {
  if (newVal > form.value.quantity) {
    form.value.defectiveQuantity = form.value.quantity;
  }
  form.value.qualifiedQuantity = Number((form.value.quantity - newVal).toFixed(2));
});
// 监听总数量变化,自动更新合格数量
watch(() => form.value.quantity, (newVal, oldVal) => {
  const totalQty = Number(newVal) || 0;
  const defectiveQty = Number(form.value.defectiveQuantity) || 0;
  // 确保不良数量不超过总数量
  if (defectiveQty > totalQty) {
    form.value.defectiveQuantity = totalQty;
  }
  // 计算合格数量
  form.value.qualifiedQuantity = Number((totalQty - defectiveQty).toFixed(2));
});
// 打开弹框
const openDialog = async (type, row) => {
  operationType.value = type;