yuan
5 天以前 9ea5ff67655241271bdf04bb50ca3a8d60c4e22a
src/views/qualityManagement/processInspection/components/formDia.vue
@@ -30,7 +30,6 @@
                          prop="productId">
              <el-tree-select v-model="form.productId"
                              placeholder="请选择"
                              filterable
                              clearable
                              check-strictly
                              @change="getModels"
@@ -131,6 +130,34 @@
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="是否抽检:"
                          prop="isSampling">
              <el-radio-group v-model="form.isSampling"
                              class="sampling-radio-group"
                              :disabled="isViewMode"
                              @change="handleSamplingChange">
                <el-radio-button :label="1">是</el-radio-button>
                <el-radio-button :label="0">否</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12"
                  v-if="form.isSampling === 1">
            <el-form-item label="抽检数量:"
                          prop="samplingQuantity">
              <el-input-number :step="0.01"
                               :min="0"
                               style="width: 100%"
                               v-model="form.samplingQuantity"
                               placeholder="请输入"
                               clearable
                               :precision="2"
                               :disabled="isViewMode" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="检测单位:"
                          prop="checkCompany">
              <el-input v-model="form.checkCompany"
@@ -140,17 +167,8 @@
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检测结果:"
                          prop="checkResult">
              <el-select v-model="form.checkResult"
                         :disabled="isViewMode">
                <el-option label="合格"
                           value="合格" />
                <el-option label="不合格"
                           value="不合格" />
                <el-option label="部分合格"
                           value="部分合格" />
              </el-select>
            <el-form-item label="合格率:">
              <el-tag :type="passRateTagType">{{ passRateDisplayText }}</el-tag>
            </el-form-item>
          </el-col>
        </el-row>
@@ -202,8 +220,7 @@
                       @click="submitForm">确认</el-button>
            <el-button @click="closeDia">取消</el-button>
          </template>
          <el-button v-else
                     @click="closeDia">关闭</el-button>
          <el-button v-else @click="closeDia">关闭</el-button>
        </div>
      </template>
    </el-dialog>
