| | |
| | | } |
| | | } |
| | | |
| | | // 打开附件弹框----- TODO:接口是没有对接的,需要新增接口,为写报告添加的 |
| | | // 打开附件弹框 |
| | | const openFilesFormDia = async (row) => { |
| | | currentFileRow.value = row |
| | | try { |
| | |
| | | try { |
| | | const formData = new FormData() |
| | | formData.append("file", file) |
| | | formData.append("id", currentFileRow.value.id) |
| | | const uploadRes = await request({ |
| | | url: "/file/upload", |
| | | url: "/afterSalesService/file/upload", |
| | | method: "post", |
| | | data: formData, |
| | | headers: { |
| | |
| | | }, |
| | | }) |
| | | if (uploadRes.code === 200) { |
| | | const fileData = { |
| | | proxy.$modal.msgSuccess("文件上传成功") |
| | | // 重新获取文件列表 |
| | | const listRes = await afterSalesServiceFileListPage({ |
| | | afterSalesServiceId: currentFileRow.value.id, |
| | | name: uploadRes.data?.originalName || file.name, |
| | | url: uploadRes.data?.tempPath || uploadRes.data?.url, |
| | | current: 1, |
| | | size: 100, |
| | | }) |
| | | if (listRes.code === 200 && fileListRef.value) { |
| | | const fileList = (listRes.data?.records || []).map((item) => ({ |
| | | name: item.fileName, |
| | | url: item.fileUrl, |
| | | id: item.id, |
| | | ...item, |
| | | })) |
| | | fileListRef.value.setList(fileList) |
| | | } |
| | | const saveRes = await afterSalesServiceFileAdd(fileData) |
| | | if (saveRes.code === 200) { |
| | | proxy.$modal.msgSuccess("文件上传成功") |
| | | const listRes = await afterSalesServiceFileListPage({ |
| | | afterSalesServiceId: currentFileRow.value.id, |
| | | current: 1, |
| | | size: 100, |
| | | }) |
| | | if (listRes.code === 200 && fileListRef.value) { |
| | | const fileList = (listRes.data?.records || []).map((item) => ({ |
| | | name: item.name || item.fileName, |
| | | url: item.url || item.fileUrl, |
| | | id: item.id, |
| | | ...item, |
| | | })) |
| | | fileListRef.value.setList(fileList) |
| | | } |
| | | resolve({ name: fileData.name, url: fileData.url, id: saveRes.data?.id }) |
| | | } else { |
| | | proxy.$modal.msgError(saveRes.msg || "文件保存失败") |
| | | resolve(null) |
| | | } |
| | | resolve({ name: file.name, url: "", id: null }) |
| | | } else { |
| | | proxy.$modal.msgError(uploadRes.msg || "文件上传失败") |
| | | resolve(null) |
| | |
| | | // 删除附件 |
| | | const handleFileDelete = async (row) => { |
| | | try { |
| | | const res = await afterSalesServiceFileDel([row.id]) |
| | | if (res.code === 200) { |
| | | proxy.$modal.msgSuccess("删除成功") |
| | | if (currentFileRow.value && fileListRef.value) { |
| | | const listRes = await afterSalesServiceFileListPage({ |
| | | afterSalesServiceId: currentFileRow.value.id, |
| | | current: 1, |
| | | size: 100, |
| | | }) |
| | | if (listRes.code === 200) { |
| | | const fileList = (listRes.data?.records || []).map((item) => ({ |
| | | name: item.name || item.fileName, |
| | | url: item.url || item.fileUrl, |
| | | id: item.id, |
| | | ...item, |
| | | })) |
| | | fileListRef.value.setList(fileList) |
| | | } |
| | | // 添加确认对话框 |
| | | const confirmResult = await ElMessageBox.confirm( |
| | | '确定要删除这个附件吗?', |
| | | '删除确认', |
| | | { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'warning' |
| | | } |
| | | } else { |
| | | proxy.$modal.msgError(res.msg || "删除失败") |
| | | return false |
| | | ) |
| | | |
| | | if (confirmResult === 'confirm') { |
| | | const res = await afterSalesServiceFileDel(row.id) |
| | | if (res.code === 200) { |
| | | proxy.$modal.msgSuccess("删除成功") |
| | | if (currentFileRow.value && fileListRef.value) { |
| | | const listRes = await afterSalesServiceFileListPage({ |
| | | afterSalesServiceId: currentFileRow.value.id, |
| | | current: 1, |
| | | size: 100, |
| | | }) |
| | | if (listRes.code === 200) { |
| | | const fileList = (listRes.data?.records || []).map((item) => ({ |
| | | name: item.fileName, |
| | | url: item.fileUrl, |
| | | id: item.id, |
| | | ...item, |
| | | })) |
| | | fileListRef.value.setList(fileList) |
| | | } |
| | | } |
| | | } else { |
| | | proxy.$modal.msgError(res.msg || "删除失败") |
| | | return false |
| | | } |
| | | } |
| | | } catch (error) { |
| | | proxy.$modal.msgError("删除失败") |
| | | // 如果用户取消删除,不显示错误信息 |
| | | if (error !== 'cancel') { |
| | | proxy.$modal.msgError("删除失败") |
| | | } |
| | | return false |
| | | } |
| | | } |