From ff1169ac5114c68e96c5686a0caa5d69d8a60b8a Mon Sep 17 00:00:00 2001
From: zhouwx <1175765986@qq.com>
Date: 星期五, 12 十二月 2025 16:55:39 +0800
Subject: [PATCH] 修改

---
 src/views/work/selfProblems/internalAudit/problemMng/noConformanceMng/components/editDialog.vue |   91 ++++++++++++++++++++++++++-------------------
 1 files changed, 52 insertions(+), 39 deletions(-)

diff --git a/src/views/work/selfProblems/internalAudit/problemMng/noConformanceMng/components/editDialog.vue b/src/views/work/selfProblems/internalAudit/problemMng/noConformanceMng/components/editDialog.vue
index c292e4e..1cba27c 100644
--- a/src/views/work/selfProblems/internalAudit/problemMng/noConformanceMng/components/editDialog.vue
+++ b/src/views/work/selfProblems/internalAudit/problemMng/noConformanceMng/components/editDialog.vue
@@ -27,14 +27,14 @@
               placeholder="请选择年份"
           />
         </el-form-item>
-        <el-form-item label="文件名称:" prop="inconsistentName">
+        <el-form-item label="不符合项内容:" prop="inconsistentName">
           <el-input v-model.trim="state.form.inconsistentName" :disabled="state.title =='查看'" placeholder="文件名称"></el-input>
         </el-form-item>
         <el-form-item label="文件:" prop="filePath">
           <el-upload accept=".doc,.docx,.pdf,.jpg" :action="state.uploadUrl" :headers="state.header" method="post" :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile)" :on-exceed="showTip" :limit='state.fileLimit' v-model:file-list="state.fileList" :before-upload="picSize" :on-remove="(file, uploadFiles)=>handleRemove(file, uploadFiles)" >
             <el-button type="primary">点击上传</el-button>
             <template #tip>
-              <div class="el-upload__tip">支持上传.doc、.docx、.pdf、.jpg格式,尺寸小于5M,最多可上传1份</div>
+              <div class="el-upload__tip">支持上传.doc、.docx、.pdf、.jpg格式,尺寸小于5M,最多可上传10份</div>
             </template>
           </el-upload>
         </el-form-item>
@@ -81,7 +81,7 @@
     id: null,
     year: '',
     inconsistentName: '',
-    filePath: '',
+    filePath: [],
     format: '',
     companyId: null
   },
@@ -97,7 +97,7 @@
   header: {
     Authorization: getToken()
   },
-  fileLimit: 1,
+  fileLimit: 10,
   fileList: []
 })
 onMounted(() => {
@@ -118,12 +118,26 @@
         state.form[key] = value[key]
       }
     })
-    if(value.filePath) {
-      const obj = {
-        url: value.filePath,
-        name: '模板文件'
-      }
-      state.fileList = [obj]
+    if(!value.filePath || value.filePath == ''){
+      state.form.filePath = []
+    }else{
+      const certificatePaths = value.filePath.split(',')
+      state.form.filePath = certificatePaths
+      state.fileList = certificatePaths.map((path, index) => {
+        const fileName = path.split('/').pop() || `文件${index + 1}`
+        return {
+          name: fileName,
+          url: path,
+          response: {
+            data: {
+              path: path,
+              fileName: fileName
+            }
+          },
+          status: 'success',
+          uid: Date.now() + index
+        }
+      })
     }
   }
   dialogVisible.value = true
@@ -135,6 +149,9 @@
   if(valid){
     if(state.title == '新增'){
       const {id,...data} = state.form
+      data.filePath = state.fileList
+          .filter(file => file.response?.data?.path)
+          .map(file => file.response.data.path).join(',')
       const res = await addSelectInconsistent(data)
       if(res.code == 200){
         ElMessage.success(res.message)
@@ -145,7 +162,11 @@
         ElMessage.warning(res.message)
       }
     }else{
-      const res = await updateSelectInconsistent(state.form)
+      const data = JSON.parse(JSON.stringify(state.form))
+      data.filePath = state.fileList
+          .filter(file => file.response?.data?.path)
+          .map(file => file.response.data.path).join(',')
+      const res = await updateSelectInconsistent(data)
       if(res.code == 200){
         ElMessage.success(res.message)
         emit('getList')
@@ -158,16 +179,18 @@
   }
 }
 
-const handleAvatarSuccess = (res, uploadFile) => {
-  if(res.code == 200){
-    state.form.filePath = res.data.path
-    state.form.format = '.' + res.data.filename.split('.')[1]
-  }else{
-    state.fileList = []
-    ElMessage({
-      type: 'warning',
-      message: '文件上传失败'
-    })
+const handleAvatarSuccess = (response, uploadFile) => {
+  if(response.code === 200){
+    // 设置文件显示名称
+    uploadFile.name = response.data.fileName || `文件${state.fileList.length}`
+    uploadFile.url = response.data.url || response.data.path
+    ElMessage.success('文件上传成功')
+  } else {
+    const index = state.fileList.findIndex(file => file.uid === uploadFile.uid)
+    if (index > -1) {
+      state.fileList.splice(index, 1)
+    }
+    ElMessage.error(response.message || '文件上传失败')
   }
 }
 
@@ -187,24 +210,14 @@
   }
 };
 const handleRemove = async (file, uploadFiles) => {
-  let path = state.form.filePath;
-  await delPic({path: path}).then(res => {
-    if(res.code == 200){
-      // ElMessage({
-      //   type: 'success',
-      //   message: '文件已删除'
-      // })
-      state.form.filePath = ''
-      state.form.format = ''
-    }else{
-      ElMessage({
-        type: 'warning',
-        message: res.message
-      })
+  try {
+    if (file.response?.data?.path) {
+      await delPic({ path: file.response.data.path })
+      ElMessage.success('文件删除成功')
     }
-  }).catch(() => {
-    state.form.imgUrl = ''
-  });
+  } catch (error) {
+    ElMessage.error('文件删除失败')
+  }
 }
 
 const handleClose = () => {
@@ -212,7 +225,7 @@
     id: null,
     year: '',
     inconsistentName: '',
-    filePath: '',
+    filePath: [],
     format: '',
     companyId: null
   }

--
Gitblit v1.9.2