@@ -253,7 +270,8 @@
      qualifiedQuantity: "",
      unqualifiedQuantity: "",
      checkCompany: "",
      checkResult: "",
      isSampling: 0,
      samplingQuantity: "",
    },
    rules: {
      checkTime: [{ required: true, message: "请输入", trigger: "blur" }],
@@ -261,23 +279,51 @@
      checkName: [{ required: false, message: "请输入", trigger: "blur" }],
      productId: [{ required: true, message: "请输入", trigger: "blur" }],
      productModelId: [{ required: true, message: "请选择", trigger: "change" }],
      testStandardId: [
        { required: false, message: "请选择指标", trigger: "change" },
      ],
      testStandardId: [{ required: false, message: "请选择指标", trigger: "change" }],
      unit: [{ required: false, message: "请输入", trigger: "blur" }],
      quantity: [{ required: true, message: "请输入", trigger: "blur" }],
      qualifiedQuantity: [{ required: true, message: "请输入", trigger: "blur" }],
      unqualifiedQuantity: [
        { required: true, message: "请输入", trigger: "blur" },
      ],
      unqualifiedQuantity: [{ required: true, message: "请输入", trigger: "blur" }],
      checkCompany: [{ required: false, message: "请输入", trigger: "blur" }],
      checkResult: [{ required: true, message: "请输入", trigger: "change" }],
      isSampling: [{ required: true, message: "请选择是否抽检", trigger: "change" }],
      samplingQuantity: [{ required: true, message: "请输入抽检数量", trigger: "blur" }],
    },
  });
  const userList = ref([]);
  const { form, rules } = toRefs(data);
  // 是否为查看模式
  const isViewMode = computed(() => operationType.value === "view");
  const isViewMode = computed(() => operationType.value === 'view');
  const passRateValue = computed(() => {
    const fromApi = form.value.passRate;
    if (fromApi != null && fromApi !== '') {
      const n = Number(fromApi);
      if (!Number.isNaN(n)) return n;
    }
    const qualified = Number(form.value.qualifiedQuantity) || 0;
    const unqualified = Number(form.value.unqualifiedQuantity) || 0;
    const total = qualified + unqualified;
    if (!total || total === 0) return null;
    return (qualified / total) * 100;
  });
  const passRateDisplayText = computed(() => {
    const params = passRateValue.value;
    if (params == null || params === '') return '—';
    const n = Number(params);
    if (Number.isNaN(n)) return '—';
    return `${n.toFixed(2)}%`;
  });
  const passRateTagType = computed(() => {
    const params = passRateValue.value;
    if (params == null || params === '') return 'info';
    const n = Number(params);
    if (Number.isNaN(n)) return 'info';
    if (n >= 100) return 'success';
    if (n >= 90) return 'warning';
    return 'danger';
  });
  // 编辑时:productMainId 或 purchaseLedgerId 任一有值则工序、数量置灰
  const processQuantityDisabled = computed(() => {
    const v = form.value || {};
@@ -345,7 +391,8 @@
      unit: "",
      quantity: "",
      checkCompany: "",
      checkResult: "",
      isSampling: 0,
      samplingQuantity: "",
    };
    testStandardOptions.value = [];
    tableData.value = [];
@@ -354,8 +401,8 @@
    if (operationType.value === "edit" || operationType.value === "view") {
      // 先保存 testStandardId,避免被清空
      const savedTestStandardId = row.testStandardId;
      // 先设置表单数据,但暂时清空 testStandardId,等选项加载完成后再设置
      form.value = { ...row, testStandardId: "" };
      const { passRate, ...rowWithoutPassRate } = row;
      form.value = { ...rowWithoutPassRate, testStandardId: "" };
      currentProductId.value = row.productId || 0;
      // 关键:编辑时加载规格型号下拉选项,才能反显 productModelId
      if (currentProductId.value) {
@@ -452,26 +499,25 @@
      modelOptions.value.find(item => item.id == value)?.unit || "";
  };
  const handleQualifiedQuantityChange = value => {
  const handleQualifiedQuantityChange = (value) => {
    if (value === null || value === undefined) {
      form.value.qualifiedQuantity = 0;
      return;
    }
    const quantity = parseFloat(form.value.quantity) || 0;
    const qualified = parseFloat(value) || 0;
    form.value.qualifiedQuantity = qualified > quantity ? quantity : qualified;
    form.value.qualifiedQuantity = qualified > quantity?quantity:qualified;
    form.value.unqualifiedQuantity = Math.max(0, quantity - qualified);
  };
  const handleUnqualifiedQuantityChange = value => {
  const handleUnqualifiedQuantityChange = (value) => {
    if (value === null || value === undefined) {
      form.value.unqualifiedQuantity = 0;
      return;
    }
    const quantity = parseFloat(form.value.quantity) || 0;
    const unqualified = parseFloat(value) || 0;
    form.value.unqualifiedQuantity =
      unqualified > quantity ? quantity : unqualified;
    form.value.unqualifiedQuantity = unqualified > quantity?quantity:unqualified;
    form.value.qualifiedQuantity = Math.max(0, quantity - unqualified);
  };
@@ -579,7 +625,7 @@
        tableData.value = res.data || [];
        tableData.value = tableData.value.map(item => ({
          ...item,
          id: null,
          id: null
        }));
      })
      .catch(error => {
@@ -594,6 +640,15 @@
    qualityInspectParamInfo(id).then(res => {
      tableData.value = res.data;
    });
  };
  // 是否抽检切换
  const handleSamplingChange = (value) => {
    if (value !== 1) {
      form.value.samplingQuantity = "";
      nextTick(() => {
        proxy.$refs?.formRef?.clearValidate?.("samplingQuantity");
      });
    }
  };
  // 关闭弹框
  const closeDia = () => {
@@ -610,4 +665,7 @@
</script>
<style scoped>
.sampling-radio-group {
  height: 32px;
}
</style>