| | |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="工序:" prop="process"> |
| | | <el-input v-model="form.process" placeholder="请输入工序" clearable /> |
| | | <el-select v-model="form.process" placeholder="请选择工序" clearable :disabled="processQuantityDisabled" style="width: 100%"> |
| | | <el-option v-for="item in processList" :key="item.name" :label="item.name" :value="item.name"/> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="单位:" prop="unit"> |
| | | <el-input v-model="form.unit" placeholder="请输入" disabled/> |
| | | <el-input v-model="form.unit" placeholder="自动带出" readonly class="readonly-display"/> |
| | | </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="thickness"> |
| | | <el-input v-model="form.thickness" placeholder="自动带出" readonly class="readonly-display"/> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="30"> |
| | | <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" |
| | | @change="onTotalQuantityChange"/> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="30"> |
| | | <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" @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-form-item> |
| | | </el-col> |
| | | <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> |
| | | </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> |
| | | <el-option v-for="item in userList" :key="item.nickName" :label="item.nickName" |
| | |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="检测日期:" prop="checkTime"> |
| | | <el-date-picker |
| | |
| | | </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"; |
| | | import {qualityInspectDetailByProductId, getQualityTestStandardParamByTestStandardId} from "@/api/qualityManagement/metricMaintenance.js"; |
| | | import {userListNoPage} from "@/api/system/user.js"; |
| | | import {qualityInspectParamInfo} from "@/api/qualityManagement/qualityInspectParam.js"; |
| | | import { list } from "@/api/productionManagement/productionProcess"; |
| | | const { proxy } = getCurrentInstance() |
| | | const emit = defineEmits(['close']) |
| | | |
| | | |
| | | |
| | | const dialogFormVisible = ref(false); |
| | | const operationType = ref('') |
| | |
| | | model: "", |
| | | testStandardId: "", |
| | | unit: "", |
| | | thickness: "", |
| | | quantity: "", |
| | | qualifiedQuantity: null, |
| | | unqualifiedQuantity: null, |
| | | checkCompany: "", |
| | | checkResult: "", |
| | | }, |
| | | rules: { |
| | | checkTime: [{ required: true, message: "请输入", trigger: "blur" },], |
| | | process: [{ required: true, message: "请输入工序", trigger: "blur" }], |
| | | process: [{ required: true, message: "请选择工序", trigger: "change" }], |
| | | checkName: [{ required: false, message: "请输入", trigger: "blur" }], |
| | | productId: [{ required: true, message: "请输入", trigger: "blur" }], |
| | | productModelId: [{ required: true, message: "请选择", trigger: "change" }], |
| | | testStandardId: [{required: false, message: "请选择指标", trigger: "change"}], |
| | | unit: [{ required: false, message: "请输入", trigger: "blur" }], |
| | | 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 userList = ref([]); |
| | | 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 |
| | | } |
| | | } |
| | | // 编辑时:productMainId 或 purchaseLedgerId 任一有值则工序、数量置灰 |
| | | const processQuantityDisabled = computed(() => { |
| | | const v = form.value || {}; |
| | | return !!(v.productMainId != null || v.purchaseLedgerId != null); |
| | | }); |
| | | const processList = ref([]); // 工序下拉列表(工序名称 name) |
| | | const supplierList = ref([]); |
| | | const productOptions = ref([]); |
| | | const tableColumn = ref([ |
| | |
| | | getOptions().then((res) => { |
| | | supplierList.value = res.data; |
| | | }); |
| | | // 加载工序下拉列表 |
| | | try { |
| | | const res = await list(); |
| | | processList.value = res.data || []; |
| | | } catch (e) { |
| | | console.error("加载工序列表失败", e); |
| | | processList.value = []; |
| | | } |
| | | let userLists = await userListNoPage(); |
| | | userList.value = userLists.data; |
| | | // 先重置表单数据(保持字段完整,避免弹窗首次渲染时触发必填红框“闪一下”) |
| | |
| | | model: "", |
| | | testStandardId: "", |
| | | unit: "", |
| | | thickness: "", |
| | | quantity: "", |
| | | qualifiedQuantity: null, |
| | | unqualifiedQuantity: null, |
| | | checkCompany: "", |
| | | checkResult: "", |
| | | } |
| | | testStandardOptions.value = []; |
| | | tableData.value = []; |
| | |
| | | const savedTestStandardId = row.testStandardId; |
| | | // 先设置表单数据,但暂时清空 testStandardId,等选项加载完成后再设置 |
| | | form.value = {...row, testStandardId: ''} |
| | | normalizeQuantitiesFromLegacy() |
| | | currentProductId.value = row.productId || 0 |
| | | // 关键:编辑时加载规格型号下拉选项,才能反显 productModelId |
| | | if (currentProductId.value) { |
| | |
| | | const getModels = (value) => { |
| | | form.value.productModelId = undefined; |
| | | form.value.unit = undefined; |
| | | form.value.thickness = undefined; |
| | | modelOptions.value = []; |
| | | currentProductId.value = value |
| | | form.value.productName = findNodeById(productOptions.value, value); |
| | |
| | | }; |
| | | |
| | | const handleChangeModel = (value) => { |
| | | form.value.model = modelOptions.value.find(item => item.id == value)?.model || ''; |
| | | form.value.unit = modelOptions.value.find(item => item.id == value)?.unit || ''; |
| | | const selectedModel = modelOptions.value.find(item => item.id == value); |
| | | form.value.model = selectedModel?.model || ''; |
| | | form.value.unit = selectedModel?.unit || ''; |
| | | form.value.thickness = selectedModel?.thickness ?? ''; |
| | | } |
| | | |
| | | const findNodeById = (nodes, productId) => { |
| | |
| | | const submitForm = () => { |
| | | proxy.$refs.formRef.validate(valid => { |
| | | if (valid) { |
| | | ensureQtyPairInitialized() |
| | | if (!assertQtySplitOrError()) { |
| | | return |
| | | } |
| | | form.value.inspectType = 1 |
| | | const processName = form.value.process || ''; |
| | | if (operationType.value === "add") { |
| | |
| | | |
| | | <style scoped> |
| | | |
| | | :deep(.readonly-display .el-input__wrapper) { |
| | | background-color: var(--el-disabled-bg-color); |
| | | box-shadow: 0 0 0 1px var(--el-disabled-border-color) inset; |
| | | } |
| | | |
| | | :deep(.readonly-display .el-input__inner) { |
| | | color: var(--el-disabled-text-color); |
| | | -webkit-text-fill-color: var(--el-disabled-text-color); |
| | | cursor: not-allowed; |
| | | } |
| | | |
| | | </style> |