| | |
| | | <div> |
| | | <el-dialog |
| | | v-model="dialogFormVisible" |
| | | :title="operationType === 'add' ? '新增不合格管理' : '编辑不合格管理'" |
| | | width="70%" |
| | | :title="operationType === 'add' ? '新增不合格品处理单' : '编辑不合格品处理单'" |
| | | width="80%" |
| | | @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="inspectType"> |
| | | <el-select v-model="form.inspectType"> |
| | | <el-option label="原材料检验" :value="0" /> |
| | | <el-option label="过程检验" :value="1" /> |
| | | <el-option label="出厂检验" :value="2" /> |
| | | </el-select> |
| | | <el-form-item label="项目名称:" prop="projectName"> |
| | | <el-input v-model="form.projectName" placeholder="请输入项目名称" clearable/> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="项目编号:" prop="projectNo"> |
| | | <el-input v-model="form.projectNo" placeholder="请输入项目编号" clearable/> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- 第二行:设备名称、设备图号 --> |
| | | <el-row :gutter="30"> |
| | | <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-form-item label="设备名称:" prop="equipmentName"> |
| | | <el-input v-model="form.equipmentName" placeholder="请输入设备名称" clearable/> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="规格型号:" prop="model"> |
| | | <el-select v-model="form.model" placeholder="请选择" clearable :disabled="operationType === 'edit'" |
| | | filterable readonly @change="handleChangeModel"> |
| | | <el-option v-for="item in modelOptions" :key="item.id" :label="item.model" :value="item.id" /> |
| | | </el-select> |
| | | <el-form-item label="设备图号:" prop="equipmentDrawingNo"> |
| | | <el-input v-model="form.equipmentDrawingNo" placeholder="请输入设备图号" clearable/> |
| | | </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-form-item label="物料/部件名称:" prop="materialName"> |
| | | <el-input v-model="form.materialName" placeholder="请输入物料/部件名称" clearable/> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="物料图号:" prop="materialDrawingNo"> |
| | | <el-input v-model="form.materialDrawingNo" placeholder="请输入物料图号" clearable/> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- 第四行:型号规格、材质、数量、不合格数 --> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="6"> |
| | | <el-form-item label="型号规格:" prop="specificationModel"> |
| | | <el-input v-model="form.specificationModel" placeholder="请输入型号规格" clearable/> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="6"> |
| | | <el-form-item label="材质:" prop="materialQuality"> |
| | | <el-input v-model="form.materialQuality" placeholder="请输入材质" clearable/> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="6"> |
| | | <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="1" :min="0" style="width: 100%" v-model="form.quantity" placeholder="请输入数量" :precision="0"/> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="6"> |
| | | <el-form-item label="不合格数:" prop="unqualifiedQuantity"> |
| | | <el-input-number :step="1" :min="0" style="width: 100%" v-model="form.unqualifiedQuantity" placeholder="请输入不合格数" :precision="0"/> |
| | | </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%"> |
| | | <el-form-item label="不合格工序:" prop="unqualifiedProcess"> |
| | | <el-radio-group v-model="form.unqualifiedProcess"> |
| | | <el-radio :label="1">来料</el-radio> |
| | | <el-radio :label="2">制程</el-radio> |
| | | <el-radio :label="3">成品</el-radio> |
| | | </el-radio-group> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="供货商名称:" prop="supplierName"> |
| | | <el-input v-model="form.supplierName" placeholder="请输入供货商名称" clearable/> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- 第六行:检验员、检验日期、责任人、责任部门 --> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="6"> |
| | | <el-form-item label="检验员:" prop="inspectorName"> |
| | | <el-select v-model="form.inspectorName" placeholder="请选择" clearable style="width: 100%"> |
| | | <el-option v-for="item in userList" :key="item.nickName" :label="item.nickName" :value="item.nickName"/> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="检测日期:" prop="checkTime"> |
| | | <el-col :span="6"> |
| | | <el-form-item label="检验日期:" prop="inspectDate"> |
| | | <el-date-picker |
| | | v-model="form.checkTime" |
| | | v-model="form.inspectDate" |
| | | type="date" |
| | | placeholder="请选择日期" |
| | | value-format="YYYY-MM-DD" |
| | |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="不合格现象:" prop="defectivePhenomena"> |
| | | <el-input v-model="form.defectivePhenomena" placeholder="请输入" clearable/> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="处理结果:" prop="dealResult"> |
| | | <el-select v-model="form.dealResult" placeholder="请选择" clearable> |
| | | <el-option :label="item.label" :value="item.value" v-for="item in rejection_handling" :key="item.value" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="处理人:" prop="dealName"> |
| | | <el-select v-model="form.dealName" placeholder="请选择" clearable style="width: 100%"> |
| | | <el-col :span="6"> |
| | | <el-form-item label="责任人:" prop="responsiblePerson"> |
| | | <el-select v-model="form.responsiblePerson" placeholder="请选择" clearable style="width: 100%"> |
| | | <el-option v-for="item in userList" :key="item.nickName" :label="item.nickName" :value="item.nickName"/> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="处理日期:" prop="dealTime"> |
| | | <el-date-picker |
| | | v-model="form.dealTime" |
| | | type="date" |
| | | placeholder="请选择日期" |
| | | value-format="YYYY-MM-DD" |
| | | format="YYYY-MM-DD" |
| | | <el-col :span="6"> |
| | | <el-form-item label="责任部门:" prop="responsibleDept"> |
| | | <el-input v-model="form.responsibleDept" placeholder="请输入责任部门" clearable/> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- 第七行:问题描述 --> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="24"> |
| | | <el-form-item label="问题描述:" prop="problemDescription"> |
| | | <el-input |
| | | v-model="form.problemDescription" |
| | | type="textarea" |
| | | :rows="3" |
| | | placeholder="请输入问题描述" |
| | | clearable |
| | | style="width: 100%" |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- 第八行:原因分析及建议 --> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="工时损失:" prop="lossWorking"> |
| | | <el-input-number |
| | | v-model="form.lossWorking" |
| | | :min="0" |
| | | :step="0.01" |
| | | :precision="2" |
| | | style="width: 100%" |
| | | placeholder="请输入" |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="材料费损失:" prop="lossMaterial"> |
| | | <el-input-number |
| | | v-model="form.lossMaterial" |
| | | :min="0" |
| | | :step="0.01" |
| | | :precision="2" |
| | | style="width: 100%" |
| | | placeholder="请输入" |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="原因分析:" prop="reasonAnalysis"> |
| | | <el-col :span="24"> |
| | | <el-form-item label="原因分析及建议:" prop="reasonAnalysis"> |
| | | <el-input |
| | | v-model="form.reasonAnalysis" |
| | | type="textarea" |
| | | :rows="4" |
| | | placeholder="请输入" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="预防与纠正措施:" prop="preventiveCorrective"> |
| | | <el-input |
| | | v-model="form.preventiveCorrective" |
| | | type="textarea" |
| | | :rows="4" |
| | | placeholder="请输入" |
| | | placeholder="请输入原因分析及建议" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- 第九行:纠正措施 --> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="24"> |
| | | <el-form-item label="纠正措施:" prop="correctionAction"> |
| | | <el-input |
| | | v-model="form.correctionAction" |
| | | type="textarea" |
| | | :rows="3" |
| | | placeholder="请输入纠正措施" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- 第十行:处置方式 --> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="24"> |
| | | <el-form-item label="处置方式:" prop="disposalMethod"> |
| | | <el-radio-group v-model="form.disposalMethod"> |
| | | <el-radio :label="1">让步接收</el-radio> |
| | | <el-radio :label="2">厂内维修</el-radio> |
| | | <el-radio :label="3">返厂维修</el-radio> |
| | | <el-radio :label="4">换货</el-radio> |
| | | <el-radio :label="5">退货</el-radio> |
| | | <el-radio :label="6">报废</el-radio> |
| | | </el-radio-group> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- 第十一行:厂内/返厂维修评估 --> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="24"> |
| | | <el-form-item label="厂内/返厂维修评估:" prop="repairEvaluation"> |
| | | <el-input |
| | | v-model="form.repairEvaluation" |
| | | type="textarea" |
| | | :rows="3" |
| | | placeholder="请输入厂内/返厂维修评估" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- 第十二行:预防措施 --> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="24"> |
| | | <el-form-item label="预防措施:" prop="preventiveAction"> |
| | | <el-input |
| | | v-model="form.preventiveAction" |
| | | type="textarea" |
| | | :rows="3" |
| | | placeholder="请输入预防措施" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- 第十三行:状态 --> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="24"> |
| | | <el-form-item label="状态:" prop="status"> |
| | | <el-radio-group v-model="form.status"> |
| | | <el-radio :label="0">草稿</el-radio> |
| | | <el-radio :label="1">待审核</el-radio> |
| | | <el-radio :label="2">审批中</el-radio> |
| | | <el-radio :label="3">已完成</el-radio> |
| | | <el-radio :label="4">已驳回</el-radio> |
| | | </el-radio-group> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- 第十四行:备注 --> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="24"> |
| | | <el-form-item label="备注:" prop="remark"> |
| | | <el-input |
| | | v-model="form.remark" |
| | | type="textarea" |
| | | :rows="3" |
| | | placeholder="请输入备注" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- 第十五行:不良品照片 --> |
| | | <el-row :gutter="30"> |
| | | <el-col :span="24"> |
| | | <el-form-item label="不良品照片:" prop="defectivePhotos"> |
| | |
| | | <el-button type="primary" v-if="operationType !== 'view'">上传</el-button> |
| | | <template #tip v-if="operationType !== 'view'"> |
| | | <div class="el-upload__tip"> |
| | | 文件格式支持 doc,docx,xls,xlsx,ppt,pptx,pdf,txt,xml,jpg,jpeg,png,gif,bmp,rar,zip,7z |
| | | 文件格式支持 jpg,jpeg,png,gif,bmp |
| | | </div> |
| | | </template> |
| | | </el-upload> |
| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref, reactive, toRefs, getCurrentInstance, watch } from "vue"; |
| | | import {modelList, productTreeList} from "@/api/basicData/product.js"; |
| | | import { ref, reactive, toRefs, getCurrentInstance } from "vue"; |
| | | import { |
| | | getQualityUnqualifiedInfo, |
| | | qualityUnqualifiedAdd, |
| | |
| | | |
| | | const dialogFormVisible = ref(false); |
| | | const operationType = ref('') |
| | | const { rejection_handling } = proxy.useDict("rejection_handling") |
| | | const defectivePhotoFileList = ref([]); |
| | | const defectivePhotoUploadRef = ref(null); |
| | | const upload = reactive({ |
| | | url: import.meta.env.VITE_APP_BASE_API + "/file/upload", |
| | | headers: { Authorization: "Bearer " + getToken() }, |
| | | }); |
| | | |
| | | const data = reactive({ |
| | | form: { |
| | | checkTime: "", |
| | | process: "", |
| | | checkName: "", |
| | | productName: "", |
| | | productId: "", |
| | | model: "", |
| | | unit: "", |
| | | quantity: "", |
| | | checkCompany: "", |
| | | checkResult: "", |
| | | inspectType: '', |
| | | defectivePhenomena: '', |
| | | // 基本信息 |
| | | projectName: '', |
| | | projectNo: '', |
| | | equipmentName: '', |
| | | equipmentDrawingNo: '', |
| | | materialName: '', |
| | | materialDrawingNo: '', |
| | | specificationModel: '', |
| | | materialQuality: '', |
| | | quantity: 0, |
| | | unqualifiedQuantity: 0, |
| | | unqualifiedProcess: undefined, |
| | | supplierName: '', |
| | | inspectorName: '', |
| | | inspectDate: '', |
| | | responsiblePerson: '', |
| | | responsibleDept: '', |
| | | |
| | | // 问题描述和处理 |
| | | problemDescription: '', |
| | | reasonAnalysis: '', |
| | | correctionAction: '', |
| | | disposalMethod: undefined, |
| | | repairEvaluation: '', |
| | | preventiveAction: '', |
| | | |
| | | // 状态 |
| | | status: 0, |
| | | remark: '', |
| | | |
| | | // 附件 |
| | | defectivePhotos: '', |
| | | tempFileIds: [], |
| | | dealResult: '', |
| | | dealName: '', |
| | | dealTime: '', |
| | | reasonAnalysis: '', |
| | | preventiveCorrective: '', |
| | | lossWorking: 0, |
| | | lossMaterial: 0, |
| | | }, |
| | | rules: { |
| | | checkTime: [{ required: false, message: "请输入", trigger: "blur" },], |
| | | process: [{ required: true, message: "请输入", trigger: "blur" }], |
| | | checkName: [{ required: true, message: "请选择检验员", trigger: "change" }], |
| | | productId: [{ required: true, message: "请输入", trigger: "blur" }], |
| | | model: [{ required: true, message: "请输入", trigger: "blur" }], |
| | | unit: [{ required: false, message: "请输入", trigger: "blur" }], |
| | | quantity: [{ required: true, message: "请输入", trigger: "blur" }], |
| | | checkCompany: [{ required: false, message: "请输入", trigger: "blur" }], |
| | | checkResult: [{ required: false, message: "请输入", trigger: "blur" }], |
| | | dealName: [{ required: true, message: "请选择处理人", trigger: "change" }], |
| | | projectName: [{ required: true, message: "请输入项目名称", trigger: "blur" }], |
| | | materialName: [{ required: true, message: "请输入物料/部件名称", trigger: "blur" }], |
| | | quantity: [{ required: true, message: "请输入数量", trigger: "blur" }], |
| | | unqualifiedQuantity: [{ required: true, message: "请输入不合格数", trigger: "blur" }], |
| | | inspectorName: [{ required: true, message: "请选择检验员", trigger: "change" }], |
| | | inspectDate: [{ required: true, message: "请选择检验日期", trigger: "change" }], |
| | | problemDescription: [{ required: true, message: "请输入问题描述", trigger: "blur" }], |
| | | }, |
| | | }); |
| | | |
| | | const { form, rules } = toRefs(data); |
| | | const productOptions = ref([]); |
| | | const modelOptions = ref([]); |
| | | const userList = ref([]); // 检验员/处理人下拉列表 |
| | | const userList = ref([]); // 检验员/责任人下拉列表 |
| | | |
| | | // 打开弹框 |
| | | const openDialog = async (type, row) => { |
| | |
| | | if (operationType.value === 'add') { |
| | | defectivePhotoFileList.value = []; |
| | | form.value = { |
| | | checkName: userStore.nickName || '', |
| | | dealName: '', |
| | | dealTime: '', |
| | | dealResult: '', |
| | | defectivePhenomena: '', |
| | | projectName: '', |
| | | projectNo: '', |
| | | equipmentName: '', |
| | | equipmentDrawingNo: '', |
| | | materialName: '', |
| | | materialDrawingNo: '', |
| | | specificationModel: '', |
| | | materialQuality: '', |
| | | quantity: 0, |
| | | unqualifiedQuantity: 0, |
| | | unqualifiedProcess: undefined, |
| | | supplierName: '', |
| | | inspectorName: userStore.nickName || '', |
| | | inspectDate: '', |
| | | responsiblePerson: '', |
| | | responsibleDept: '', |
| | | problemDescription: '', |
| | | reasonAnalysis: '', |
| | | correctionAction: '', |
| | | disposalMethod: undefined, |
| | | repairEvaluation: '', |
| | | preventiveAction: '', |
| | | status: 0, |
| | | remark: '', |
| | | defectivePhotos: '', |
| | | tempFileIds: [], |
| | | inspectType: '', |
| | | checkTime: '', |
| | | productId: '', |
| | | model: '', |
| | | unit: '', |
| | | quantity: '', |
| | | productName: '', |
| | | reasonAnalysis: '', |
| | | preventiveCorrective: '', |
| | | lossWorking: 0, |
| | | lossMaterial: 0, |
| | | }; |
| | | } else { |
| | | defectivePhotoFileList.value = []; |
| | | form.value = {}; |
| | | } |
| | | getProductOptions(); |
| | | |
| | | if (operationType.value === 'edit') { |
| | | getQualityUnqualifiedInfo(row.id).then(res => { |
| | | const { inspectState, ...rest } = (res.data || {}) |
| | | form.value = { |
| | | reasonAnalysis: '', |
| | | preventiveCorrective: '', |
| | | lossWorking: 0, |
| | | lossMaterial: 0, |
| | | ...rest |
| | | } |
| | | const data = res.data?.records?.[0] || res.data || {} |
| | | form.value = { ...data } |
| | | }) |
| | | } |
| | | } |
| | | const getProductOptions = () => { |
| | | productTreeList().then((res) => { |
| | | productOptions.value = convertIdToValue(res); |
| | | }); |
| | | }; |
| | | const getModels = (value) => { |
| | | form.value.productName = findNodeById(productOptions.value, value); |
| | | modelList({ id: value }).then((res) => { |
| | | modelOptions.value = res; |
| | | }) |
| | | }; |
| | | 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; // 在子节点中找到,返回该节点 |
| | | } |
| | | } |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | return newItem; |
| | | }); |
| | | } |
| | | |
| | | // 提交产品表单 |
| | | const submitForm = () => { |
| | | proxy.$refs.formRef.validate(valid => { |
| | | if (valid) { |
| | | // 状态字段不在表单填写,也不传给后端 |
| | | const { inspectState, ...payload } = (form.value || {}) |
| | | if (operationType.value === "add") { |
| | | qualityUnqualifiedAdd(payload).then(res => { |
| | | qualityUnqualifiedAdd(form.value).then(res => { |
| | | proxy.$modal.msgSuccess("提交成功"); |
| | | closeDia(); |
| | | }) |
| | | } else { |
| | | qualityUnqualifiedUpdate(payload).then(res => { |
| | | qualityUnqualifiedUpdate(form.value).then(res => { |
| | | proxy.$modal.msgSuccess("提交成功"); |
| | | closeDia(); |
| | | }) |
| | |
| | | }) |
| | | } |
| | | |
| | | // 上传前校检(参考协同审批附件上传) |
| | | // 上传前校检 |
| | | function handleBeforeUpload() { |
| | | proxy.$modal.loading("正在上传文件,请稍候..."); |
| | | return true; |
| | | } |
| | | |
| | | function handleUploadError() { |
| | | proxy.$modal.msgError("上传文件失败"); |
| | | proxy.$modal.closeLoading(); |
| | | } |
| | | // 不良品照片上传成功:保存 tempId 与 tempPath,并回写到表单 |
| | | |
| | | // 不良品照片上传成功 |
| | | function handleDefectivePhotoUploadSuccess(res, file) { |
| | | proxy.$modal.closeLoading(); |
| | | if (res?.code === 200) { |
| | |
| | | if (!form.value.tempFileIds) form.value.tempFileIds = []; |
| | | if (tempId) form.value.tempFileIds.push(tempId); |
| | | |
| | | // el-upload 列表回显需要 url/name |
| | | file.id = tempId || file.id; |
| | | file.url = tempPath; |
| | | file.name = originalName; |
| | | file.url = tempPath ? (import.meta.env.VITE_APP_BASE_API + tempPath) : file.url; |
| | | |
| | | // 以“路径字符串”形式传给新增/编辑接口(后端若只认 tempFileIds 也不冲突) |
| | | syncDefectivePhotosFromFileList(); |
| | | proxy.$modal.msgSuccess("上传成功"); |
| | | } else { |
| | | proxy.$modal.msgError(res?.msg || "上传失败"); |
| | | defectivePhotoUploadRef.value?.handleRemove(file); |
| | | } |
| | | } |
| | | |
| | | function handleDefectivePhotoRemove(file) { |
| | | // 同步移除 tempFileIds |
| | | const tempId = file?.id || file?.response?.data?.tempId; |
| | | if (tempId && Array.isArray(form.value.tempFileIds)) { |
| | | form.value.tempFileIds = form.value.tempFileIds.filter(id => id !== tempId); |
| | | // 不良品照片移除 |
| | | function handleDefectivePhotoRemove(file, fileList) { |
| | | const tempId = file?.response?.data?.tempId; |
| | | if (tempId && form.value.tempFileIds) { |
| | | const idx = form.value.tempFileIds.indexOf(tempId); |
| | | if (idx > -1) form.value.tempFileIds.splice(idx, 1); |
| | | } |
| | | syncDefectivePhotosFromFileList(); |
| | | defectivePhotoFileList.value = fileList; |
| | | } |
| | | |
| | | function syncDefectivePhotosFromFileList() { |
| | | const base = import.meta.env.VITE_APP_BASE_API; |
| | | const paths = (defectivePhotoFileList.value || []) |
| | | .map(f => f?.url || f?.response?.data?.tempPath || f?.response?.data?.url) |
| | | .filter(Boolean) |
| | | .map(url => (typeof url === "string" ? url.replace(base, "") : "")) |
| | | .filter(Boolean); |
| | | form.value.defectivePhotos = paths.join(","); |
| | | } |
| | | |
| | | // 编辑/详情时,把后端返回的 defectivePhotos 路径串转成 el-upload 可回显的 fileList |
| | | watch( |
| | | () => form.value?.defectivePhotos, |
| | | val => { |
| | | if (!val) { |
| | | defectivePhotoFileList.value = []; |
| | | return; |
| | | } |
| | | const base = import.meta.env.VITE_APP_BASE_API; |
| | | const list = String(val) |
| | | .split(",") |
| | | .map((p, idx) => { |
| | | const path = p?.trim(); |
| | | if (!path) return null; |
| | | return { |
| | | name: `图片${idx + 1}`, |
| | | url: path.startsWith("http") ? path : base + path, |
| | | id: undefined, |
| | | }; |
| | | }) |
| | | .filter(Boolean); |
| | | defectivePhotoFileList.value = list; |
| | | }, |
| | | { immediate: true } |
| | | ); |
| | | // 关闭弹框 |
| | | const closeDia = () => { |
| | | defectivePhotoFileList.value = [] |
| | | proxy.resetForm("formRef"); |
| | | dialogFormVisible.value = false; |
| | | emit('close') |
| | | }; |
| | | } |
| | | |
| | | defineExpose({ |
| | | openDialog, |
| | | }); |
| | | }) |
| | | </script> |
| | | |
| | | <style scoped> |
| | | |
| | | </style> |