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
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user