Files
shanxia2.0/web-admin/src/views/bx/view/all/index.vue
T

902 lines
32 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!-- 全部申请单(总经理) -->
<!-- eslint-disable vue/no-v-model-argument -->
<template>
<div class="page-container">
<section class="panel">
<div class="filter-block">
<el-form
:model="filterForm"
class="filter-form"
@submit.prevent
style="--filter-label-width: 110px"
>
<div class="filter-grid">
<el-form-item label="单号">
<el-input v-model="filterForm.code" placeholder="请输入单号" clearable />
</el-form-item>
<el-form-item label="业务类型">
<el-select v-model="filterForm.bizType" placeholder="全部" clearable>
<el-option v-for="t in bizTypeOptions" :key="t" :label="t" :value="t" />
</el-select>
</el-form-item>
<el-form-item label="申请人">
<el-select
v-model="filterForm.applicantId"
placeholder="请选择申请人"
clearable
filterable
>
<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-select v-model="filterForm.status" placeholder="全部" clearable>
<el-option v-for="s in statusOptions" :key="s" :label="s" :value="s" />
</el-select>
</el-form-item>
<el-form-item label="申请时间">
<el-date-picker
v-model="filterForm.applyDateRange"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="YYYY-MM-DD"
clearable
style="width: 100%"
/>
</el-form-item>
<el-form-item label="金额区间(元)">
<el-input v-model="filterForm.amountRange" placeholder="如 1000-5000" clearable />
</el-form-item>
<el-form-item label="当前节点">
<el-select v-model="filterForm.currentNode" placeholder="全部" clearable>
<el-option v-for="n in nodeOptions" :key="n" :label="n" :value="n" />
</el-select>
</el-form-item>
</div>
<div class="filter-actions">
<div class="filter-actions-start" />
<div class="filter-actions-end">
<el-button class="btn-ghost" :loading="loading" @click="handleReset">
<el-icon><RefreshLeft /></el-icon>重置
</el-button>
<el-button class="btn-main" type="primary" :loading="loading" @click="handleSearch">
<el-icon><Search /></el-icon>搜索
</el-button>
</div>
</div>
</el-form>
</div>
<div class="list-toolbar">
<div class="list-toolbar-row">
<ListQuickSearchInput
v-model="quickSearchKeyword"
placeholder="单号/标题/申请人"
@search="handleQuickSearch"
@clear="handleQuickSearchClear"
/>
<ListExportDropdown
:export-fn="exportBxViewAll"
:get-filter-params="getBxViewExportFilterParams"
:has-selection="true"
:selected-ids="selectedRows.map((r) => String(r.id))"
:visible-columns="bxViewExportColumns"
filename="业务视图.xlsx"
/>
<ListToolbarEndActions
:loading="loading"
:column-defs="listColumnDefs"
v-model:visible-columns="visibleColumns"
v-model:check-all="checkAll"
:is-indeterminate="isIndeterminate"
@refresh="loadData"
@reset-columns="resetToDefault"
/>
</div>
</div>
<div class="list-body list-wrap">
<div ref="allTableWrapRef" class="table-scroll bx-list-table-wrap">
<ListTable
ref="allTableRef"
table-key="bx-view-all"
class="list-table"
:height="tableHeight"
:data="pager.pagedRows.value"
v-loading="loading"
stripe
@row-dblclick="openViewDetail"
@selection-change="handleSelectionChange"
@header-dragend="() => allStatsRowRef?.resync?.()"
>
<el-table-column type="selection" width="55" align="center" header-align="center" />
<el-table-column
type="index"
label="序号"
width="68"
align="center"
header-align="center"
/>
<el-table-column
v-if="isColumnVisible('applyTime')"
prop="applyTime"
label="申请时间"
min-width="160"
align="center"
header-align="center"
show-overflow-tooltip
/>
<el-table-column
prop="applyCode"
label="申请单号"
class-name="col-apply-code"
min-width="140"
align="center"
header-align="center"
show-overflow-tooltip
>
<template #default="{ row }">
<el-link type="primary" @click="openViewDetail(row)">{{ row.applyCode }}</el-link>
</template>
</el-table-column>
<el-table-column
v-if="isColumnVisible('bizType')"
prop="bizType"
label="业务类型"
min-width="100"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-tag :type="bizTypeTagType(row.bizType)" size="small">
{{ row.bizType }}
</el-tag>
</template>
</el-table-column>
<el-table-column
v-if="isColumnVisible('applicantName')"
prop="applicantName"
label="申请人"
min-width="100"
align="center"
header-align="center"
/>
<el-table-column
v-if="isColumnVisible('title')"
prop="title"
label="申请标题"
min-width="180"
align="left"
header-align="center"
show-overflow-tooltip
/>
<el-table-column
v-if="isColumnVisible('amount')"
prop="amount"
label="申请金额(元)"
:formatter="moneyTableFormatter"
class-name="col-money"
min-width="240"
align="right"
header-align="center"
/>
<el-table-column
v-if="isColumnVisible('status')"
prop="status"
label="状态"
min-width="110"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-tag :type="statusTagType(row.status)" size="small">
{{ statusLabel(row.status) }}
</el-tag>
</template>
</el-table-column>
<el-table-column
v-if="isColumnVisible('currentNode')"
prop="currentNode"
label="当前节点"
min-width="120"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-tag
v-if="shouldShowWorkflowNodeTag(row.currentNode, row.status)"
:type="workflowNodeTagType(row.currentNode, row.status)"
size="small"
>
{{ workflowNodeLabel(row.currentNode, row.status) }}
</el-tag>
<span v-else>-</span>
</template>
</el-table-column>
</ListTable>
</div>
<div ref="allBelowRef">
<ListColumnStatsRow
ref="allStatsRowRef"
storage-key="bx-view-all-column-stats"
:columns="allStatsRowColumns"
:data="pager.pagedRows.value"
:table-wrap-el="allTableWrapRef"
/>
<div class="pagination list-pager-bar">
<span class="list-range">{{ pager.rangeText.value }}</span>
<el-pagination
v-model:current-page="pager.currentPage.value"
v-model:page-size="pager.pageSize.value"
:total="pager.total.value"
layout="total, sizes, prev, pager, next"
:page-sizes="[10, 20, 100, 500]"
@size-change="pager.onSizeChange"
/>
</div>
</div>
</div>
</section>
<el-dialog
v-model="dialogs.viewDetail"
title="申请单详情"
width="1040px"
class="dialog-form-layout dialog-view-xl"
align-center
destroy-on-close
>
<div class="dlg-view">
<div class="dlg-view-hero">
<div class="dlg-view-hero-top">
<h2 class="dlg-view-title">{{ viewHero.applyCode || '-' }}</h2>
<div class="dlg-view-tags">
<el-tag :type="bizTypeTagType(viewHero.bizType)" size="small">
{{ viewHero.bizType || '-' }}
</el-tag>
<el-tag v-if="viewHero.status" :type="statusTagType(viewHero.status)" size="small">
{{ statusLabel(viewHero.status) }}
</el-tag>
</div>
</div>
<p class="dlg-view-meta">
金额(元):<b class="money-em">{{ formatMoneyYuan(viewHero.amount || 0) }}</b> ·
申请人:{{ viewHero.applicantName || '-' }}
</p>
</div>
<div class="dlg-view-section">
<h4 class="dlg-view-section-title">基础信息</h4>
<BxViewKvTable :fields="viewDetailKvFields" mode="triple" />
</div>
<template v-if="viewHero.bizType === '报销单'">
<div class="dlg-view-section">
<h4 class="dlg-view-section-title">报销明细</h4>
<el-table
:data="viewData.details || []"
border
size="small"
show-summary
:summary-method="viewDetailSummary"
class="view-detail-table"
>
<el-table-column type="index" label="序号" width="68" align="center" />
<el-table-column prop="expenseName" label="费用项目" min-width="160" />
<el-table-column
prop="amount"
label="金额(元)"
min-width="120"
class-name="col-money"
>
<template #default="{ row }">
{{ formatMoneyYuan(row.amount || 0) }}
</template>
</el-table-column>
<el-table-column prop="remark" label="报销事由" min-width="140">
<template #default="{ row }">
{{ row.remark || '-' }}
</template>
</el-table-column>
<el-table-column prop="occurDate" label="发生时间" min-width="120" align="center" header-align="center">
<template #default="{ row }">{{ row.occurDate || '—' }}</template>
</el-table-column>
</el-table>
</div>
<div v-if="viewLinkedInvoiceFiles.length" class="dlg-view-section">
<h4 class="dlg-view-section-title">关联发票</h4>
<BxAttachmentReadonly :files="viewLinkedInvoiceFiles" />
</div>
<div v-if="viewAttachments.length" class="dlg-view-section">
<h4 class="dlg-view-section-title">申请附件</h4>
<BxAttachmentReadonly :files="viewAttachments" />
</div>
<div v-if="viewPayAttachments.length" class="dlg-view-section">
<h4 class="dlg-view-section-title">发放附件</h4>
<BxAttachmentReadonly :files="viewPayAttachments" />
</div>
<div v-if="viewOffsetAttachments.length" class="dlg-view-section">
<h4 class="dlg-view-section-title">冲抵附件</h4>
<BxAttachmentReadonly :files="viewOffsetAttachments" />
</div>
</template>
<template v-else-if="viewHero.bizType === '备用金'">
<BaseDetailTableSection
title="冲抵记录"
:data="viewOffsetRecords"
empty-text="暂无冲抵记录"
>
<el-table :data="viewOffsetRecords" border size="small" class="view-detail-table">
<el-table-column type="index" label="序号" width="68" align="center" />
<el-table-column
prop="reimburseApplyCode"
label="报销单号"
min-width="130"
align="center"
show-overflow-tooltip
/>
<el-table-column
prop="reimburseApplicantName"
label="报销申请人"
min-width="110"
align="center"
/>
<el-table-column
prop="reimburseTitle"
label="报销标题"
min-width="160"
align="left"
show-overflow-tooltip
/>
<el-table-column
label="冲抵金额(元)"
min-width="120"
class-name="col-money"
align="right"
>
<template #default="{ row: offsetRow }">
{{ formatMoneyYuan(offsetRow.offsetAmount || 0) }}
</template>
</el-table-column>
<el-table-column prop="createTime" label="冲抵时间" min-width="160" align="center" />
<el-table-column prop="operator" label="操作人" min-width="100" align="center" />
</el-table>
</BaseDetailTableSection>
<div v-if="viewIssueAttachments.length" class="dlg-view-section">
<h4 class="dlg-view-section-title">发放附件</h4>
<BxAttachmentReadonly :files="viewIssueAttachments" />
</div>
</template>
<BxApprovalFlowTabs
:nodes="viewFlowNodes"
:history="viewApprovalHistory"
:loading="viewFlowLoading"
/>
</div>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import ListToolbarEndActions from '@/components/business/list-toolbar-end-actions/index.vue'
import ListExportDropdown from '@/components/business/list-export-dropdown/index.vue'
import ListQuickSearchInput from '@/components/business/list-quick-search-input/index.vue'
import ListColumnStatsRow from '@/components/business/list-column-stats-row/index.vue'
import type { StatsRowColumn } from '@/utils/list-column-stats'
import { useDbInstantSearch } from '@/composables/useDbInstantSearch'
import { usePersistedListColumns } from '@/composables/usePersistedListColumns'
import { useListTableViewportHeight } from '@/composables/useListTableViewportHeight'
import { computed, onMounted, reactive, ref, nextTick } from 'vue'
import { ElMessage } from 'element-plus'
import { Search, RefreshLeft } from '@element-plus/icons-vue'
import { advanceApi, paymentApi, reimburseApi } from '@/api/bx'
import { pickBxPageResult } from '@/utils/http/bx'
import { fetchAllPagedRecords } from '@/utils/fetch-paged-list'
import {
bizTypeTagType,
statusLabel,
statusTagType,
formatMoneyYuan,
moneyTableFormatter,
workflowNodeDisplay,
workflowNodeLabel,
workflowNodeTagType,
shouldShowWorkflowNodeTag
} from '@/utils/bx/format'
import BxApprovalFlowTabs from '@/components/bx/base/BxApprovalFlowTabs.vue'
import BxViewKvTable from '@/components/bx/base/BxViewKvTable.vue'
import BxAttachmentReadonly from '@/components/bx/base/BxAttachmentReadonly.vue'
import BaseDetailTableSection from '@/components/bx/base/BaseDetailTableSection.vue'
import type { ViewField } from '@/components/business/system-view-dialog/types'
import { bxViewKv, bxViewKvLong, bxViewKvMoney } from '@/utils/bx/view-kv'
import {
type BxAttachmentItem,
fillBxAttachmentPreviews,
loadBxAttachments
} from '@/utils/bx/attachment'
import { invoicesToLinkedAttachmentFiles } from '@/utils/bx/invoice-link-files'
import { buildApplyDateRangeQuery, type ApplyDateRange } from '@/utils/bx/apply-date-filter'
import { usePagedTable } from '@/hooks/bx/usePagedTable'
import { useApplicantOptions } from '@/hooks/bx/useApplicantOptions'
const STATUS_LABEL_TO_CODE: Record<string, string> = {
待提交: 'draft',
审批中: 'pending',
审批通过: 'approved',
审批驳回: 'rejected'
}
type DialogKey = 'viewDetail'
const loading = ref(false)
async function exportBxViewAll(payload: Record<string, any>) {
const biz = appliedFilter.bizType || filterForm.bizType || ''
const ids: string[] = payload.ids || []
if (ids.length) {
const selected = selectedRows.value.filter((r: any) => ids.includes(String(r.id)))
const adv = selected.filter((r: any) => r.bizType === '备用金')
const rei = selected.filter((r: any) => r.bizType === '报销单')
if (adv.length && rei.length) {
throw new Error('请选择同一业务类型的记录再导出')
}
if (adv.length) {
return advanceApi.exportList({ ...payload, ids: adv.map((r: any) => String(r.id)) })
}
return reimburseApi.exportList({ ...payload, ids: rei.map((r: any) => String(r.id)) })
}
if (biz === '备用金') return advanceApi.exportList(payload)
if (biz === '报销单') return reimburseApi.exportList(payload)
throw new Error('请先筛选业务类型(备用金/报销单)后再导出')
}
function getBxViewExportFilterParams() {
const q: Record<string, any> = {}
const kw = (quickSearchKeyword.value.trim() || filterForm.keyword || appliedFilter.keyword || '').trim()
if (kw) q.keyword = kw
const status = filterForm.status || appliedFilter.status
if (status) q.status = status
buildApplyDateRangeQuery(filterForm.applyDateRange || appliedFilter.applyDateRange, q)
return q
}
const bxViewExportColumns = computed(() => {
const cols = [...visibleColumns.value]
if (!cols.includes('applyCode')) cols.unshift('applyCode')
return cols
})
const selectedRows = ref<any[]>([])
const dialogs = reactive<Record<DialogKey, boolean>>({
viewDetail: false
})
const mergedRows = ref<any[]>([])
const { applicantOptions, loadApplicantOptions } = useApplicantOptions()
const listColumnDefs = [
{ prop: 'applyTime', label: '申请时间' },
{ prop: 'bizType', label: '业务类型' },
{ prop: 'applicantName', label: '申请人' },
{ prop: 'title', label: '申请标题' },
{ prop: 'amount', label: '申请金额(元)' },
{ prop: 'status', label: '状态' },
{ prop: 'currentNode', label: '当前节点', defaultVisible: false }
]
const { visibleColumns, checkAll, isIndeterminate, isColumnVisible, resetToDefault } =
usePersistedListColumns('bx-view-all-list-columns', listColumnDefs)
const allTableWrapRef = ref<HTMLElement | null>(null)
const allBelowRef = ref<HTMLElement | null>(null)
const allTableRef = ref<any>(null)
const allStatsRowRef = ref<{ resync?: () => void } | null>(null)
const { tableHeight, recalc: recalcTableHeight } = useListTableViewportHeight({
tableEl: allTableWrapRef,
pagerEl: allBelowRef,
tableRef: allTableRef
})
const allStatsRowColumns = computed((): StatsRowColumn[] => {
const cols: StatsRowColumn[] = [
{ key: '__selection', interactive: false },
{ key: '__index', interactive: false }
]
if (isColumnVisible('applyTime')) {
cols.push({ key: 'applyTime', interactive: true, prop: 'applyTime' })
}
cols.push({ key: 'applyCode', interactive: true, prop: 'applyCode' })
for (const def of listColumnDefs) {
if (def.prop === 'applyTime') continue
if (!isColumnVisible(def.prop)) continue
cols.push({
key: def.prop,
interactive: true,
prop: def.prop,
money: def.prop === 'amount'
})
}
return cols
})
const quickSearchKeyword = ref('')
const appliedQuickSearch = ref('')
const filterForm = reactive({
code: '',
bizType: '' as string,
applicantId: undefined as string | number | undefined,
status: '' as string,
applyDateRange: null as ApplyDateRange,
amountRange: '',
currentNode: '' as string
})
const appliedFilter = reactive({
code: '',
bizType: '' as string,
applicantId: undefined as string | number | undefined,
status: '' as string,
applyDateRange: null as ApplyDateRange,
amountRange: '',
currentNode: '' as string
})
function syncAppliedFilter() {
Object.assign(appliedFilter, { ...filterForm })
}
/** 接口已支持的条件在 loadData 中下发;此处仅处理合并列表后的本地条件 */
function filterMergedRows(rows: any[]) {
let list = [...rows]
const quickKw = appliedQuickSearch.value.trim().toLowerCase()
if (quickKw) {
list = list.filter(
(r: any) =>
String(r.applyCode || '')
.toLowerCase()
.includes(quickKw) ||
String(r.title || '')
.toLowerCase()
.includes(quickKw) ||
String(r.applicantName || '')
.toLowerCase()
.includes(quickKw)
)
}
if (appliedFilter.bizType && appliedFilter.bizType !== '全部') {
list = list.filter((r: any) => r.bizType === appliedFilter.bizType)
}
if (appliedFilter.status === '已发放') {
list = list.filter((r: any) => ['issued', 'paid', 'offset'].includes(r.status))
}
if (appliedFilter.currentNode && appliedFilter.currentNode !== '全部') {
list = list.filter((r: any) => (r.currentNode || '') === appliedFilter.currentNode)
}
if (appliedFilter.amountRange?.trim()) {
const parts = appliedFilter.amountRange
.split(/[-–]/)
.map((x: string) => Number(String(x).trim()))
if (parts.length >= 2 && !parts.some((n) => Number.isNaN(n))) {
const lo = Math.min(parts[0], parts[1])
const hi = Math.max(parts[0], parts[1])
list = list.filter((r: any) => {
const amt = Number(r.amount || 0)
return amt >= lo && amt <= hi
})
}
}
return list
}
function buildApiQuery() {
const q: Record<string, string | number> = {}
const code = appliedFilter.code.trim()
if (code) q.keyword = code
if (appliedFilter.applicantId != null && appliedFilter.applicantId !== '') {
q.applicantId = String(appliedFilter.applicantId)
}
if (appliedFilter.status && appliedFilter.status !== '全部' && appliedFilter.status !== '已发放') {
const statusCode = STATUS_LABEL_TO_CODE[appliedFilter.status]
if (statusCode) q.status = statusCode
}
buildApplyDateRangeQuery(appliedFilter.applyDateRange, q)
return q
}
const filteredMergedRows = computed(() => filterMergedRows(mergedRows.value))
const pager = usePagedTable(() => filteredMergedRows.value, { initialPageSize: 20 })
const currentRow = ref<any>(null)
const viewData = ref<Record<string, any>>({})
const viewHero = computed(() => {
const row = currentRow.value || {}
const detail = viewData.value || {}
return {
...row,
...detail,
bizType: row.bizType || detail.bizType,
applyCode: detail.applyCode || row.applyCode,
applicantName: detail.applicantName || row.applicantName,
amount: detail.amount ?? row.amount,
currentNode: detail.currentNode ?? row.currentNode,
status: detail.status ?? row.status
}
})
const viewDetailKvFields = computed<ViewField[]>(() => {
const d = viewHero.value
if (d.bizType === '备用金') {
return [
bxViewKv('申请单号', d.applyCode, { long: false }),
bxViewKv('业务类型', d.bizType, { long: false, tagType: bizTypeTagType(d.bizType) }),
bxViewKv('申请人', d.applicantName, { long: false }),
bxViewKvMoney(
'实际发放金额(元)',
d.actualAmount != null ? formatMoneyYuan(d.actualAmount) : '—',
{ long: false }
),
bxViewKvMoney('申请金额(元)', formatMoneyYuan(d.amount || 0), { long: false }),
bxViewKvMoney('冲抵总金额(元)', formatMoneyYuan(d.offsetAmount || 0), { long: false }),
bxViewKv('状态', statusLabel(d.status), { long: false, tagType: statusTagType(d.status) }),
bxViewKv('申请时间', d.applyTime, { long: false }),
bxViewKv('申请原因', d.reason || d.title, { long: false })
]
}
return [
bxViewKv('申请单号', d.applyCode, { long: false }),
bxViewKv('业务类型', d.bizType, { long: false, tagType: bizTypeTagType(d.bizType) }),
bxViewKv('报销日期', d.reimburseDate, { long: false }),
bxViewKv('报销标题', d.title, { long: false }),
bxViewKv('申请人', d.applicantName, { long: false }),
bxViewKvMoney('申请金额(元)', formatMoneyYuan(d.amount || 0), { long: false }),
bxViewKv('状态', statusLabel(d.status), { long: false, tagType: statusTagType(d.status) }),
bxViewKv('当前节点', workflowNodeDisplay(d.currentNode, d.status), { long: false }),
bxViewKv('申请时间', d.applyTime, { long: false }),
bxViewKvLong('报销说明', d.remark, { fullSpan: true })
]
})
const viewFlowNodes = ref<any[]>([])
const viewApprovalHistory = ref<any[]>([])
const viewFlowLoading = ref(false)
const viewLinkedInvoiceFiles = ref<BxAttachmentItem[]>([])
const viewAttachments = ref<BxAttachmentItem[]>([])
const viewPayAttachments = ref<BxAttachmentItem[]>([])
const viewOffsetAttachments = ref<BxAttachmentItem[]>([])
const viewIssueAttachments = ref<BxAttachmentItem[]>([])
const viewOffsetRecords = ref<any[]>([])
function viewDetailSummary({ columns, data }: { columns: any[]; data: any[] }) {
const sums: string[] = []
columns.forEach((_: any, index: number) => {
if (index === 0) {
sums[index] = '合计'
return
}
if (index === 2) {
const total = data.reduce((sum: number, row: any) => sum + Number(row.amount || 0), 0)
sums[index] = formatMoneyYuan(total)
return
}
sums[index] = ''
})
return sums
}
const bizTypeOptions = ['全部', '报销单', '备用金']
const statusOptions = ['全部', '待提交', '审批中', '审批通过', '审批驳回', '已发放']
const nodeOptions = [
'全部',
'草稿',
'发起人主管审批',
'财务复核',
'总经理审批',
'已完成',
'已驳回',
'已发放'
]
function mapAdvanceRow(r: any) {
return {
...r,
bizType: '备用金',
title: r.reason,
applyCode: r.applyCode || r.code,
applicantName: r.applicantName || r.user,
applicantId: r.applicantId
}
}
function mapReimburseRow(r: any) {
return {
...r,
bizType: '报销单',
title: r.title,
applyCode: r.applyCode || r.code,
applicantName: r.applicantName || r.user,
applicantId: r.applicantId
}
}
async function loadData() {
loading.value = true
try {
const apiQuery = buildApiQuery()
const [advRes, reimRes] = await Promise.allSettled([
fetchAllPagedRecords(async (page, pageSize) =>
pickBxPageResult(await advanceApi.list({ page, pageSize, ...apiQuery }))
),
fetchAllPagedRecords(async (page, pageSize) =>
pickBxPageResult(await reimburseApi.list({ page, pageSize, ...apiQuery }))
)
])
const advRows = advRes.status === 'fulfilled' ? advRes.value.map(mapAdvanceRow) : []
const reimRows = reimRes.status === 'fulfilled' ? reimRes.value.map(mapReimburseRow) : []
mergedRows.value = [...advRows, ...reimRows]
} catch {
// error handled by interceptor
} finally {
loading.value = false
}
}
function handleSearch() {
quickSearchKeyword.value = ''
appliedQuickSearch.value = ''
syncAppliedFilter()
pager.currentPage.value = 1
loadData()
}
useDbInstantSearch(
() => ({
code: filterForm.code,
bizType: filterForm.bizType,
applicantId: filterForm.applicantId,
status: filterForm.status,
applyDateRange: filterForm.applyDateRange,
amountRange: filterForm.amountRange,
currentNode: filterForm.currentNode
}),
handleSearch
)
function handleReset() {
quickSearchKeyword.value = ''
appliedQuickSearch.value = ''
Object.assign(filterForm, {
code: '',
bizType: '',
applicantId: undefined,
status: '',
applyDateRange: null,
amountRange: '',
currentNode: ''
})
Object.assign(appliedFilter, {
code: '',
bizType: '',
applicantId: undefined,
status: '',
applyDateRange: null,
amountRange: '',
currentNode: ''
})
pager.currentPage.value = 1
loadData()
}
function handleQuickSearch() {
appliedQuickSearch.value = quickSearchKeyword.value.trim()
pager.currentPage.value = 1
}
function handleQuickSearchClear() {
quickSearchKeyword.value = ''
appliedQuickSearch.value = ''
pager.currentPage.value = 1
}
function handleSelectionChange(rows: any[]) {
selectedRows.value = rows
}
async function openViewDetail(row: any) {
currentRow.value = row
viewData.value = {}
viewFlowNodes.value = []
viewApprovalHistory.value = []
viewLinkedInvoiceFiles.value = []
viewAttachments.value = []
viewPayAttachments.value = []
viewOffsetAttachments.value = []
viewIssueAttachments.value = []
viewOffsetRecords.value = []
viewFlowLoading.value = true
dialogs.viewDetail = true
const isAdvance = row.bizType === '备用金'
const api = isAdvance ? advanceApi : reimburseApi
try {
const detailRes: any = await api.getById(row.id)
viewData.value = detailRes?.data || detailRes || {}
const tasks: Promise<any>[] = [api.getApprovals(row.id), api.getApprovalHistory(row.id)]
if (isAdvance) {
tasks.push(
paymentApi
.advanceOffsetRecords(row.id)
.then((res: any) => {
viewOffsetRecords.value = res?.data || []
})
.catch(() => {
viewOffsetRecords.value = []
}),
loadBxAttachments('advance_issue', row.id)
.then((files) => {
viewIssueAttachments.value = files
})
.catch(() => {
viewIssueAttachments.value = []
})
)
} else {
const linked = invoicesToLinkedAttachmentFiles(viewData.value.invoices || [])
viewLinkedInvoiceFiles.value = linked
tasks.push(
fillBxAttachmentPreviews(linked).catch(() => undefined),
loadBxAttachments('reimburse_apply', row.id)
.then((files) => {
viewAttachments.value = files
})
.catch(() => {
viewAttachments.value = []
}),
loadBxAttachments('reimburse_pay', row.id)
.then((files) => {
viewPayAttachments.value = files
})
.catch(() => {
viewPayAttachments.value = []
}),
loadBxAttachments('reimburse_offset', row.id)
.then((files) => {
viewOffsetAttachments.value = files
})
.catch(() => {
viewOffsetAttachments.value = []
})
)
}
const [flowRes, historyRes]: any[] = await Promise.all(tasks)
viewFlowNodes.value = (flowRes.data || []).sort((a: any, b: any) => a.nodeOrder - b.nodeOrder)
viewApprovalHistory.value = historyRes.data || []
} catch (e: any) {
ElMessage.error(e.message || '加载详情失败')
} finally {
viewFlowLoading.value = false
}
}
onMounted(() => {
loadApplicantOptions()
loadData()
nextTick(() => recalcTableHeight())
})
</script>
<style scoped lang="scss">
.bx-list-table-wrap {
min-width: 0;
}
</style>