feat(bx): 报销可代选申请人,并放宽主数据选项的数据权限过滤
支持具备 changeApplicant 权限时代填申请人及发票/余额联动;系统/CRM/BX/PL 主数据与下拉选项改为仅租户隔离,避免「仅本人」导致空选项。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
6c2121d7fc
commit
31b0db6840
36 files changed
+36351
-37915
No files matched your search
@@ -118,10 +118,11 @@ export const advanceApi = {
|
||||
}
|
||||
|
||||
export const reimburseApi = {
|
||||
generateTitle(reimburseDate?: string, excludeApplyId?: BxId) {
|
||||
generateTitle(reimburseDate?: string, excludeApplyId?: BxId, applicantId?: BxId) {
|
||||
const params: Record<string, string> = {}
|
||||
if (reimburseDate) params.reimburseDate = reimburseDate
|
||||
if (excludeApplyId) params.excludeApplyId = String(excludeApplyId)
|
||||
if (applicantId) params.applicantId = String(applicantId)
|
||||
return bxRequest.get('/reimburses/generate-title', { params })
|
||||
},
|
||||
list(params: {
|
||||
@@ -283,8 +284,8 @@ export const paymentApi = {
|
||||
}
|
||||
|
||||
export const invoiceWalletApi = {
|
||||
mineSummary() {
|
||||
return bxRequest.get('/invoice-wallets/mine/summary')
|
||||
mineSummary(params?: { userId?: BxId }) {
|
||||
return bxRequest.get('/invoice-wallets/mine/summary', { params })
|
||||
},
|
||||
list(params: { page: number; pageSize: number; keyword?: string }) {
|
||||
return bxRequest.get('/invoice-wallets', { params })
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
<template>
|
||||
<div class="attachment-upload">
|
||||
<div
|
||||
ref="rootRef"
|
||||
class="attachment-upload"
|
||||
:class="{ 'attachment-upload--drag-over': isDragOver && !disabled }"
|
||||
:tabindex="disabled ? undefined : 0"
|
||||
@mouseenter="handlePointerEnter"
|
||||
@mouseleave="handlePointerLeave"
|
||||
@focusin="handlePointerEnter"
|
||||
@focusout="handleFocusOut"
|
||||
@dragenter="handleDragEnter"
|
||||
@dragleave="handleDragLeave"
|
||||
@dragover="handleDragOver"
|
||||
@drop="handleDrop"
|
||||
>
|
||||
<div class="attachment-list">
|
||||
<el-upload
|
||||
ref="uploadRef"
|
||||
@@ -12,7 +25,7 @@
|
||||
>
|
||||
<div class="upload-card">
|
||||
<el-icon :size="28" color="#1ca851"><Plus /></el-icon>
|
||||
<span class="upload-card-text">上传附件</span>
|
||||
<span class="upload-card-text">{{ isDragOver ? '松开上传' : '上传附件' }}</span>
|
||||
</div>
|
||||
</el-upload>
|
||||
<div
|
||||
@@ -87,147 +100,273 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, ref } from 'vue'
|
||||
import {
|
||||
Plus,
|
||||
Loading,
|
||||
VideoPlay,
|
||||
Document,
|
||||
Download,
|
||||
Delete
|
||||
} from '@element-plus/icons-vue'
|
||||
import type { UploadFile, UploadInstance } from 'element-plus'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { attachmentApi, type BxId } from '@/api/bx'
|
||||
import {
|
||||
type BxAttachmentItem,
|
||||
isBxImageFile,
|
||||
isBxVideoFile,
|
||||
canBxPreview,
|
||||
downloadBxAttachment,
|
||||
previewBxAttachment
|
||||
} from '@/utils/bx/attachment'
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import {
|
||||
Plus,
|
||||
Loading,
|
||||
VideoPlay,
|
||||
Document,
|
||||
Download,
|
||||
Delete
|
||||
} from '@element-plus/icons-vue'
|
||||
import type { UploadFile, UploadInstance } from 'element-plus'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { attachmentApi, type BxId } from '@/api/bx'
|
||||
import {
|
||||
type BxAttachmentItem,
|
||||
isBxImageFile,
|
||||
isBxVideoFile,
|
||||
canBxPreview,
|
||||
downloadBxAttachment,
|
||||
previewBxAttachment
|
||||
} from '@/utils/bx/attachment'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue: BxAttachmentItem[]
|
||||
bizType: string
|
||||
bizId?: BxId
|
||||
hint?: string
|
||||
showHint?: boolean
|
||||
disabled?: boolean
|
||||
}>(),
|
||||
{
|
||||
bizId: 0,
|
||||
hint: '支持图片、视频、PDF、Word、Excel等文件',
|
||||
showHint: true,
|
||||
disabled: false
|
||||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: BxAttachmentItem[]]
|
||||
}>()
|
||||
|
||||
const uploadRef = ref<UploadInstance>()
|
||||
const globalUploading = ref(false)
|
||||
const previewVisible = ref(false)
|
||||
const previewUrl = ref('')
|
||||
const previewFileName = ref('')
|
||||
const previewMode = ref<'image' | 'video'>('image')
|
||||
|
||||
const files = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
})
|
||||
|
||||
function syncFiles(next: BxAttachmentItem[]) {
|
||||
emit('update:modelValue', next)
|
||||
}
|
||||
|
||||
async function handleAttachmentChange(uploadFile: UploadFile) {
|
||||
const rawFile = uploadFile.raw
|
||||
if (!rawFile) return
|
||||
|
||||
const item: BxAttachmentItem = {
|
||||
id: `upload-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
||||
fileName: rawFile.name,
|
||||
fileType: rawFile.type,
|
||||
fileSize: rawFile.size,
|
||||
previewUrl: '',
|
||||
_uploading: true
|
||||
}
|
||||
syncFiles([...files.value, item])
|
||||
globalUploading.value = true
|
||||
|
||||
try {
|
||||
const res: any = await attachmentApi.upload(rawFile, props.bizType, props.bizId ?? 0)
|
||||
item.id = res.data.id
|
||||
item.fileName = res.data.fileName || item.fileName
|
||||
item.fileType = res.data.fileType || item.fileType
|
||||
item.fileSize = res.data.fileSize ?? item.fileSize
|
||||
item._uploading = false
|
||||
if (isBxImageFile(item)) {
|
||||
try {
|
||||
const previewRes: any = await attachmentApi.preview(item.id)
|
||||
item.previewUrl = previewRes.data?.url || ''
|
||||
} catch {
|
||||
/* preview optional */
|
||||
}
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue: BxAttachmentItem[]
|
||||
bizType: string
|
||||
bizId?: BxId
|
||||
hint?: string
|
||||
showHint?: boolean
|
||||
disabled?: boolean
|
||||
}>(),
|
||||
{
|
||||
bizId: 0,
|
||||
hint: '支持图片、视频、PDF、Word、Excel等文件;可拖拽或在此区域粘贴上传',
|
||||
showHint: true,
|
||||
disabled: false
|
||||
}
|
||||
syncFiles([...files.value])
|
||||
} catch (error: any) {
|
||||
syncFiles(files.value.filter((entry) => entry.id !== item.id))
|
||||
ElMessage.error(error?.message || '上传失败')
|
||||
} finally {
|
||||
globalUploading.value = files.value.some((entry) => entry._uploading)
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: BxAttachmentItem[]]
|
||||
}>()
|
||||
|
||||
const rootRef = ref<HTMLElement>()
|
||||
const uploadRef = ref<UploadInstance>()
|
||||
const globalUploading = ref(false)
|
||||
const previewVisible = ref(false)
|
||||
const previewUrl = ref('')
|
||||
const previewFileName = ref('')
|
||||
const previewMode = ref<'image' | 'video'>('image')
|
||||
const isPointerInside = ref(false)
|
||||
const isDragOver = ref(false)
|
||||
let dragEnterDepth = 0
|
||||
|
||||
const files = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
})
|
||||
|
||||
function syncFiles(next: BxAttachmentItem[]) {
|
||||
emit('update:modelValue', next)
|
||||
}
|
||||
|
||||
function normalizeIncomingFile(file: File, index = 0) {
|
||||
if (file.name && file.name.trim()) return file
|
||||
const ext = (file.type || '').split('/')[1] || 'bin'
|
||||
return new File([file], `paste-${Date.now()}-${index}.${ext}`, {
|
||||
type: file.type || 'application/octet-stream'
|
||||
})
|
||||
}
|
||||
|
||||
function collectClipboardFiles(event: ClipboardEvent) {
|
||||
const out: File[] = []
|
||||
const items = event.clipboardData?.items
|
||||
if (items?.length) {
|
||||
Array.from(items).forEach((item, index) => {
|
||||
if (item.kind !== 'file') return
|
||||
const file = item.getAsFile()
|
||||
if (file) out.push(normalizeIncomingFile(file, index))
|
||||
})
|
||||
}
|
||||
if (!out.length && event.clipboardData?.files?.length) {
|
||||
Array.from(event.clipboardData.files).forEach((file, index) => {
|
||||
out.push(normalizeIncomingFile(file, index))
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
async function uploadRawFile(rawFile: File) {
|
||||
if (props.disabled) return
|
||||
const item: BxAttachmentItem = {
|
||||
id: `upload-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
||||
fileName: rawFile.name,
|
||||
fileType: rawFile.type,
|
||||
fileSize: rawFile.size,
|
||||
previewUrl: '',
|
||||
_uploading: true
|
||||
}
|
||||
syncFiles([...files.value, item])
|
||||
globalUploading.value = true
|
||||
|
||||
try {
|
||||
const res: any = await attachmentApi.upload(rawFile, props.bizType, props.bizId ?? 0)
|
||||
item.id = res.data.id
|
||||
item.fileName = res.data.fileName || item.fileName
|
||||
item.fileType = res.data.fileType || item.fileType
|
||||
item.fileSize = res.data.fileSize ?? item.fileSize
|
||||
item._uploading = false
|
||||
if (isBxImageFile(item)) {
|
||||
try {
|
||||
const previewRes: any = await attachmentApi.preview(item.id)
|
||||
item.previewUrl = previewRes.data?.url || ''
|
||||
} catch {
|
||||
/* preview optional */
|
||||
}
|
||||
}
|
||||
syncFiles([...files.value])
|
||||
} catch (error: any) {
|
||||
syncFiles(files.value.filter((entry) => entry.id !== item.id))
|
||||
ElMessage.error(error?.message || '上传失败')
|
||||
} finally {
|
||||
globalUploading.value = files.value.some((entry) => entry._uploading)
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadFiles(list: File[]) {
|
||||
for (const file of list) {
|
||||
await uploadRawFile(file)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleAttachmentChange(uploadFile: UploadFile) {
|
||||
const rawFile = uploadFile.raw
|
||||
if (!rawFile) return
|
||||
await uploadRawFile(rawFile)
|
||||
await nextTick()
|
||||
uploadRef.value?.clearFiles()
|
||||
}
|
||||
}
|
||||
|
||||
async function removeAttachment(index: number) {
|
||||
const file = files.value[index]
|
||||
if (!file || file._uploading) return
|
||||
try {
|
||||
await ElMessageBox.confirm('确定删除该附件?', '提示', { type: 'warning' })
|
||||
if (typeof file.id === 'number' || /^\d+$/.test(String(file.id))) {
|
||||
await attachmentApi.delete(file.id)
|
||||
}
|
||||
const next = [...files.value]
|
||||
next.splice(index, 1)
|
||||
syncFiles(next)
|
||||
ElMessage.success('已删除')
|
||||
} catch {
|
||||
/* cancelled */
|
||||
function handlePointerEnter() {
|
||||
if (props.disabled) return
|
||||
isPointerInside.value = true
|
||||
}
|
||||
}
|
||||
|
||||
function handleDownload(file: BxAttachmentItem) {
|
||||
if (file._uploading) return
|
||||
downloadBxAttachment(file)
|
||||
}
|
||||
function handlePointerLeave() {
|
||||
isPointerInside.value = false
|
||||
}
|
||||
|
||||
async function handlePreview(file: BxAttachmentItem) {
|
||||
const result = await previewBxAttachment(file)
|
||||
if (!result) return
|
||||
previewMode.value = result.type
|
||||
previewUrl.value = result.url
|
||||
previewFileName.value = result.fileName
|
||||
previewVisible.value = true
|
||||
}
|
||||
function handleFocusOut(event: FocusEvent) {
|
||||
const next = event.relatedTarget as Node | null
|
||||
if (next && rootRef.value?.contains(next)) return
|
||||
isPointerInside.value = false
|
||||
}
|
||||
|
||||
function hasUploading() {
|
||||
return files.value.some((item) => item._uploading)
|
||||
}
|
||||
function handleDragEnter(event: DragEvent) {
|
||||
if (props.disabled) return
|
||||
event.preventDefault()
|
||||
dragEnterDepth += 1
|
||||
isDragOver.value = true
|
||||
isPointerInside.value = true
|
||||
}
|
||||
|
||||
function getFileIds() {
|
||||
return files.value.filter((item) => !item._uploading).map((item) => item.id)
|
||||
}
|
||||
function handleDragLeave(event: DragEvent) {
|
||||
if (props.disabled) return
|
||||
event.preventDefault()
|
||||
dragEnterDepth = Math.max(0, dragEnterDepth - 1)
|
||||
if (dragEnterDepth === 0) isDragOver.value = false
|
||||
}
|
||||
|
||||
defineExpose({ hasUploading, getFileIds })
|
||||
function handleDragOver(event: DragEvent) {
|
||||
if (props.disabled) return
|
||||
event.preventDefault()
|
||||
if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy'
|
||||
}
|
||||
|
||||
async function handleDrop(event: DragEvent) {
|
||||
if (props.disabled) return
|
||||
event.preventDefault()
|
||||
dragEnterDepth = 0
|
||||
isDragOver.value = false
|
||||
await uploadFiles(Array.from(event.dataTransfer?.files || []))
|
||||
}
|
||||
|
||||
async function handleDocumentPaste(event: ClipboardEvent) {
|
||||
if (props.disabled || !isPointerInside.value) return
|
||||
const clipboardFiles = collectClipboardFiles(event)
|
||||
if (!clipboardFiles.length) return
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
await uploadFiles(clipboardFiles)
|
||||
}
|
||||
|
||||
async function removeAttachment(index: number) {
|
||||
const file = files.value[index]
|
||||
if (!file || file._uploading) return
|
||||
try {
|
||||
await ElMessageBox.confirm('确定删除该附件?', '提示', { type: 'warning' })
|
||||
if (typeof file.id === 'number' || /^\d+$/.test(String(file.id))) {
|
||||
await attachmentApi.delete(file.id)
|
||||
}
|
||||
const next = [...files.value]
|
||||
next.splice(index, 1)
|
||||
syncFiles(next)
|
||||
ElMessage.success('已删除')
|
||||
} catch {
|
||||
/* cancelled */
|
||||
}
|
||||
}
|
||||
|
||||
function handleDownload(file: BxAttachmentItem) {
|
||||
if (file._uploading) return
|
||||
downloadBxAttachment(file)
|
||||
}
|
||||
|
||||
async function handlePreview(file: BxAttachmentItem) {
|
||||
const result = await previewBxAttachment(file)
|
||||
if (!result) return
|
||||
previewMode.value = result.type
|
||||
previewUrl.value = result.url
|
||||
previewFileName.value = result.fileName
|
||||
previewVisible.value = true
|
||||
}
|
||||
|
||||
function hasUploading() {
|
||||
return files.value.some((item) => item._uploading)
|
||||
}
|
||||
|
||||
function getFileIds() {
|
||||
return files.value.filter((item) => !item._uploading).map((item) => item.id)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('paste', handleDocumentPaste, true)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('paste', handleDocumentPaste, true)
|
||||
})
|
||||
|
||||
defineExpose({ hasUploading, getFileIds })
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@use '@/styles/bx/attachment.scss';
|
||||
@use '@/styles/bx/attachment.scss';
|
||||
|
||||
.attachment-upload {
|
||||
outline: none;
|
||||
border-radius: 8px;
|
||||
|
||||
&:focus-visible {
|
||||
box-shadow: 0 0 0 2px rgba(28, 168, 81, 0.25);
|
||||
}
|
||||
|
||||
&--drag-over {
|
||||
.attachment-list {
|
||||
padding: 4px;
|
||||
border-radius: 8px;
|
||||
outline: 2px dashed #1ca851;
|
||||
outline-offset: 4px;
|
||||
background: rgba(16, 185, 129, 0.06);
|
||||
}
|
||||
|
||||
.upload-card {
|
||||
border-color: #1ca851;
|
||||
border-style: solid;
|
||||
background: #e6f8ed;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -2,35 +2,68 @@
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
title="从发票夹选择"
|
||||
width="720px"
|
||||
class="dialog-form-layout"
|
||||
width="1040px"
|
||||
class="dialog-form-layout bx-invoice-select-dialog"
|
||||
align-center
|
||||
destroy-on-close
|
||||
append-to-body
|
||||
@open="loadList"
|
||||
>
|
||||
<el-table
|
||||
ref="tableRef"
|
||||
v-loading="loading"
|
||||
class="list-table"
|
||||
:data="rows"
|
||||
stripe
|
||||
row-key="id"
|
||||
max-height="420"
|
||||
@selection-change="onSelectionChange"
|
||||
>
|
||||
<el-table-column type="selection" min-width="48" />
|
||||
<el-table-column prop="amount" label="金额(元)" min-width="120" align="right">
|
||||
<template #default="{ row }">{{ formatMoneyYuan(row.amount) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="fileName" label="附件" min-width="180" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ attachmentLabel(row) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="remark" label="备注" min-width="140" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.remark || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="createTime" label="上传时间" min-width="160" />
|
||||
</el-table>
|
||||
<div v-loading="loading" class="invoice-attach-panel">
|
||||
<div v-if="!loading && !monthGroups.length" class="invoice-attach-empty">暂无发票附件</div>
|
||||
<div v-else class="invoice-attach-months">
|
||||
<section v-for="group in monthGroups" :key="group.monthKey" class="invoice-attach-month">
|
||||
<h4 class="invoice-attach-month__title">{{ group.monthLabel }}</h4>
|
||||
<div class="invoice-attach-grid">
|
||||
<button
|
||||
v-for="item in group.items"
|
||||
:key="item.key"
|
||||
type="button"
|
||||
class="invoice-attach-card"
|
||||
:class="{ 'is-selected': selectedKeys.has(item.key) }"
|
||||
@click="toggleOne(item.key)"
|
||||
>
|
||||
<span class="invoice-attach-card__index">{{ item.serial }}</span>
|
||||
<div class="invoice-attach-card__preview">
|
||||
<template v-if="isBxImageFile(item.file) && item.file.previewUrl">
|
||||
<img :src="item.file.previewUrl" :alt="item.file.fileName" />
|
||||
</template>
|
||||
<template v-else-if="isBxVideoFile(item.file)">
|
||||
<div class="attachment-preview__icon attachment-preview__icon--video">
|
||||
<el-icon :size="28"><VideoPlay /></el-icon>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="attachment-preview__icon attachment-preview__icon--doc">
|
||||
<el-icon :size="28"><Document /></el-icon>
|
||||
</div>
|
||||
</template>
|
||||
<span v-if="selectedKeys.has(item.key)" class="invoice-attach-check">
|
||||
<el-icon :size="14"><Check /></el-icon>
|
||||
</span>
|
||||
</div>
|
||||
<div class="invoice-attach-card__meta">
|
||||
<span class="invoice-attach-card__name" :title="item.file.fileName">
|
||||
{{ item.file.fileName }}
|
||||
</span>
|
||||
<div class="invoice-attach-card__footer">
|
||||
<span class="invoice-attach-card__amount">
|
||||
{{ formatMoneyYuan(item.amount) }} 元
|
||||
</span>
|
||||
<el-icon
|
||||
class="invoice-attach-card__download"
|
||||
title="下载"
|
||||
@click.stop="handleDownload(item.file)"
|
||||
>
|
||||
<Download />
|
||||
</el-icon>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button class="btn-ghost" @click="visible = false">
|
||||
@@ -44,28 +77,75 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { nextTick, ref, watch } from 'vue'
|
||||
import { Close, Check } from '@element-plus/icons-vue'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { Close, Check, VideoPlay, Document, Download } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { invoiceApi } from '@/api/bx'
|
||||
import { formatMoneyYuan } from '@/utils/bx/format'
|
||||
import { pickBxPageResult } from '@/utils/http/bx'
|
||||
import {
|
||||
type BxAttachmentItem,
|
||||
fillBxAttachmentPreviews,
|
||||
downloadBxAttachment,
|
||||
isBxImageFile,
|
||||
isBxVideoFile
|
||||
} from '@/utils/bx/attachment'
|
||||
|
||||
export type InvoiceAttachPick = {
|
||||
key: string
|
||||
invoiceId: string | number
|
||||
attachmentId: string | number
|
||||
amount: number | string
|
||||
createTime: string
|
||||
invoice: any
|
||||
file: BxAttachmentItem
|
||||
}
|
||||
|
||||
type MonthGroup = {
|
||||
monthKey: string
|
||||
monthLabel: string
|
||||
items: Array<InvoiceAttachPick & { serial: number }>
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: boolean
|
||||
selectedIds?: string[]
|
||||
/** 已选附件 key:`${invoiceId}:${attachmentId}` */
|
||||
selectedKeys?: string[]
|
||||
/** 代申请时查询指定申请人的发票夹 */
|
||||
ownerUserId?: string | number
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', v: boolean): void
|
||||
(e: 'confirm', rows: any[]): void
|
||||
(e: 'confirm', picks: InvoiceAttachPick[]): void
|
||||
}>()
|
||||
|
||||
const visible = ref(false)
|
||||
const loading = ref(false)
|
||||
const rows = ref<any[]>([])
|
||||
const selected = ref<any[]>([])
|
||||
const tableRef = ref<any>(null)
|
||||
const attachItems = ref<InvoiceAttachPick[]>([])
|
||||
const selectedKeys = ref<Set<string>>(new Set())
|
||||
|
||||
const monthGroups = computed<MonthGroup[]>(() => {
|
||||
const map = new Map<string, InvoiceAttachPick[]>()
|
||||
attachItems.value.forEach((item) => {
|
||||
const monthKey = toMonthKey(item.createTime)
|
||||
const list = map.get(monthKey) || []
|
||||
list.push(item)
|
||||
map.set(monthKey, list)
|
||||
})
|
||||
return Array.from(map.entries())
|
||||
.sort((a, b) => b[0].localeCompare(a[0]))
|
||||
.map(([monthKey, items]) => {
|
||||
const sorted = items
|
||||
.slice()
|
||||
.sort((a, b) => String(b.createTime).localeCompare(String(a.createTime)))
|
||||
return {
|
||||
monthKey,
|
||||
monthLabel: toMonthLabel(monthKey),
|
||||
items: sorted.map((item, idx) => ({ ...item, serial: idx + 1 }))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
@@ -79,44 +159,262 @@
|
||||
emit('update:modelValue', v)
|
||||
})
|
||||
|
||||
function toMonthKey(raw: string) {
|
||||
const text = String(raw || '').trim()
|
||||
if (!text) return 'unknown'
|
||||
const m = text.match(/^(\d{4})[-/]?(\d{2})/)
|
||||
if (m) return `${m[1]}-${m[2]}`
|
||||
const d = new Date(text)
|
||||
if (!Number.isNaN(d.getTime())) {
|
||||
const y = d.getFullYear()
|
||||
const mo = String(d.getMonth() + 1).padStart(2, '0')
|
||||
return `${y}-${mo}`
|
||||
}
|
||||
return 'unknown'
|
||||
}
|
||||
|
||||
function toMonthLabel(monthKey: string) {
|
||||
if (monthKey === 'unknown') return '未知月份'
|
||||
const [y, m] = monthKey.split('-')
|
||||
return `${y}年${Number(m)}月`
|
||||
}
|
||||
|
||||
function invoiceAttachments(row: any): BxAttachmentItem[] {
|
||||
const list = Array.isArray(row?.attachments) ? row.attachments : []
|
||||
if (list.length) {
|
||||
return list.map((a: any) => ({
|
||||
id: a.id || a.attachmentId,
|
||||
fileName: a.fileName || a.file_name || '发票附件',
|
||||
fileType: a.fileType || a.file_type || '',
|
||||
previewUrl: a.previewUrl || '',
|
||||
_existing: true
|
||||
}))
|
||||
}
|
||||
if (row?.attachmentId) {
|
||||
return [
|
||||
{
|
||||
id: row.attachmentId,
|
||||
fileName: row.fileName || '发票附件',
|
||||
fileType: row.fileType || '',
|
||||
previewUrl: '',
|
||||
_existing: true
|
||||
}
|
||||
]
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
function buildAttachItems(rows: any[]): InvoiceAttachPick[] {
|
||||
const items: InvoiceAttachPick[] = []
|
||||
rows.forEach((row) => {
|
||||
invoiceAttachments(row).forEach((file) => {
|
||||
const attachmentId = file.id
|
||||
items.push({
|
||||
key: `${row.id}:${attachmentId}`,
|
||||
invoiceId: row.id,
|
||||
attachmentId,
|
||||
amount: row.amount,
|
||||
createTime: row.createTime || row.create_time || '',
|
||||
invoice: row,
|
||||
file
|
||||
})
|
||||
})
|
||||
})
|
||||
return items
|
||||
}
|
||||
|
||||
async function loadList() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res: any = await invoiceApi.list({ page: 1, pageSize: 200 })
|
||||
const page = pickBxPageResult<any>(res)
|
||||
rows.value = page.list
|
||||
await nextTick()
|
||||
const idSet = new Set((props.selectedIds || []).map(String))
|
||||
selected.value = []
|
||||
rows.value.forEach((row) => {
|
||||
if (idSet.has(String(row.id))) {
|
||||
tableRef.value?.toggleRowSelection?.(row, true)
|
||||
}
|
||||
const res: any = await invoiceApi.list({
|
||||
page: 1,
|
||||
pageSize: 200,
|
||||
userId: props.ownerUserId || undefined
|
||||
})
|
||||
const page = pickBxPageResult<any>(res)
|
||||
const items = buildAttachItems(page.list)
|
||||
await fillBxAttachmentPreviews(items.map((item) => item.file))
|
||||
attachItems.value = items
|
||||
const preferred = new Set((props.selectedKeys || []).map(String))
|
||||
selectedKeys.value = new Set(items.filter((i) => preferred.has(i.key)).map((i) => i.key))
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '加载发票失败')
|
||||
attachItems.value = []
|
||||
selectedKeys.value = new Set()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function onSelectionChange(list: any[]) {
|
||||
selected.value = list
|
||||
/** 多选:同一批附件可逐个勾选,互不影响 */
|
||||
function toggleOne(key: string) {
|
||||
const next = new Set(selectedKeys.value)
|
||||
if (next.has(key)) next.delete(key)
|
||||
else next.add(key)
|
||||
selectedKeys.value = next
|
||||
}
|
||||
|
||||
function attachmentLabel(row: any) {
|
||||
const list = Array.isArray(row?.attachments) ? row.attachments : []
|
||||
if (list.length) {
|
||||
return list
|
||||
.map((a: any) => a.fileName || a.file_name)
|
||||
.filter(Boolean)
|
||||
.join('、') || `${list.length} 个附件`
|
||||
}
|
||||
return row?.fileName || '-'
|
||||
function handleDownload(file: BxAttachmentItem) {
|
||||
downloadBxAttachment(file)
|
||||
}
|
||||
|
||||
function confirm() {
|
||||
emit('confirm', selected.value.slice())
|
||||
emit(
|
||||
'confirm',
|
||||
attachItems.value.filter((item) => selectedKeys.value.has(item.key))
|
||||
)
|
||||
visible.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@use '@/styles/bx/attachment.scss';
|
||||
|
||||
.invoice-attach-panel {
|
||||
min-height: calc(100vh - 280px);
|
||||
}
|
||||
|
||||
.invoice-attach-empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 240px;
|
||||
font-size: 13px;
|
||||
color: var(--mint-text-muted, #64748b);
|
||||
}
|
||||
|
||||
.invoice-attach-months {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.invoice-attach-month__title {
|
||||
margin: 0 0 12px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--text, #1e293b);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.invoice-attach-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
align-content: flex-start;
|
||||
}
|
||||
|
||||
.invoice-attach-card {
|
||||
position: relative;
|
||||
width: 140px;
|
||||
padding: 0;
|
||||
border: 1px solid var(--border, #d9e8e2);
|
||||
border-radius: 8px;
|
||||
background: var(--surface, #fff);
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
transition:
|
||||
border-color 0.15s ease,
|
||||
box-shadow 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--primary, #10b981);
|
||||
box-shadow: 0 2px 8px rgba(16, 185, 129, 0.12);
|
||||
}
|
||||
|
||||
&.is-selected {
|
||||
border-color: var(--primary, #10b981);
|
||||
box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
.invoice-attach-card__index {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
top: 6px;
|
||||
left: 8px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
line-height: 1.2;
|
||||
color: var(--primary, #10b981);
|
||||
background: none;
|
||||
}
|
||||
|
||||
.invoice-attach-card__preview {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 96px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--table-head, #f8fafc);
|
||||
overflow: hidden;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.invoice-attach-check {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 6px;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 50%;
|
||||
background: var(--primary, #10b981);
|
||||
color: #fff;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.invoice-attach-card__meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
padding: 6px 8px;
|
||||
}
|
||||
|
||||
.invoice-attach-card__name {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
font-size: 11px;
|
||||
line-height: 1.4;
|
||||
color: var(--text, #1e293b);
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.invoice-attach-card__footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.invoice-attach-card__amount {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--primary-dark, #059669);
|
||||
}
|
||||
|
||||
.invoice-attach-card__download {
|
||||
flex-shrink: 0;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 4px;
|
||||
color: var(--mint-text-muted, #64748b);
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: var(--primary, #10b981);
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -3,7 +3,7 @@
|
||||
<header class="portal-header">
|
||||
<div class="portal-header-start">
|
||||
<div class="portal-header-brand" @click="toHome">
|
||||
<ArtLogo class="portal-header-logo" src="/logo-sx.svg" :size="38" />
|
||||
<ArtLogo class="portal-header-logo" src="/logo-sx.svg" :size="28" />
|
||||
<p class="portal-header-title">{{ AppConfig.systemInfo.name }}</p>
|
||||
</div>
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
gap: 12px;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
/* +1px:与侧栏 #app-sidebar 外边框(内容宽 + 1px border)纵向对齐 */
|
||||
width: calc(var(--app-sidebar-open-width, 270px) + 1px);
|
||||
@@ -134,7 +134,7 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
font-weight: 600;
|
||||
line-height: 1.35;
|
||||
color: #fff;
|
||||
white-space: nowrap;
|
||||
|
||||
@@ -93,6 +93,15 @@ bxAxios.interceptors.request.use(async (config: InternalAxiosRequestConfig) => {
|
||||
if (config.url) {
|
||||
config.url = normalizeBxUrl(config.url)
|
||||
}
|
||||
if (config.data instanceof FormData) {
|
||||
// 让浏览器自动带 multipart boundary;覆盖实例默认 application/json
|
||||
if (typeof config.headers.set === 'function') {
|
||||
config.headers.set('Content-Type', false as unknown as string)
|
||||
} else {
|
||||
delete (config.headers as any)['Content-Type']
|
||||
delete (config.headers as any)['content-type']
|
||||
}
|
||||
}
|
||||
const store = useUserStore()
|
||||
let token = store.accessToken as unknown as string
|
||||
if (!token) {
|
||||
|
||||
@@ -234,14 +234,31 @@
|
||||
<el-dialog
|
||||
v-model="dialogs.add"
|
||||
:title="editingId ? '编辑报销申请' : '新增报销申请'"
|
||||
width="780px"
|
||||
width="1040px"
|
||||
class="dialog-form-layout"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form label-position="top" class="bx-dialog-form">
|
||||
<div class="form-grid-2">
|
||||
<div class="form-grid-3">
|
||||
<el-form-item label="申请人">
|
||||
<el-select
|
||||
v-model="addForm.applicantId"
|
||||
placeholder="请选择申请人"
|
||||
filterable
|
||||
:disabled="!canChangeApplicant"
|
||||
style="width: 100%"
|
||||
@change="onApplicantChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="opt in applicantOptions"
|
||||
:key="opt.value"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="报销日期">
|
||||
<el-date-picker
|
||||
v-model="addForm.reimburseDate"
|
||||
@@ -340,21 +357,55 @@
|
||||
<el-button class="btn-ghost" @click="invoiceSelectVisible = true">
|
||||
<el-icon><FolderOpened /></el-icon>从发票夹选择
|
||||
</el-button>
|
||||
<span class="invoice-select-hint">发票请先在「我的发票夹」上传;此处仅做可选关联。</span>
|
||||
</div>
|
||||
<div v-if="selectedInvoices.length" class="invoice-selected-list">
|
||||
<el-tag
|
||||
v-for="inv in selectedInvoices"
|
||||
:key="inv.id"
|
||||
class="invoice-selected-tag"
|
||||
closable
|
||||
@close="removeSelectedInvoice(inv.id)"
|
||||
<div v-if="selectedInvoicePicks.length" class="invoice-selected-thumbs">
|
||||
<div
|
||||
v-for="pick in selectedInvoicePicks"
|
||||
:key="pick.key"
|
||||
class="invoice-selected-card"
|
||||
>
|
||||
{{ formatMoneyYuan(inv.amount) }} 元
|
||||
<template v-if="invoicePickLabel(inv)"> · {{ invoicePickLabel(inv) }}</template>
|
||||
</el-tag>
|
||||
<button
|
||||
type="button"
|
||||
class="invoice-selected-card__remove"
|
||||
title="移除"
|
||||
@click="removeSelectedInvoice(pick.key)"
|
||||
>
|
||||
<el-icon :size="12"><Close /></el-icon>
|
||||
</button>
|
||||
<div class="invoice-selected-card__preview">
|
||||
<template v-if="isBxImageFile(pick) && pick.previewUrl">
|
||||
<img :src="pick.previewUrl" :alt="pick.fileName" />
|
||||
</template>
|
||||
<template v-else-if="isBxVideoFile(pick)">
|
||||
<div class="invoice-selected-card__icon invoice-selected-card__icon--video">
|
||||
<el-icon :size="20"><VideoPlay /></el-icon>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="invoice-selected-card__icon invoice-selected-card__icon--doc">
|
||||
<el-icon :size="20"><Document /></el-icon>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="invoice-selected-card__meta">
|
||||
<span class="invoice-selected-card__name" :title="pick.fileName">
|
||||
{{ pick.fileName || '发票附件' }}
|
||||
</span>
|
||||
<div class="invoice-selected-card__footer">
|
||||
<span class="invoice-selected-card__amount">
|
||||
{{ formatMoneyYuan(pick.amount) }} 元
|
||||
</span>
|
||||
<el-icon
|
||||
class="invoice-selected-card__download"
|
||||
title="下载"
|
||||
@click="downloadSelectedInvoice(pick)"
|
||||
>
|
||||
<Download />
|
||||
</el-icon>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="invoice-selected-empty">未关联发票(可选)</div>
|
||||
</div>
|
||||
|
||||
<el-form label-position="top" class="bx-dialog-form">
|
||||
@@ -375,7 +426,8 @@
|
||||
|
||||
<BxInvoiceSelectDialog
|
||||
v-model="invoiceSelectVisible"
|
||||
:selected-ids="selectedInvoices.map((i) => String(i.id))"
|
||||
:selected-keys="selectedInvoicePicks.map((p) => p.key)"
|
||||
:owner-user-id="addForm.applicantId || undefined"
|
||||
@confirm="onInvoicesPicked"
|
||||
/>
|
||||
|
||||
@@ -541,12 +593,18 @@ import {
|
||||
Check,
|
||||
Search,
|
||||
RefreshLeft,
|
||||
FolderOpened
|
||||
FolderOpened,
|
||||
VideoPlay,
|
||||
Document,
|
||||
Download
|
||||
} from '@element-plus/icons-vue'
|
||||
import { reimburseApi, invoiceWalletApi } from '@/api/bx'
|
||||
import { fetchGetMenuCodes } from '@/api/auth'
|
||||
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'
|
||||
import { useApplicantOptions } from '@/hooks/bx/useApplicantOptions'
|
||||
import { useUserStore } from '@/store/modules/user'
|
||||
import {
|
||||
statusLabel,
|
||||
statusTagType,
|
||||
@@ -567,7 +625,13 @@ import BxInvoiceSelectDialog from '@/components/bx/base/BxInvoiceSelectDialog.vu
|
||||
import type { ViewField } from '@/components/business/system-view-dialog/types'
|
||||
import { bxViewKv, bxViewKvLong, bxViewKvMoney } from '@/utils/bx/view-kv'
|
||||
import { buildPageSummaryMethod, sumField } from '@/utils/bx/table-summary'
|
||||
import { type BxAttachmentItem, loadBxAttachments } from '@/utils/bx/attachment'
|
||||
import {
|
||||
type BxAttachmentItem,
|
||||
loadBxAttachments,
|
||||
downloadBxAttachment,
|
||||
isBxImageFile,
|
||||
isBxVideoFile
|
||||
} from '@/utils/bx/attachment'
|
||||
import { pickBxData } from '@/utils/http/bx'
|
||||
|
||||
type DialogKey = 'add' | 'view' | 'viewFlow'
|
||||
@@ -593,6 +657,38 @@ const { rows, total, currentPage, pageSize, rangeText, loading, refresh, search,
|
||||
)
|
||||
|
||||
const { expenseTree } = useExpenseItemTree()
|
||||
const { applicantOptions, loadApplicantOptions } = useApplicantOptions()
|
||||
const userStore = useUserStore()
|
||||
|
||||
const CHANGE_APPLICANT_PERM = 'bx:reimburseApply:changeApplicant'
|
||||
const canChangeApplicant = ref(false)
|
||||
|
||||
function isSuperAdminUser() {
|
||||
const roles = userStore.info?.roles || []
|
||||
return userStore.info?.role === 'super_admin' || roles.includes('super_admin')
|
||||
}
|
||||
|
||||
function currentUserId() {
|
||||
return String(userStore.info?.userId || userStore.info?.id || '')
|
||||
}
|
||||
|
||||
async function loadChangeApplicantPerm() {
|
||||
if (isSuperAdminUser()) {
|
||||
canChangeApplicant.value = true
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res: any = await fetchGetMenuCodes()
|
||||
if (res?.all || res?.isSuperAdmin) {
|
||||
canChangeApplicant.value = true
|
||||
return
|
||||
}
|
||||
const codes = new Set(res?.menuCodes || [])
|
||||
canChangeApplicant.value = codes.has(CHANGE_APPLICANT_PERM)
|
||||
} catch {
|
||||
canChangeApplicant.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function markDisabledExpenseNodes(tree: ExpenseItem[]): ExpenseItem[] {
|
||||
return tree.map((node) => ({
|
||||
@@ -639,6 +735,7 @@ function todayYmd() {
|
||||
}
|
||||
|
||||
const addForm = reactive({
|
||||
applicantId: '' as string,
|
||||
reimburseDate: todayYmd(),
|
||||
title: '',
|
||||
remark: '',
|
||||
@@ -687,7 +784,17 @@ const viewAttachments = ref<BxAttachmentItem[]>([])
|
||||
const viewPayAttachments = ref<BxAttachmentItem[]>([])
|
||||
const viewOffsetAttachments = ref<BxAttachmentItem[]>([])
|
||||
const viewLinkedInvoices = ref<any[]>([])
|
||||
const selectedInvoices = ref<any[]>([])
|
||||
type SelectedInvoicePick = {
|
||||
key: string
|
||||
invoiceId: string | number
|
||||
attachmentId: string | number
|
||||
amount: number | string
|
||||
fileName: string
|
||||
fileType?: string
|
||||
previewUrl?: string
|
||||
}
|
||||
|
||||
const selectedInvoicePicks = ref<SelectedInvoicePick[]>([])
|
||||
const invoiceSelectVisible = ref(false)
|
||||
const walletBalance = ref(0)
|
||||
const editingId = ref<number | null>(null)
|
||||
@@ -706,7 +813,8 @@ async function refreshGeneratedTitle() {
|
||||
try {
|
||||
const res: any = await reimburseApi.generateTitle(
|
||||
addForm.reimburseDate,
|
||||
editingId.value ?? undefined
|
||||
editingId.value ?? undefined,
|
||||
addForm.applicantId || undefined
|
||||
)
|
||||
addForm.title = res.data || ''
|
||||
titleAutoLinked.value = true
|
||||
@@ -725,9 +833,16 @@ async function onReimburseDateChange() {
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshWalletBalance() {
|
||||
async function onApplicantChange() {
|
||||
selectedInvoicePicks.value = []
|
||||
await Promise.all([refreshWalletBalance(), refreshGeneratedTitle()])
|
||||
}
|
||||
|
||||
async function refreshWalletBalance(ownerUserId?: string) {
|
||||
try {
|
||||
const res: any = await invoiceWalletApi.mineSummary()
|
||||
const res: any = await invoiceWalletApi.mineSummary({
|
||||
userId: ownerUserId || addForm.applicantId || undefined
|
||||
})
|
||||
const data: any = pickBxData(res) || {}
|
||||
walletBalance.value = Number(data.balance ?? 0)
|
||||
} catch {
|
||||
@@ -735,35 +850,84 @@ async function refreshWalletBalance() {
|
||||
}
|
||||
}
|
||||
|
||||
function onInvoicesPicked(rows: any[]) {
|
||||
selectedInvoices.value = rows
|
||||
function onInvoicesPicked(picks: any[]) {
|
||||
selectedInvoicePicks.value = (picks || []).map((pick) => ({
|
||||
key: String(pick.key),
|
||||
invoiceId: pick.invoiceId,
|
||||
attachmentId: pick.attachmentId,
|
||||
amount: pick.amount,
|
||||
fileName: pick.file?.fileName || '',
|
||||
fileType: pick.file?.fileType || '',
|
||||
previewUrl: pick.file?.previewUrl || ''
|
||||
}))
|
||||
}
|
||||
|
||||
function invoicePickLabel(inv: any) {
|
||||
const list = Array.isArray(inv?.attachments) ? inv.attachments : []
|
||||
if (list.length) {
|
||||
return list
|
||||
.map((a: any) => a.fileName || a.file_name)
|
||||
.filter(Boolean)
|
||||
.join('、')
|
||||
}
|
||||
return inv?.fileName || ''
|
||||
function removeSelectedInvoice(key: string) {
|
||||
selectedInvoicePicks.value = selectedInvoicePicks.value.filter((p) => p.key !== key)
|
||||
}
|
||||
|
||||
function removeSelectedInvoice(id: string | number) {
|
||||
selectedInvoices.value = selectedInvoices.value.filter((i) => String(i.id) !== String(id))
|
||||
function downloadSelectedInvoice(pick: SelectedInvoicePick) {
|
||||
if (!pick.attachmentId) return
|
||||
downloadBxAttachment({
|
||||
id: pick.attachmentId,
|
||||
fileName: pick.fileName || '发票附件'
|
||||
})
|
||||
}
|
||||
|
||||
async function loadSelectedPicksFromInvoices(invoices: any[]) {
|
||||
const picks: SelectedInvoicePick[] = []
|
||||
await Promise.all(
|
||||
(invoices || []).map(async (inv) => {
|
||||
try {
|
||||
const files = await loadBxAttachments('invoice', inv.id)
|
||||
const file = files[0]
|
||||
if (file) {
|
||||
picks.push({
|
||||
key: `${inv.id}:${file.id}`,
|
||||
invoiceId: inv.id,
|
||||
attachmentId: file.id,
|
||||
amount: inv.amount,
|
||||
fileName: file.fileName || '',
|
||||
fileType: file.fileType || '',
|
||||
previewUrl: file.previewUrl || ''
|
||||
})
|
||||
return
|
||||
}
|
||||
} catch {
|
||||
/* fallback below */
|
||||
}
|
||||
picks.push({
|
||||
key: String(inv.id),
|
||||
invoiceId: inv.id,
|
||||
attachmentId: inv.id,
|
||||
amount: inv.amount,
|
||||
fileName: '',
|
||||
fileType: '',
|
||||
previewUrl: ''
|
||||
})
|
||||
})
|
||||
)
|
||||
const order = new Map((invoices || []).map((inv: any, idx: number) => [String(inv.id), idx]))
|
||||
picks.sort((a, b) => (order.get(String(a.invoiceId)) ?? 0) - (order.get(String(b.invoiceId)) ?? 0))
|
||||
selectedInvoicePicks.value = picks
|
||||
}
|
||||
|
||||
async function openAddDialog() {
|
||||
addForm.applicantId = currentUserId()
|
||||
addForm.reimburseDate = todayYmd()
|
||||
addForm.title = ''
|
||||
addForm.remark = ''
|
||||
addForm.details = [{ expenseItemId: '', amount: '', remark: '' }]
|
||||
selectedInvoices.value = []
|
||||
selectedInvoicePicks.value = []
|
||||
editingId.value = null
|
||||
titleAutoLinked.value = true
|
||||
dialogs.add = true
|
||||
await Promise.all([refreshGeneratedTitle(), refreshWalletBalance()])
|
||||
await Promise.all([
|
||||
loadApplicantOptions(),
|
||||
loadChangeApplicantPerm(),
|
||||
refreshGeneratedTitle(),
|
||||
refreshWalletBalance()
|
||||
])
|
||||
}
|
||||
|
||||
function isDraftEditable(row?: any) {
|
||||
@@ -832,6 +996,7 @@ async function openEditDialog(row: any) {
|
||||
try {
|
||||
const res: any = await reimburseApi.getById(row.id)
|
||||
const data = res.data || res
|
||||
addForm.applicantId = String(data.applicantId || currentUserId())
|
||||
addForm.title = data.title || ''
|
||||
addForm.reimburseDate = data.reimburseDate || todayYmd()
|
||||
titleAutoLinked.value = isAutoReimburseTitle(addForm.title)
|
||||
@@ -845,9 +1010,14 @@ async function openEditDialog(row: any) {
|
||||
addForm.details = [{ expenseItemId: '', amount: '', remark: '' }]
|
||||
}
|
||||
editingId.value = row.id
|
||||
selectedInvoices.value = Array.isArray(data.invoices) ? data.invoices : []
|
||||
const invoices = Array.isArray(data.invoices) ? data.invoices : []
|
||||
dialogs.add = true
|
||||
await refreshWalletBalance()
|
||||
await Promise.all([
|
||||
loadApplicantOptions(),
|
||||
loadChangeApplicantPerm(),
|
||||
refreshWalletBalance(),
|
||||
loadSelectedPicksFromInvoices(invoices)
|
||||
])
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e.message || '加载失败')
|
||||
}
|
||||
@@ -922,13 +1092,20 @@ async function handleToolbarSubmit() {
|
||||
ElMessage.warning('仅草稿或已驳回的报销单可提交')
|
||||
return
|
||||
}
|
||||
await refreshWalletBalance()
|
||||
const totalNeed = selectedRows.value.reduce((s, r) => s + Number(r.amount || 0), 0)
|
||||
if (Number(walletBalance.value) < totalNeed) {
|
||||
ElMessage.warning(
|
||||
`发票额度不足(余额 ${formatMoneyYuan(walletBalance.value)},本次 ${formatMoneyYuan(totalNeed)})`
|
||||
)
|
||||
return
|
||||
// 按申请人分别校验发票余额(代申请时用申请人额度)
|
||||
const needByApplicant = new Map<string, number>()
|
||||
for (const row of selectedRows.value) {
|
||||
const aid = String(row.applicantId || currentUserId())
|
||||
needByApplicant.set(aid, (needByApplicant.get(aid) || 0) + Number(row.amount || 0))
|
||||
}
|
||||
for (const [aid, need] of needByApplicant) {
|
||||
await refreshWalletBalance(aid)
|
||||
if (Number(walletBalance.value) < need) {
|
||||
ElMessage.warning(
|
||||
`发票额度不足(余额 ${formatMoneyYuan(walletBalance.value)},本次 ${formatMoneyYuan(need)})`
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
loadingMap.submit = true
|
||||
try {
|
||||
@@ -955,8 +1132,11 @@ async function submitAdd() {
|
||||
ElMessage.warning('请为每条报销明细填写报销事由')
|
||||
return
|
||||
}
|
||||
const invoiceIds = selectedInvoices.value.map((i) => String(i.id))
|
||||
const invoiceIds = Array.from(
|
||||
new Set(selectedInvoicePicks.value.map((p) => String(p.invoiceId)))
|
||||
)
|
||||
const payload = {
|
||||
applicantId: addForm.applicantId || undefined,
|
||||
reimburseDate: addForm.reimburseDate,
|
||||
title: addForm.title || undefined,
|
||||
remark: addForm.remark,
|
||||
@@ -977,11 +1157,12 @@ async function submitAdd() {
|
||||
ElMessage.success('新增成功')
|
||||
}
|
||||
dialogs.add = false
|
||||
addForm.applicantId = currentUserId()
|
||||
addForm.reimburseDate = todayYmd()
|
||||
addForm.title = ''
|
||||
addForm.remark = ''
|
||||
addForm.details = [{ expenseItemId: '', amount: '', remark: '' }]
|
||||
selectedInvoices.value = []
|
||||
selectedInvoicePicks.value = []
|
||||
editingId.value = null
|
||||
await refreshList()
|
||||
} catch (e: any) {
|
||||
@@ -1068,7 +1249,7 @@ async function openFlowDialog(row?: any) {
|
||||
}
|
||||
|
||||
async function handleSubmit(row: any) {
|
||||
await refreshWalletBalance()
|
||||
await refreshWalletBalance(String(row.applicantId || currentUserId()))
|
||||
if (Number(walletBalance.value) < Number(row.amount || 0)) {
|
||||
ElMessage.warning(
|
||||
`发票额度不足(余额 ${formatMoneyYuan(walletBalance.value)},本次 ${formatMoneyYuan(row.amount)})`
|
||||
@@ -1154,23 +1335,121 @@ function viewDetailSummary({ columns, data }: { columns: any[]; data: any[] }) {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.invoice-select-hint {
|
||||
font-size: 12px;
|
||||
color: var(--mint-text-muted, #64748b);
|
||||
}
|
||||
|
||||
.invoice-selected-list {
|
||||
.invoice-selected-thumbs {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.invoice-selected-tag {
|
||||
max-width: 100%;
|
||||
.invoice-selected-card {
|
||||
position: relative;
|
||||
width: 96px;
|
||||
border: 1px solid var(--border, #d9e8e2);
|
||||
border-radius: 6px;
|
||||
background: var(--surface, #fff);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.invoice-selected-empty {
|
||||
font-size: 13px;
|
||||
.invoice-selected-card__remove {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: rgba(15, 23, 42, 0.55);
|
||||
color: #fff;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: var(--el-color-danger);
|
||||
}
|
||||
}
|
||||
|
||||
.invoice-selected-card__preview {
|
||||
width: 100%;
|
||||
height: 64px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--table-head, #f8fafc);
|
||||
overflow: hidden;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.invoice-selected-card__icon {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&--video {
|
||||
background: #ede9fe;
|
||||
color: #7c3aed;
|
||||
}
|
||||
|
||||
&--doc {
|
||||
background: #e0f2fe;
|
||||
color: #0284c7;
|
||||
}
|
||||
}
|
||||
|
||||
.invoice-selected-card__meta {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
padding: 4px 6px;
|
||||
}
|
||||
|
||||
.invoice-selected-card__name {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 1;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
font-size: 10px;
|
||||
line-height: 1.3;
|
||||
color: var(--text, #1e293b);
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.invoice-selected-card__footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.invoice-selected-card__amount {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: var(--primary-dark, #059669);
|
||||
}
|
||||
|
||||
.invoice-selected-card__download {
|
||||
flex-shrink: 0;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border-radius: 4px;
|
||||
color: var(--mint-text-muted, #64748b);
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: var(--primary, #10b981);
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user