feat(bx): bind reimburse apply attachments on save and submit
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
24aca104ad
commit
d373776526
1 file changed
+26
-1
@@ -848,7 +848,7 @@ import {
|
||||
Filter
|
||||
} from '@element-plus/icons-vue'
|
||||
import type { UploadFile } from 'element-plus'
|
||||
import { reimburseApi, invoiceWalletApi } from '@/api/bx'
|
||||
import { reimburseApi, invoiceWalletApi, attachmentApi } from '@/api/bx'
|
||||
import { buildApplyDateRangeQuery, type ApplyDateRange } from '@/utils/bx/apply-date-filter'
|
||||
import { canDeleteByCreator, allRowsDeletableByCreator, CREATOR_DELETE_TIP } from '@/utils/creator-delete'
|
||||
import { useExpenseItemTree, type ExpenseItem } from '@/hooks/bx/useExpenseItemTree'
|
||||
@@ -1413,6 +1413,7 @@ async function handleViewDelete() {
|
||||
}
|
||||
|
||||
async function openEditDialog(row: any) {
|
||||
applyAttachments.value = []
|
||||
try {
|
||||
const res: any = await reimburseApi.getById(row.id)
|
||||
const data = res.data || res
|
||||
@@ -1709,10 +1710,31 @@ async function saveAddForm(payload: AddPayload): Promise<string | null> {
|
||||
return id || null
|
||||
}
|
||||
|
||||
async function bindApplyAttachments(reimburseId: string) {
|
||||
const ids = (applyAttachmentRef.value?.getFileIds?.() || applyAttachments.value.map((f) => f.id)).filter(
|
||||
(id) => id != null && id !== '' && !String(id).startsWith('upload-')
|
||||
)
|
||||
if (!ids.length) return
|
||||
try {
|
||||
await attachmentApi.bindBiz(ids, 'reimburse_apply', reimburseId)
|
||||
} catch (e: any) {
|
||||
ElMessage.warning(e?.message || '报销单已保存,但申请附件关联失败,请重新编辑后保存')
|
||||
}
|
||||
}
|
||||
|
||||
function assertApplyAttachmentsIdle(): boolean {
|
||||
if (applyAttachmentRef.value?.hasUploading()) {
|
||||
ElMessage.warning('附件上传中,请稍候')
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/** 保存草稿 */
|
||||
async function submitAdd() {
|
||||
const payload = buildAddPayload()
|
||||
if (!payload) return
|
||||
if (!assertApplyAttachmentsIdle()) return
|
||||
const wasEdit = !!editingId.value
|
||||
loadingMap.addSubmit = true
|
||||
try {
|
||||
@@ -1722,6 +1744,7 @@ async function submitAdd() {
|
||||
await refreshList()
|
||||
return
|
||||
}
|
||||
await bindApplyAttachments(id)
|
||||
ElMessage.success(wasEdit ? '保存成功' : '新增成功')
|
||||
resetAddForm()
|
||||
await refreshList()
|
||||
@@ -1736,6 +1759,7 @@ async function submitAdd() {
|
||||
async function submitAddAndApprove() {
|
||||
const payload = buildAddPayload()
|
||||
if (!payload) return
|
||||
if (!assertApplyAttachmentsIdle()) return
|
||||
loadingMap.addApprove = true
|
||||
try {
|
||||
const id = await saveAddForm(payload)
|
||||
@@ -1744,6 +1768,7 @@ async function submitAddAndApprove() {
|
||||
await refreshList()
|
||||
return
|
||||
}
|
||||
await bindApplyAttachments(id)
|
||||
// 保存成功后记下 id,提交失败时再次操作会走更新而非重复新建
|
||||
editingId.value = id
|
||||
await reimburseApi.submit(id)
|
||||
|
||||
Reference in new issue
Block a user