| | |
| | | </el-row> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="数量:" prop="quantity"> |
| | | <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="supplierQuantityDisabled"/> |
| | | clearable :precision="2" :disabled="supplierQuantityDisabled" |
| | | @change="onTotalQuantityChange"/> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | |
| | | </el-row> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="检测结果:" prop="checkResult"> |
| | | <el-select v-model="form.checkResult"> |
| | | <el-option label="合格" value="合格"/> |
| | | <el-option label="不合格" value="不合格"/> |
| | | </el-select> |
| | | <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" @change="onQualifiedQuantityChange"/> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="不合格数量:" prop="unqualifiedQuantity"> |
| | | <el-input-number :step="0.01" :min="0" style="width: 100%" v-model="form.unqualifiedQuantity" placeholder="请输入" |
| | | clearable :precision="2" @change="onUnqualifiedQuantityChange"/> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="检验员:" prop="checkName"> |
| | | <el-select v-model="form.checkName" placeholder="请选择" clearable style="width: 100%"> |
| | |
| | | unit: "", |
| | | thickness: "", |
| | | quantity: "", |
| | | qualifiedQuantity: null, |
| | | unqualifiedQuantity: null, |
| | | checkCompany: "", |
| | | checkResult: "", |
| | | reviewName: "", |
| | | }, |
| | | rules: { |
| | |
| | | thickness: [{required: false, message: "请输入", trigger: "blur"}], |
| | | quantity: [{required: true, message: "请输入", trigger: "blur"}], |
| | | checkCompany: [{required: false, message: "请输入", trigger: "blur"}], |
| | | checkResult: [{required: true, message: "请选择检测结果", trigger: "change"}], |
| | | qualifiedQuantity: [{required: true, message: "请输入合格数量", trigger: "blur"}], |
| | | unqualifiedQuantity: [{required: true, message: "请输入不合格数量", trigger: "blur"}], |
| | | }, |
| | | }); |
| | | const tableColumn = ref([ |
| | |
| | | const tableLoading = ref(false); |
| | | |
| | | const {form, rules} = toRefs(data); |
| | | |
| | | function normalizeQuantitiesFromLegacy() { |
| | | const qty = form.value.quantity != null ? Number(form.value.quantity) : null |
| | | if (qty == null || Number.isNaN(qty)) return |
| | | const hasQ = form.value.qualifiedQuantity != null && form.value.qualifiedQuantity !== '' |
| | | const hasU = form.value.unqualifiedQuantity != null && form.value.unqualifiedQuantity !== '' |
| | | if (hasQ && hasU) return |
| | | if (form.value.checkResult === '不合格') { |
| | | form.value.qualifiedQuantity = 0 |
| | | form.value.unqualifiedQuantity = qty |
| | | } else { |
| | | form.value.qualifiedQuantity = qty |
| | | form.value.unqualifiedQuantity = 0 |
| | | } |
| | | } |
| | | |
| | | function assertQtySplitOrError() { |
| | | const total = Number(form.value.quantity) |
| | | const a = form.value.qualifiedQuantity != null ? Number(form.value.qualifiedQuantity) : NaN |
| | | const b = form.value.unqualifiedQuantity != null ? Number(form.value.unqualifiedQuantity) : NaN |
| | | if (!Number.isFinite(total) || total < 0) { |
| | | proxy.$modal.msgError('请先填写有效的总数量') |
| | | return false |
| | | } |
| | | if (!Number.isFinite(a) || !Number.isFinite(b) || a < 0 || b < 0) { |
| | | proxy.$modal.msgError('请填写合格数量与不合格数量') |
| | | return false |
| | | } |
| | | if (a + b - total > 0.001) { |
| | | proxy.$modal.msgError('合格数量与不合格数量之和不能超过总数量') |
| | | return false |
| | | } |
| | | return true |
| | | } |
| | | |
| | | function roundQty(n) { |
| | | if (!Number.isFinite(n)) return 0 |
| | | return Math.round(n * 100) / 100 |
| | | } |
| | | |
| | | function parseTotalQty() { |
| | | const t = Number(form.value.quantity) |
| | | return Number.isFinite(t) && t >= 0 ? t : null |
| | | } |
| | | |
| | | function onQualifiedQuantityChange(val) { |
| | | const total = parseTotalQty() |
| | | if (total == null) return |
| | | let q = val == null || val === '' ? 0 : Number(val) |
| | | if (!Number.isFinite(q) || q < 0) q = 0 |
| | | if (q > total) q = total |
| | | q = roundQty(q) |
| | | form.value.qualifiedQuantity = q |
| | | form.value.unqualifiedQuantity = roundQty(total - q) |
| | | } |
| | | |
| | | function onUnqualifiedQuantityChange(val) { |
| | | const total = parseTotalQty() |
| | | if (total == null) return |
| | | let u = val == null || val === '' ? 0 : Number(val) |
| | | if (!Number.isFinite(u) || u < 0) u = 0 |
| | | if (u > total) u = total |
| | | u = roundQty(u) |
| | | form.value.unqualifiedQuantity = u |
| | | form.value.qualifiedQuantity = roundQty(total - u) |
| | | } |
| | | |
| | | function onTotalQuantityChange() { |
| | | const total = parseTotalQty() |
| | | if (total == null) return |
| | | const q = form.value.qualifiedQuantity != null && form.value.qualifiedQuantity !== '' ? Number(form.value.qualifiedQuantity) : NaN |
| | | const u = form.value.unqualifiedQuantity != null && form.value.unqualifiedQuantity !== '' ? Number(form.value.unqualifiedQuantity) : NaN |
| | | if (!Number.isFinite(q) && !Number.isFinite(u)) { |
| | | form.value.qualifiedQuantity = roundQty(total) |
| | | form.value.unqualifiedQuantity = 0 |
| | | return |
| | | } |
| | | if (Number.isFinite(q) && Number.isFinite(u)) { |
| | | const sum = q + u |
| | | if (sum > total + 0.001) { |
| | | const nq = roundQty(Math.min(Math.max(0, q), total)) |
| | | form.value.qualifiedQuantity = nq |
| | | form.value.unqualifiedQuantity = roundQty(total - nq) |
| | | } |
| | | return |
| | | } |
| | | if (Number.isFinite(q)) { |
| | | const nq = roundQty(Math.min(Math.max(0, q), total)) |
| | | form.value.qualifiedQuantity = nq |
| | | form.value.unqualifiedQuantity = roundQty(total - nq) |
| | | } else if (Number.isFinite(u)) { |
| | | const nu = roundQty(Math.min(Math.max(0, u), total)) |
| | | form.value.unqualifiedQuantity = nu |
| | | form.value.qualifiedQuantity = roundQty(total - nu) |
| | | } |
| | | } |
| | | |
| | | function ensureQtyPairInitialized() { |
| | | const total = parseTotalQty() |
| | | if (total == null) return |
| | | const qEmpty = form.value.qualifiedQuantity == null || form.value.qualifiedQuantity === '' |
| | | const uEmpty = form.value.unqualifiedQuantity == null || form.value.unqualifiedQuantity === '' |
| | | if (qEmpty && uEmpty) { |
| | | form.value.qualifiedQuantity = roundQty(total) |
| | | form.value.unqualifiedQuantity = 0 |
| | | } |
| | | } |
| | | |
| | | const supplierList = ref([]); |
| | | const productOptions = ref([]); |
| | | const currentProductId = ref(0); |
| | |
| | | unit: "", |
| | | thickness: "", |
| | | quantity: "", |
| | | qualifiedQuantity: null, |
| | | unqualifiedQuantity: null, |
| | | checkCompany: "", |
| | | checkResult: "", |
| | | reviewName: "", |
| | | } |
| | | approverNodes.value = [{ id: 1, userId: null }]; |
| | |
| | | // 先保存 testStandardId,避免被清空 |
| | | const savedTestStandardId = row.testStandardId; |
| | | form.value = {...row} |
| | | normalizeQuantitiesFromLegacy() |
| | | if (form.value.approveUserIds) { |
| | | const ids = String(form.value.approveUserIds) |
| | | .split(",") |
| | |
| | | const submitForm = () => { |
| | | proxy.$refs.formRef.validate(valid => { |
| | | if (valid) { |
| | | ensureQtyPairInitialized() |
| | | if (!assertQtySplitOrError()) { |
| | | return |
| | | } |
| | | const hasEmptyApprover = approverNodes.value.some(node => !node.userId); |
| | | if (hasEmptyApprover) { |
| | | proxy.$modal.msgError("请为所有审批节点选择审批人!"); |