| | |
| | | <template> |
| | | <div> |
| | | <el-dialog |
| | | v-model="dialogFormVisible" |
| | | :title="operationType === 'add' ? '新增原材料检验' : '编辑原材料检验'" |
| | | width="70%" |
| | | @close="closeDia" |
| | | > |
| | | <el-dialog v-model="dialogFormVisible" :title="operationType === 'add' ? '新增原材料检验' : '编辑原材料检验'" width="70%" |
| | | @close="closeDia"> |
| | | <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef"> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="供应商:" prop="supplier"> |
| | | <el-select |
| | | v-model="form.supplier" |
| | | placeholder="请选择" |
| | | clearable |
| | | > |
| | | <el-option |
| | | v-for="item in supplierList" |
| | | :key="item.id" |
| | | :label="item.supplierName" |
| | | :value="item.supplierName" |
| | | /> |
| | | <el-select v-model="form.supplier" placeholder="请选择" clearable :disabled="operationType === 'edit'" |
| | | filterable readonly> |
| | | <el-option v-for="item in supplierList" :key="item.id" :label="item.supplierName" |
| | | :value="item.supplierName" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="产品名称:" prop="productId"> |
| | | <el-tree-select |
| | | v-model="form.productId" |
| | | placeholder="请选择" |
| | | clearable |
| | | check-strictly |
| | | @change="getModels" |
| | | :data="productOptions" |
| | | :render-after-expand="false" |
| | | style="width: 100%" |
| | | /> |
| | | <el-tree-select v-model="form.productId" placeholder="请选择" clearable :disabled="operationType === 'edit'" |
| | | check-strictly @change="getModels" :data="productOptions" |
| | | :props="{ label: 'label', value: 'value', children: 'children' }" node-key="value" |
| | | :render-after-expand="false" style="width: 100%" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="规格型号:" prop="model"> |
| | | <el-input v-model="form.model" placeholder="请输入" clearable/> |
| | | <el-form-item label="规格型号:" prop="productModelId"> |
| | | <el-select v-model="form.productModelId" placeholder="请选择" clearable :disabled="operationType === 'edit'" |
| | | filterable readonly> |
| | | <el-option v-for="item in modelOptions" :key="item.id" :label="item.model" :value="item.id" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="单位:" prop="unit"> |
| | | <el-input v-model="form.unit" placeholder="请输入" clearable/> |
| | | <el-input v-model="form.unit" :disabled="operationType === 'edit'" placeholder="请输入" clearable /> |
| | | </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-input-number :step="0.01" :min="0" :disabled="operationType === 'edit'" style="width: 100%" |
| | | v-model="form.quantity" placeholder="请输入" clearable :precision="2" /> |
| | | </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" placeholder="请输入" clearable/> |
| | | <el-input v-model="form.checkCompany" placeholder="请输入" clearable /> |
| | | </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-option label="合格" value="合格" /> |
| | | <el-option label="不合格" value="不合格" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row v-if="form.checkResult == '不合格'" :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="不合格现象:" prop="checkCompany"> |
| | | <el-input v-model="form.defectivePhenomena" placeholder="请输入" clearable /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="检验员:" prop="checkName"> |
| | | <el-input v-model="form.checkName" placeholder="请输入" clearable/> |
| | | |
| | | <el-input v-model="form.checkName" placeholder="请输入" clearable /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="检测日期:" prop="checkTime"> |
| | | <el-date-picker |
| | | v-model="form.checkTime" |
| | | type="date" |
| | | placeholder="请选择日期" |
| | | value-format="YYYY-MM-DD" |
| | | format="YYYY-MM-DD" |
| | | clearable |
| | | style="width: 100%" |
| | | /> |
| | | <el-date-picker v-model="form.checkTime" type="date" placeholder="请选择日期" value-format="YYYY-MM-DD" |
| | | format="YYYY-MM-DD" clearable style="width: 100%" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | </el-form> |
| | | <div style="margin-bottom: 10px;text-align: right"> |
| | | <el-button type="danger" plain @click="handleDelete">删除</el-button> |
| | | </div> |
| | | <PIMTable |
| | | rowKey="id" |
| | | :column="tableColumn" |
| | | :tableData="tableData" |
| | | :tableLoading="tableLoading" |
| | | :isSelection="true" |
| | | @selection-change="handleSelectionChange" |
| | | height="400" |
| | | > |
| | | <!-- <div style="margin-bottom: 10px;text-align: right">--> |
| | | <!-- <el-button type="danger" plain @click="handleDelete">删除</el-button>--> |
| | | <!-- </div>--> |
| | | <PIMTable rowKey="id" :column="tableColumn" :tableData="tableData" :tableLoading="tableLoading" height="400"> |
| | | <template #slot="{ row }"> |
| | | <el-input v-model="row.testValue" clearable/> |
| | | <el-input v-model="row.testValue" clearable /> |
| | | </template> |
| | | </PIMTable> |
| | | <template #footer> |
| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import {ref} from "vue"; |
| | | import {getOptions} from "@/api/procurementManagement/procurementLedger.js"; |
| | | import {productTreeList} from "@/api/basicData/product.js"; |
| | | import {qualityInspectAdd, qualityInspectUpdate} from "@/api/qualityManagement/rawMaterialInspection.js"; |
| | | import {ElMessageBox} from "element-plus"; |
| | | import {qualityInspectParamDel, qualityInspectParamInfo} from "@/api/qualityManagement/qualityInspectParam.js"; |
| | | import {qualityInspectDetailByProductId} from "@/api/qualityManagement/metricMaintenance.js"; |
| | | import { ref, reactive, toRefs, nextTick, getCurrentInstance, 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"; |
| | | import { |
| | | qualityInspectParamInfo, |
| | | } from "@/api/qualityManagement/qualityInspectParam.js"; |
| | | import { qualityInspectDetailByProductId } from "@/api/qualityManagement/metricMaintenance.js"; |
| | | |
| | | const {proxy} = getCurrentInstance() |
| | | const emit = defineEmits(['close']) |
| | | const { proxy } = getCurrentInstance(); |
| | | const emit = defineEmits(["close"]); |
| | | |
| | | const dialogFormVisible = ref(false); |
| | | const operationType = ref('') |
| | | const operationType = ref(""); |
| | | const tableLoading = ref(false); |
| | | const isInitializing = ref(false); |
| | | const currentProductId = ref(null); |
| | | |
| | | const data = reactive({ |
| | | form: { |
| | | checkTime: "", |
| | |
| | | checkName: "", |
| | | productName: "", |
| | | productId: "", |
| | | model: "", |
| | | productModelId: undefined, |
| | | unit: "", |
| | | quantity: "", |
| | | checkCompany: "", |
| | | checkResult: "", |
| | | defectivePhenomena: "", |
| | | }, |
| | | rules: { |
| | | checkTime: [{required: false, message: "请输入", trigger: "blur"},], |
| | | supplier: [{required: true, message: "请输入", trigger: "blur"}], |
| | | checkName: [{required: false, message: "请输入", trigger: "blur"}], |
| | | productId: [{required: true, message: "请输入", trigger: "blur"}], |
| | | model: [{required: false, message: "请输入", trigger: "blur"}], |
| | | unit: [{required: false, message: "请输入", trigger: "blur"}], |
| | | quantity: [{required: true, message: "请输入", trigger: "blur"}], |
| | | checkCompany: [{required: false, message: "请输入", trigger: "blur"}], |
| | | checkResult: [{required: true, message: "请选择检测结果", trigger: "change"}], |
| | | checkTime: [{ required: true, message: "请输入", trigger: "blur" }], |
| | | supplier: [{ required: true, message: "请输入", trigger: "blur" }], |
| | | productId: [{ required: true, message: "请选择", trigger: "change" }], |
| | | quantity: [{ required: true, message: "请输入", trigger: "blur" }], |
| | | checkResult: [{ required: true, message: "请选择检测结果", trigger: "change" }], |
| | | }, |
| | | }); |
| | | |
| | | const { form, rules } = toRefs(data); |
| | | |
| | | const supplierList = ref([]); |
| | | const productOptions = ref([]); |
| | | const modelOptions = ref([]); |
| | | const tableData = ref([]); |
| | | |
| | | const tableColumn = ref([ |
| | | { |
| | | label: "指标", |
| | | prop: "parameterItem", |
| | | }, |
| | | { |
| | | label: "单位", |
| | | prop: "unit", |
| | | }, |
| | | { |
| | | label: "标准值", |
| | | prop: "standardValue", |
| | | }, |
| | | { |
| | | label: "内控值", |
| | | prop: "controlValue", |
| | | }, |
| | | { label: "指标", prop: "parameterItem" }, |
| | | { label: "单位", prop: "unit" }, |
| | | { label: "标准值", prop: "standardValue" }, |
| | | { label: "内控值", prop: "controlValue" }, |
| | | { |
| | | label: "检验值", |
| | | prop: "testValue", |
| | | dataType: 'slot', |
| | | slot: 'slot', |
| | | dataType: "slot", |
| | | slot: "slot", |
| | | }, |
| | | ]); |
| | | const tableData = ref([]); |
| | | const tableLoading = ref(false); |
| | | |
| | | const {form, rules} = toRefs(data); |
| | | const supplierList = ref([]); |
| | | const productOptions = ref([]); |
| | | const currentProductId = ref(0); |
| | | |
| | | // 打开弹框 |
| | | const openDialog = (type, row) => { |
| | | // 打开弹窗 |
| | | const openDialog = async (type, row) => { |
| | | operationType.value = type; |
| | | dialogFormVisible.value = true; |
| | | getOptions().then((res) => { |
| | | supplierList.value = res.data; |
| | | isInitializing.value = true; |
| | | |
| | | // 重置 |
| | | tableData.value = []; |
| | | currentProductId.value = null; |
| | | Object.assign(form.value, { |
| | | checkTime: "", |
| | | supplier: "", |
| | | checkName: "", |
| | | productName: "", |
| | | productId: "", |
| | | productModelId: undefined, |
| | | unit: "", |
| | | quantity: "", |
| | | checkCompany: "", |
| | | checkResult: "", |
| | | defectivePhenomena: "", |
| | | }); |
| | | getProductOptions(); |
| | | if (operationType.value === 'edit') { |
| | | form.value = {...row} |
| | | currentProductId.value = row.productId || 0 |
| | | getQualityInspectParamList(row.id) |
| | | |
| | | await nextTick(); |
| | | |
| | | try { |
| | | const [optionsRes, productTreeRes] = await Promise.all([ |
| | | getOptions(), |
| | | productTreeList(), |
| | | ]); |
| | | |
| | | supplierList.value = optionsRes.data; |
| | | productOptions.value = convertIdToValue(productTreeRes); |
| | | |
| | | if (type === "edit") { |
| | | currentProductId.value = row.productId; |
| | | Object.assign(form.value, row); |
| | | |
| | | // 加载型号,但不触发指标 |
| | | await getModels(row.productId, true); |
| | | |
| | | // 加载已保存的质检参数 |
| | | await getQualityInspectParamList(row.id); |
| | | } |
| | | } finally { |
| | | // 👇 初始化完成 |
| | | isInitializing.value = false; |
| | | } |
| | | } |
| | | const getProductOptions = () => { |
| | | productTreeList().then((res) => { |
| | | productOptions.value = convertIdToValue(res); |
| | | }); |
| | | }; |
| | | const getModels = (value) => { |
| | | currentProductId.value = value |
| | | form.value.productName = findNodeById(productOptions.value, value); |
| | | if (currentProductId) { |
| | | |
| | | // 产品型号 |
| | | const getModels = async (productId, skipList = false) => { |
| | | if (!productId) return; |
| | | |
| | | currentProductId.value = productId; |
| | | if (!skipList) { |
| | | form.value.productModelId = undefined; |
| | | } |
| | | |
| | | form.value.productName = findNodeById(productOptions.value, productId); |
| | | |
| | | const res = await modelList({ id: productId }); |
| | | modelOptions.value = res; |
| | | |
| | | // add 场景:立即加载指标 |
| | | if (!skipList && !isInitializing.value) { |
| | | getList(); |
| | | } |
| | | }; |
| | | const findNodeById = (nodes, productId) => { |
| | | for (let i = 0; i < nodes.length; i++) { |
| | | if (nodes[i].value === productId) { |
| | | return nodes[i].label; // 找到节点,返回该节点 |
| | | } |
| | | if (nodes[i].children && nodes[i].children.length > 0) { |
| | | const foundNode = findNodeById(nodes[i].children, productId); |
| | | if (foundNode) { |
| | | return foundNode; // 在子节点中找到,返回该节点 |
| | | } |
| | | } |
| | | |
| | | // 拉指标 |
| | | const getList = async () => { |
| | | console.log("getList执行"); |
| | | |
| | | if (!currentProductId.value || isInitializing.value) return; |
| | | |
| | | tableLoading.value = true; |
| | | try { |
| | | const res = await qualityInspectDetailByProductId(currentProductId.value); |
| | | tableData.value = res.data || []; |
| | | } finally { |
| | | tableLoading.value = false; |
| | | } |
| | | return null; // 没有找到节点,返回null |
| | | }; |
| | | |
| | | function convertIdToValue(data) { |
| | | return data.map((item) => { |
| | | const {id, children, ...rest} = item; |
| | | const newItem = { |
| | | ...rest, |
| | | value: id, // 将 id 改为 value |
| | | }; |
| | | if (children && children.length > 0) { |
| | | newItem.children = convertIdToValue(children); |
| | | } |
| | | // edit 初始化完成后触发一次 |
| | | watch(isInitializing, (val) => { |
| | | if ( |
| | | val === false && |
| | | operationType.value === "edit" && |
| | | currentProductId.value |
| | | ) { |
| | | getList(); |
| | | } |
| | | }); |
| | | |
| | | return newItem; |
| | | }); |
| | | } |
| | | // 回填参数 |
| | | const getQualityInspectParamList = async (id) => { |
| | | tableLoading.value = true; |
| | | try { |
| | | const res = await qualityInspectParamInfo(id); |
| | | tableData.value = res.data || []; |
| | | } finally { |
| | | tableLoading.value = false; |
| | | } |
| | | }; |
| | | |
| | | // 提交产品表单 |
| | | // 提交 |
| | | const submitForm = () => { |
| | | proxy.$refs.formRef.validate(valid => { |
| | | if (valid) { |
| | | form.value.inspectType = 0 |
| | | const data = {...form.value, qualityInspectParams: tableData.value} |
| | | if (operationType.value === "add") { |
| | | qualityInspectAdd(data).then(res => { |
| | | proxy.$modal.msgSuccess("提交成功"); |
| | | closeDia(); |
| | | }) |
| | | } else { |
| | | qualityInspectUpdate(data).then(res => { |
| | | proxy.$modal.msgSuccess("提交成功"); |
| | | closeDia(); |
| | | }) |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | |
| | | const handleSelectionChange = (selection) => { |
| | | selectedRows.value = selection; |
| | | }; |
| | | |
| | | const handleDelete = () => { |
| | | let ids = []; |
| | | if (selectedRows.value.length > 0) { |
| | | ids = selectedRows.value.map((item) => item.id); |
| | | } else { |
| | | proxy.$modal.msgWarning("请选择数据"); |
| | | return; |
| | | if (form.value.checkResult === "合格") { |
| | | form.value.defectivePhenomena = ""; |
| | | } |
| | | ElMessageBox.confirm("选中的内容将被删除,是否确认删除?", "导出", { |
| | | confirmButtonText: "确认", |
| | | cancelButtonText: "取消", |
| | | type: "warning", |
| | | }) |
| | | .then(() => { |
| | | qualityInspectParamDel(ids).then((res) => { |
| | | proxy.$modal.msgSuccess("删除成功"); |
| | | getList(); |
| | | }); |
| | | }) |
| | | .catch(() => { |
| | | proxy.$modal.msg("已取消"); |
| | | }); |
| | | |
| | | proxy.$refs.formRef.validate(async (valid) => { |
| | | if (!valid) return; |
| | | |
| | | form.value.inspectType = 0; |
| | | if (operationType.value === "add") { |
| | | tableData.value.forEach((i) => delete i.id); |
| | | } |
| | | |
| | | const submitData = { |
| | | ...form.value, |
| | | qualityInspectParams: tableData.value, |
| | | }; |
| | | |
| | | const api = |
| | | operationType.value === "add" |
| | | ? qualityInspectAdd |
| | | : qualityInspectUpdate; |
| | | |
| | | await api(submitData); |
| | | proxy.$modal.msgSuccess("提交成功"); |
| | | closeDia(); |
| | | }); |
| | | }; |
| | | |
| | | const getList = () => { |
| | | qualityInspectDetailByProductId(currentProductId.value).then(res => { |
| | | tableData.value = res.data; |
| | | }) |
| | | } |
| | | |
| | | const getQualityInspectParamList = (id) => { |
| | | qualityInspectParamInfo(id).then(res => { |
| | | tableData.value = res.data; |
| | | }) |
| | | } |
| | | // 关闭弹框 |
| | | // 关闭 |
| | | const closeDia = () => { |
| | | proxy.resetForm("formRef"); |
| | | tableData.value = [] |
| | | tableData.value = []; |
| | | dialogFormVisible.value = false; |
| | | emit('close') |
| | | emit("close"); |
| | | }; |
| | | defineExpose({ |
| | | openDialog, |
| | | }); |
| | | |
| | | function findNodeById(list, id) { |
| | | for (const item of list) { |
| | | if (item.value === id) return item.label; |
| | | if (item.children) { |
| | | const res = findNodeById(item.children, id); |
| | | if (res) return res; |
| | | } |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | function convertIdToValue(data = []) { |
| | | return data.map((item) => ({ |
| | | label: item.productName, |
| | | value: item.id, |
| | | children: item.children ? convertIdToValue(item.children) : [], |
| | | })); |
| | | } |
| | | |
| | | defineExpose({ openDialog }); |
| | | </script> |
| | | |
| | | <style scoped> |
| | | |
| | | </style> |
| | | <style scoped></style> |