吉安感知网项目-前端
chenyao
2026-01-29 f083281ab75f61390a04daa2484f330f8df4178f
applications/task-work-order/src/views/orderView/orderDataManage/dataObjection/FormDiaLog.vue
@@ -323,10 +323,21 @@
}
// 文件移除
// const handleFileRemove = (file, fileListVal) => {
// uploadedFiles.value = fileListVal
// }
const handleFileRemove = (file, fileListVal) => {
uploadedFiles.value = fileListVal
}
  // 从展示列表中移除
  fileList.value = fileListVal
  // 从已上传列表中移除
  const index = uploadedFiles.value.findIndex(item =>
    item.attachId === file.attachId || item.name === file.name
  )
  if (index > -1) {
    uploadedFiles.value.splice(index, 1)
  }
}
// 上传前验证
const beforeFileUpload = file => {
   const allowedExtensions = ['.zip', '.rar', '.7z', '.tar', '.gz']
@@ -366,11 +377,12 @@
async function submitForm(objectionStatus) {
   const isValid = await formRef.value?.validate().catch(() => false)
   if (!isValid) return
    // 只在新增时校验附件是否上传
  // 在编辑模式下,如果已有附件,可以不强制上传新附件
   if (dialogMode.value === 'add' && uploadedFiles.value.length === 0) {
      ElMessage.warning('请上传附件')
      return
    return ElMessage.warning('请上传附件')
   }
   submitting.value = true
   try {
@@ -387,7 +399,7 @@
         objectionBasis: formData.value.objectionBasis,
         areaCode: formData.value.areaCode || '',
         handleUnit: formData.value.handleUnit || '',
        // 只在有附件时才构建附件列表
      // 构建附件列表 - 使用当前已上传的文件(包括回显的)
      ...(uploadedFiles.value.length > 0 && {
        attachmentList: uploadedFiles.value.map(file => ({
          attachId: file.attachId,
@@ -396,6 +408,13 @@
      }),
         objectionStatus: objectionStatus
      }
    // 如果是编辑且没有修改附件,可以保留原有附件ID
    if (dialogMode.value === 'edit' && formData.value.attachIds) {
      // 这里可以根据业务需求决定是否保留原附件ID
      // 如果接口支持更新时重新上传附件ID列表,可以这样做
    }
      await gdDataObjectionSubmitApi(submitData)
      ElMessage.success(dialogMode.value === 'add' ? '新增成功' : '更新成功')
      visible.value = false
@@ -442,8 +461,38 @@
   if (!formData.value.id) return
   const res = await gdDataObjectionDetailApi({ id: formData.value.id })
   formData.value = res?.data?.data ?? {}
  // 处理附件回显
   if (formData.value.attachIds) {
      getAttachDetail(formData.value.attachIds)
    await getAttachDetail(formData.value.attachIds)
    // 回显到上传组件
    updateFileListForDisplay()
  }
}
// 更新文件列表用于显示
function updateFileListForDisplay() {
  fileList.value = []
  uploadedFiles.value = []
  if (attachmentDetailsList.value && attachmentDetailsList.value.length > 0) {
    attachmentDetailsList.value.forEach(attach => {
      const fileItem = {
        name: attach.originalName || attach.name,
        url: attach.link, // 用于预览
        attachId: attach.id, // 文件ID
        originalName: attach.originalName,
        link: attach.link
      }
      fileList.value.push({
        name: fileItem.name,
        url: fileItem.url,
        status: 'success' // 已上传状态
      })
      uploadedFiles.value.push(fileItem)
    })
   }
}
// 获取附件详情
@@ -486,7 +535,12 @@
   formData.value = dialogMode.value === 'add' ? initForm() : row
   // 重置反馈表单数据
   feedbackFormData.value = initFeedbackForm()
   if (dialogMode.value !== 'add') {
    // 如果是编辑,设置ID并加载详情
    if (row && row.id) {
      formData.value.id = row.id
    }
      await loadDetail()
   }
}