yanghao 1 месяц назад
Родитель
Сommit
1353e985b1
1 измененных файлов с 54 добавлено и 9 удалено
  1. 54 9
      src/views/technology‌/list/index2.vue

+ 54 - 9
src/views/technology‌/list/index2.vue

@@ -309,11 +309,27 @@
           placeholder="请输入应用场景和优势"
           placeholder="请输入应用场景和优势"
         />
         />
       </el-form-item>
       </el-form-item>
-      <el-form-item label="专利附件" prop="attachments">
+      <el-form-item label="专利文件">
         <UploadFile
         <UploadFile
           :file-type="['doc', 'docx', 'pdf', 'jpg', 'png', 'jpeg']"
           :file-type="['doc', 'docx', 'pdf', 'jpg', 'png', 'jpeg']"
           :return-object="true"
           :return-object="true"
-          v-model="formData.attachments"
+          v-model="patentAttachments"
+          :limit="10"
+        />
+      </el-form-item>
+      <el-form-item label="论文文件">
+        <UploadFile
+          :file-type="['doc', 'docx', 'pdf', 'jpg', 'png', 'jpeg']"
+          :return-object="true"
+          v-model="paperAttachments"
+          :limit="10"
+        />
+      </el-form-item>
+      <el-form-item label="其他资料">
+        <UploadFile
+          :file-type="['doc', 'docx', 'pdf', 'jpg', 'png', 'jpeg']"
+          :return-object="true"
+          v-model="otherMaterialAttachments"
           :limit="10"
           :limit="10"
         />
         />
       </el-form-item>
       </el-form-item>
@@ -396,6 +412,9 @@ const deptList2 = ref<Tree[]>([])
 const formType = ref<'create' | 'update'>('create')
 const formType = ref<'create' | 'update'>('create')
 const formRef = ref()
 const formRef = ref()
 const queryFormRef = ref()
 const queryFormRef = ref()
+const patentAttachments = ref<any[]>([])
+const paperAttachments = ref<any[]>([])
+const otherMaterialAttachments = ref<any[]>([])
 
 
 const queryParams = reactive({
 const queryParams = reactive({
   pageNo: 1,
   pageNo: 1,
@@ -418,7 +437,6 @@ const createDefaultForm = () => ({
   summary: '',
   summary: '',
   principles: '',
   principles: '',
   advantages: '',
   advantages: '',
-  attachments: [],
   details: [] as Array<{ progressDate: string | number; overview: string }>
   details: [] as Array<{ progressDate: string | number; overview: string }>
 })
 })
 
 
@@ -445,16 +463,22 @@ const getDeptName = (departmentId?: number) => {
   return findDept(deptList2.value) || String(departmentId)
   return findDept(deptList2.value) || String(departmentId)
 }
 }
 
 
-const normalizeAttachments = (attachments: unknown): any[] => {
+const normalizeAttachments = (attachments: unknown, type?: string): any[] => {
   if (!attachments) return []
   if (!attachments) return []
   const values = Array.isArray(attachments) ? attachments : [attachments]
   const values = Array.isArray(attachments) ? attachments : [attachments]
   return values
   return values
     .flatMap((attachment: any) => {
     .flatMap((attachment: any) => {
-      if (typeof attachment === 'string') return attachment.split(',')
+      if (typeof attachment === 'string') {
+        return attachment
+          .split(',')
+          .map((filePath) => filePath.trim())
+          .filter(Boolean)
+          .map((filePath) => (type ? { filePath, type } : filePath))
+      }
       if (attachment && typeof attachment === 'object') {
       if (attachment && typeof attachment === 'object') {
         const filePath =
         const filePath =
           attachment.filePath || attachment.path || attachment.url || attachment.fileUrl
           attachment.filePath || attachment.path || attachment.url || attachment.fileUrl
-        return filePath ? [{ ...attachment, filePath }] : []
+        return filePath ? [{ ...attachment, filePath, ...(type ? { type } : {}) }] : []
       }
       }
       return []
       return []
     })
     })
@@ -463,6 +487,23 @@ const normalizeAttachments = (attachments: unknown): any[] => {
     )
     )
 }
 }
 
 
+const splitAttachments = (attachments: unknown) => {
+  const values = normalizeAttachments(attachments)
+  patentAttachments.value = values.filter(
+    (attachment) => !attachment.type || attachment.type === 'PATENT'
+  )
+  paperAttachments.value = values.filter((attachment) => attachment.type === 'PAPER')
+  otherMaterialAttachments.value = values.filter(
+    (attachment) => attachment.type === 'OTHER_MATERIAL'
+  )
+}
+
+const getAttachments = () => [
+  ...normalizeAttachments(patentAttachments.value, 'PATENT'),
+  ...normalizeAttachments(paperAttachments.value, 'PAPER'),
+  ...normalizeAttachments(otherMaterialAttachments.value, 'OTHER_MATERIAL')
+]
+
 const getList = async () => {
 const getList = async () => {
   loading.value = true
   loading.value = true
   try {
   try {
@@ -501,6 +542,9 @@ const openForm = async (type: 'create' | 'update', id?: number) => {
   dialogTitle.value = type === 'create' ? '新增核心技术' : '编辑核心技术'
   dialogTitle.value = type === 'create' ? '新增核心技术' : '编辑核心技术'
   if (type === 'create') {
   if (type === 'create') {
     formData.value = createDefaultForm()
     formData.value = createDefaultForm()
+    patentAttachments.value = []
+    paperAttachments.value = []
+    otherMaterialAttachments.value = []
     dialogVisible.value = true
     dialogVisible.value = true
     return
     return
   }
   }
@@ -511,9 +555,9 @@ const openForm = async (type: 'create' | 'update', id?: number) => {
     formData.value = {
     formData.value = {
       ...createDefaultForm(),
       ...createDefaultForm(),
       ...data,
       ...data,
-      attachments: normalizeAttachments(data.attachments),
       details: Array.isArray(data.details) ? data.details : []
       details: Array.isArray(data.details) ? data.details : []
     }
     }
+    splitAttachments(data.attachments)
     dialogVisible.value = true
     dialogVisible.value = true
   } finally {
   } finally {
     loading.value = false
     loading.value = false
@@ -537,11 +581,12 @@ const submitForm = () => {
     if (!valid) return
     if (!valid) return
     formLoading.value = true
     formLoading.value = true
     try {
     try {
+      const payload = { ...formData.value, attachments: getAttachments() }
       if (formType.value === 'create') {
       if (formType.value === 'create') {
-        await createTechnology(formData.value)
+        await createTechnology(payload)
         message.success('新增成功')
         message.success('新增成功')
       } else {
       } else {
-        await updateTechnology(formData.value)
+        await updateTechnology(payload)
         message.success('更新成功')
         message.success('更新成功')
       }
       }
       dialogVisible.value = false
       dialogVisible.value = false