fix: 修复上传问题,报告和凭证限制 1 条,开票附件限制 2 条,需要后端修改接收数组
This commit is contained in:
parent
9657901339
commit
0694ec28fb
@ -61,6 +61,7 @@ const handleConfirm = () => {
|
|||||||
if (!errors) {
|
if (!errors) {
|
||||||
emit('confirm', {
|
emit('confirm', {
|
||||||
...formData.value,
|
...formData.value,
|
||||||
|
attachments: fileList.value?.map((file) => file.url) || [],
|
||||||
id: props.invoiceData?.id,
|
id: props.invoiceData?.id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -93,15 +94,11 @@ const handleUploadFinish = ({ file, event }) => {
|
|||||||
const res = JSON.parse(event.target.response)
|
const res = JSON.parse(event.target.response)
|
||||||
// 只要返回了 url 字段,就认为上传成功
|
// 只要返回了 url 字段,就认为上传成功
|
||||||
if (res.code === 200 && res.data?.url) {
|
if (res.code === 200 && res.data?.url) {
|
||||||
// 显式查找 fileList 中的文件对象进行更新,确保响应式
|
file.url = res.data.url
|
||||||
const targetFile = fileList.value.find(f => f.id === file.id) || file
|
file.name = res.data.filename || file.name
|
||||||
targetFile.url = res.data.url
|
file.status = 'finished'
|
||||||
targetFile.name = res.data.filename || targetFile.name
|
|
||||||
targetFile.status = 'finished' // 手动标记为完成
|
|
||||||
|
|
||||||
// 更新 formData.attachments
|
|
||||||
updateAttachments()
|
|
||||||
$message.success('上传成功')
|
$message.success('上传成功')
|
||||||
|
return file
|
||||||
} else {
|
} else {
|
||||||
$message.error(res.message || '上传失败')
|
$message.error(res.message || '上传失败')
|
||||||
// 从列表中移除失败的文件
|
// 从列表中移除失败的文件
|
||||||
@ -114,25 +111,6 @@ const handleUploadFinish = ({ file, event }) => {
|
|||||||
const index = fileList.value.findIndex((item) => item.id === file.id)
|
const index = fileList.value.findIndex((item) => item.id === file.id)
|
||||||
if (index > -1) fileList.value.splice(index, 1)
|
if (index > -1) fileList.value.splice(index, 1)
|
||||||
}
|
}
|
||||||
return file
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新附件列表
|
|
||||||
const updateAttachments = () => {
|
|
||||||
// 只要有 url 的都算作有效附件
|
|
||||||
formData.value.attachments = fileList.value
|
|
||||||
.map(file => file.url)
|
|
||||||
.filter(url => !!url)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 移除文件
|
|
||||||
const handleRemove = ({ file }) => {
|
|
||||||
const index = fileList.value.findIndex(item => item.id === file.id)
|
|
||||||
if (index > -1) {
|
|
||||||
fileList.value.splice(index, 1)
|
|
||||||
updateAttachments()
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const rules = {
|
const rules = {
|
||||||
@ -201,7 +179,6 @@ const modalTitle = props.mode === 'invoice' ? '开票' : '查看发票'
|
|||||||
:headers="uploadHeaders"
|
:headers="uploadHeaders"
|
||||||
:before-upload="beforeUpload"
|
:before-upload="beforeUpload"
|
||||||
@finish="handleUploadFinish"
|
@finish="handleUploadFinish"
|
||||||
@remove="handleRemove"
|
|
||||||
:disabled="mode === 'view'"
|
:disabled="mode === 'view'"
|
||||||
>
|
>
|
||||||
<div class="upload-trigger">
|
<div class="upload-trigger">
|
||||||
|
|||||||
@ -335,11 +335,11 @@ const handleCertificateConfirm = async (data) => {
|
|||||||
const certificateUrl = data.certificateFiles?.map(f => f.url).filter(Boolean) || []
|
const certificateUrl = data.certificateFiles?.map(f => f.url).filter(Boolean) || []
|
||||||
const reportUrl = data.reportFiles?.map(f => f.url).filter(Boolean) || []
|
const reportUrl = data.reportFiles?.map(f => f.url).filter(Boolean) || []
|
||||||
|
|
||||||
|
// 现在改为只能上传 1 张
|
||||||
const payload = {
|
const payload = {
|
||||||
...props.detailData,
|
...props.detailData,
|
||||||
certificate_url: certificateUrl,
|
certificate_url: certificateUrl?.[0],
|
||||||
report_url: reportUrl,
|
report_url: reportUrl?.[0],
|
||||||
status: 'success'
|
status: 'success'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -203,13 +203,12 @@ const handlePreview = (file) => {
|
|||||||
<div class="upload-content">
|
<div class="upload-content">
|
||||||
<NUpload
|
<NUpload
|
||||||
v-model:file-list="reportFileList"
|
v-model:file-list="reportFileList"
|
||||||
multiple
|
max="1"
|
||||||
list-type="image-card"
|
list-type="image-card"
|
||||||
:action="uploadUrl"
|
:action="uploadUrl"
|
||||||
:headers="uploadHeaders"
|
:headers="uploadHeaders"
|
||||||
:before-upload="beforeUpload"
|
:before-upload="beforeUpload"
|
||||||
@finish="handleReportUploadFinish"
|
@finish="handleReportUploadFinish"
|
||||||
|
|
||||||
:disabled="!isUploadMode"
|
:disabled="!isUploadMode"
|
||||||
show-preview-button
|
show-preview-button
|
||||||
show-download-button
|
show-download-button
|
||||||
@ -225,13 +224,12 @@ const handlePreview = (file) => {
|
|||||||
<div class="upload-content">
|
<div class="upload-content">
|
||||||
<NUpload
|
<NUpload
|
||||||
v-model:file-list="certificateFileList"
|
v-model:file-list="certificateFileList"
|
||||||
multiple
|
|
||||||
list-type="image-card"
|
list-type="image-card"
|
||||||
:action="uploadUrl"
|
:action="uploadUrl"
|
||||||
:headers="uploadHeaders"
|
:headers="uploadHeaders"
|
||||||
:before-upload="beforeUpload"
|
:before-upload="beforeUpload"
|
||||||
@finish="handleCertificateUploadFinish"
|
@finish="handleCertificateUploadFinish"
|
||||||
|
max="1"
|
||||||
:disabled="!isUploadMode"
|
:disabled="!isUploadMode"
|
||||||
show-preview-button
|
show-preview-button
|
||||||
show-download-button
|
show-download-button
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user