src/views/qualityManagement/processInspection/components/formDia.vue
@@ -66,8 +66,35 @@
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="不良数量:" prop="defectiveQuantity">
              <el-input-number
                  :step="0.01"
                  :min="0"
                  :max="getMaxDefectiveQuantity()"
                  style="width: 100%"
                  v-model="form.defectiveQuantity"
                  placeholder="请输入"
                  clearable
                  :precision="2"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="不良原因:" prop="defectiveReason">
              <el-select v-model="form.defectiveReason" placeholder="请选择" clearable style="width: 100%">
                <el-option
                  v-for="dict in defective_reason"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </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="processQuantityDisabled"/>
              <el-input-number :step="0.01" :min="0" style="width: 100%" v-model="form.quantity" placeholder="请输入" clearable :precision="2" :disabled="operationType !== 'add'"/>
            </el-form-item>
          </el-col>
        </el-row>
@@ -132,7 +159,7 @@
</template>
<script setup>
import {ref, reactive, toRefs, computed, getCurrentInstance, nextTick} from "vue";
import {ref, reactive, toRefs, computed, getCurrentInstance, nextTick, watch} 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";
@@ -140,10 +167,12 @@
import {userListNoPage} from "@/api/system/user.js";
import {qualityInspectParamInfo} from "@/api/qualityManagement/qualityInspectParam.js";
import { list } from "@/api/productionManagement/productionProcess";
import { useDict } from "@/utils/dict.js";
const { proxy } = getCurrentInstance()
const emit = defineEmits(['close'])
// 获取字典数据
const { defective_reason } = useDict('defective_reason');
const dialogFormVisible = ref(false);
const operationType = ref('')
@@ -159,6 +188,8 @@
    testStandardId: "",
    unit: "",
    quantity: "",
    defectiveQuantity: "",
    defectiveReason: "",
    checkCompany: "",
    checkResult: "",
  },
@@ -214,6 +245,27 @@
const currentProductId = ref(0);
const testStandardOptions = ref([]); // 指标选择下拉框数据
const modelOptions = ref([]);
// 保存初始的 defectiveQuantity 值(用于计算变化量)
const initialDefectiveQuantity = ref(0);
// 获取不良数量最大值
const getMaxDefectiveQuantity = () => {
  return form.value.quantity || 0;
};
// 监听不良数量变化,自动更新数量
// 当 defectiveQuantity 增加时,quantity 减少;当 defectiveQuantity 减少时,quantity 增加
watch(() => form.value.defectiveQuantity, (newVal, oldVal) => {
  const newDefectiveQty = Number(newVal) || 0;
  const oldDefectiveQty = Number(oldVal) || 0;
  const currentQuantity = Number(form.value.quantity) || 0;
  // 计算变化量:新值 - 旧值
  const changeAmount = newDefectiveQty - oldDefectiveQty;
  // quantity 反向变化
  form.value.quantity = Number((currentQuantity - changeAmount).toFixed(2));
});
// 打开弹框
const openDialog = async (type, row) => {