| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <el-dialog |
| | | v-model="dialogFormVisible" |
| | | :title="operationType === 'add' ? 'æ°å¢å·¡æ£è®°å½' : 'ç¼è¾å·¡æ£è®°å½'" |
| | | width="700px" |
| | | @close="closeDia" |
| | | > |
| | | <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef"> |
| | | <el-row :gutter="20"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="å·¥åºï¼" prop="processId"> |
| | | <el-select v-model="form.processId" placeholder="è¯·éæ©å·¥åº" clearable @change="handleProcessChange" style="width: 100%"> |
| | | <el-option |
| | | v-for="item in processList" |
| | | :key="item.id" |
| | | :label="item.processName || item.name" |
| | | :value="item.id" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="å·¡æ£æ¶é´ï¼" prop="inspectionTime"> |
| | | <el-date-picker |
| | | v-model="form.inspectionTime" |
| | | value-format="YYYY-MM-DD HH:mm:ss" |
| | | format="YYYY-MM-DD HH:mm:ss" |
| | | type="datetime" |
| | | placeholder="è¯·éæ©å·¡æ£æ¶é´" |
| | | style="width: 100%" |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="20"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="å·¡æ£åï¼" prop="inspector"> |
| | | <el-input v-model="form.inspector" placeholder="请è¾å
¥å·¡æ£å" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="æ£æµé¡¹ï¼" prop="inspectionItem"> |
| | | <el-select v-model="form.inspectionItem" placeholder="è¯·éæ©æ£æµé¡¹" clearable @change="handleInspectionItemChange" style="width: 100%"> |
| | | <el-option v-for="item in inspectionItemList" :key="item.parameterItem" :label="item.parameterItem" :value="item.parameterItem" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="20"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="æ åè¦æ±ï¼" prop="standardRequirement"> |
| | | <el-input v-model="form.standardRequirement" placeholder="æ åè¦æ±" readonly /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="宿µå¼ï¼" prop="actualValue"> |
| | | <el-input v-model="form.actualValue" placeholder="请è¾å
¥å®æµå¼" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="20"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="å¤å®ï¼" prop="judgement"> |
| | | <el-select v-model="form.judgement" placeholder="è¯·éæ©" clearable style="width: 100%"> |
| | | <el-option label="åæ ¼" value="yes" /> |
| | | <el-option label="ä¸åæ ¼" value="no" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="ä¸åæ ¼è®¢åï¼" prop="unqualifiedOrder"> |
| | | <el-input v-model="form.unqualifiedOrder" placeholder="请è¾å
¥ä¸åæ ¼è®¢å" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="20"> |
| | | <el-col :span="24"> |
| | | <el-form-item label="夿³¨ï¼" prop="remark"> |
| | | <el-input v-model="form.remark" type="textarea" :rows="3" placeholder="请è¾å
¥å¤æ³¨" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | </el-form> |
| | | <template #footer> |
| | | <div class="dialog-footer"> |
| | | <el-button type="primary" @click="submitForm">确认</el-button> |
| | | <el-button @click="closeDia">åæ¶</el-button> |
| | | </div> |
| | | </template> |
| | | </el-dialog> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref, reactive } from "vue"; |
| | | import { ElMessage } from "element-plus"; |
| | | import { addProductInspectionRecord, updProductInspectionRecord, getParameterItemByProcessOrCategory } from "@/api/qualityManagement/productInspectionRecord.js"; |
| | | import { processList as getProcessList } from "@/api/productionManagement/productionProcess.js"; |
| | | import useUserStore from "@/store/modules/user"; |
| | | |
| | | const userStore = useUserStore(); |
| | | const dialogFormVisible = ref(false); |
| | | const operationType = ref("add"); |
| | | const formRef = ref(null); |
| | | |
| | | const form = reactive({ |
| | | id: undefined, |
| | | processId: undefined, |
| | | process: "", |
| | | checkDate: undefined, |
| | | inspector: "", |
| | | inspectionTime: undefined, |
| | | inspectionItem: "", |
| | | standardRequirement: "", |
| | | actualValue: "", |
| | | judgement: "", |
| | | unqualifiedOrder: "", |
| | | remark: "", |
| | | createUser: "", |
| | | createTime: undefined, |
| | | }); |
| | | |
| | | const processList = ref([]); |
| | | const inspectionItemList = ref([]); |
| | | |
| | | /** å·¥åº id ä¸å端å¯è½ä¸º number/stringï¼ç»ä¸æ¯è¾ */ |
| | | const sameProcessId = (a, b) => a != null && b != null && String(a) === String(b); |
| | | |
| | | /** ä»å·¥åºå表åä¸ row å¹é
ç idï¼ä¿è¯ä¸ el-option ç value ç±»åä¸è´ï¼é¿å
åæ¾æçº¯æ°åï¼ */ |
| | | const resolveProcessIdFromRow = (row) => { |
| | | let pid = row.processId ?? row.process_id; |
| | | if (pid != null && pid !== "") { |
| | | const hit = processList.value.find((item) => sameProcessId(item.id, pid)); |
| | | return hit ? hit.id : pid; |
| | | } |
| | | // é¨åæ¥å£æå·¥åº id åå¨ process åæ®µé |
| | | const p = row.process; |
| | | if (p != null && p !== "" && /^\d+$/.test(String(p).trim())) { |
| | | const hit = processList.value.find((item) => sameProcessId(item.id, p)); |
| | | return hit ? hit.id : p; |
| | | } |
| | | return undefined; |
| | | }; |
| | | |
| | | const getProcessLabel = (item) => item?.processName || item?.name || ""; |
| | | |
| | | const rules = { |
| | | processId: [{ required: true, message: "è¯·éæ©å·¥åº", trigger: "change" }], |
| | | checkDate: [{ required: true, message: "è¯·éæ©å·¡æ£æ¥æ", trigger: "change" }], |
| | | }; |
| | | |
| | | const loadProcessList = async () => { |
| | | try { |
| | | const res = await getProcessList({ current: 1, size: 1000 }); |
| | | processList.value = res.data || []; |
| | | } catch (error) { |
| | | console.error("å 载工åºå表失败", error); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * @param processId å·¥åº id |
| | | * @param options.preserveInspection 为 true æ¶ä¿çå·²ææ£æµé¡¹/æ åï¼ç¼è¾åæ¾ï¼ |
| | | */ |
| | | const handleProcessChange = async (processId, options = {}) => { |
| | | const { preserveInspection = false } = options; |
| | | |
| | | if (!preserveInspection) { |
| | | form.process = ""; |
| | | form.inspectionItem = ""; |
| | | form.standardRequirement = ""; |
| | | } |
| | | inspectionItemList.value = []; |
| | | |
| | | if (!processId) { |
| | | return; |
| | | } |
| | | const process = processList.value.find((item) => sameProcessId(item.id, processId)); |
| | | if (process) { |
| | | form.process = getProcessLabel(process); |
| | | } |
| | | |
| | | try { |
| | | const { data } = await getParameterItemByProcessOrCategory({ |
| | | id: processId, |
| | | inspectType: 3, |
| | | }); |
| | | if (data && data.length > 0) { |
| | | inspectionItemList.value = data; |
| | | if (preserveInspection && form.inspectionItem) { |
| | | const cur = data.find((i) => i.parameterItem === form.inspectionItem); |
| | | form.standardRequirement = cur?.standardValue ?? form.standardRequirement ?? ""; |
| | | } else { |
| | | const firstItem = data[0]; |
| | | form.inspectionItem = firstItem.parameterItem; |
| | | form.standardRequirement = firstItem.standardValue || ""; |
| | | } |
| | | } |
| | | } catch (error) { |
| | | console.error("å è½½æ£æµé¡¹ç®å¤±è´¥", error); |
| | | } |
| | | }; |
| | | |
| | | const handleInspectionItemChange = (val) => { |
| | | if (!val) { |
| | | form.standardRequirement = ""; |
| | | return; |
| | | } |
| | | const item = inspectionItemList.value.find(i => i.parameterItem === val); |
| | | if (item) { |
| | | form.standardRequirement = item.standardValue || ""; |
| | | } |
| | | }; |
| | | |
| | | const open = async (type, row) => { |
| | | operationType.value = type; |
| | | await loadProcessList(); |
| | | if (type === "edit" && row) { |
| | | Object.assign(form, row); |
| | | const resolvedId = resolveProcessIdFromRow(row); |
| | | if (resolvedId != null && resolvedId !== "") { |
| | | form.processId = resolvedId; |
| | | const processItem = processList.value.find((item) => sameProcessId(item.id, resolvedId)); |
| | | if (processItem) { |
| | | form.process = getProcessLabel(processItem); |
| | | } else if (row.process && !/^\d+$/.test(String(row.process).trim())) { |
| | | form.process = row.process; |
| | | } |
| | | } |
| | | if (form.processId != null && form.processId !== "") { |
| | | await handleProcessChange(form.processId, { preserveInspection: true }); |
| | | } |
| | | } else { |
| | | resetForm(); |
| | | } |
| | | dialogFormVisible.value = true; |
| | | }; |
| | | |
| | | const formatDateTime = () => { |
| | | const now = new Date(); |
| | | const year = now.getFullYear(); |
| | | const month = String(now.getMonth() + 1).padStart(2, '0'); |
| | | const day = String(now.getDate()).padStart(2, '0'); |
| | | const hours = String(now.getHours()).padStart(2, '0'); |
| | | const minutes = String(now.getMinutes()).padStart(2, '0'); |
| | | const seconds = String(now.getSeconds()).padStart(2, '0'); |
| | | return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; |
| | | }; |
| | | |
| | | const resetForm = () => { |
| | | form.id = undefined; |
| | | form.processId = undefined; |
| | | form.process = ""; |
| | | form.checkDate = undefined; |
| | | form.inspector = ""; |
| | | form.inspectionTime = formatDateTime(); |
| | | form.inspectionItem = ""; |
| | | form.standardRequirement = ""; |
| | | form.actualValue = ""; |
| | | form.judgement = ""; |
| | | form.unqualifiedOrder = ""; |
| | | form.remark = ""; |
| | | form.createUser = ""; |
| | | form.createTime = undefined; |
| | | inspectionItemList.value = []; |
| | | }; |
| | | |
| | | const closeDia = () => { |
| | | dialogFormVisible.value = false; |
| | | resetForm(); |
| | | }; |
| | | |
| | | const submitForm = async () => { |
| | | const valid = await formRef.value.validate().catch(() => false); |
| | | if (!valid) return; |
| | | const p = processList.value.find((item) => sameProcessId(item.id, form.processId)); |
| | | form.process = getProcessLabel(p); |
| | | |
| | | try { |
| | | if (operationType.value === "add") { |
| | | await addProductInspectionRecord(form); |
| | | ElMessage.success("æ°å¢æå"); |
| | | } else { |
| | | await updProductInspectionRecord(form); |
| | | ElMessage.success("ä¿®æ¹æå"); |
| | | } |
| | | closeDia(); |
| | | emit("close"); |
| | | } catch (error) { |
| | | console.error(error); |
| | | } |
| | | }; |
| | | |
| | | const emit = defineEmits(["close"]); |
| | | |
| | | defineExpose({ |
| | | open, |
| | | }); |
| | | </script> |
| | | |
| | | <style scoped> |
| | | </style> |