All checks were successful
Build and Deploy Front / deploy (push) Successful in 6m37s
将站点/API 默认值收敛到配置,避免再次全局改域名;同步 H5/PC 支付充值与助手浮层交互调整。 Co-authored-by: Cursor <cursoragent@cursor.com>
966 lines
28 KiB
Vue
966 lines
28 KiB
Vue
<template>
|
||
<div class="user-invoice-container">
|
||
<div class="user-invoice-page-card">
|
||
<div class="table-toolbar">
|
||
<div class="toolbar-left">
|
||
<a-space wrap :size="12">
|
||
<a-input
|
||
v-model="keyword"
|
||
allow-clear
|
||
:placeholder="t('finance.invoiceManage.search.keywordPlaceholder')"
|
||
style="width: 200px"
|
||
@press-enter="handleSearch"
|
||
/>
|
||
<a-select
|
||
v-model="statusFilter"
|
||
:placeholder="t('finance.invoiceManage.search.statusPlaceholder')"
|
||
allow-clear
|
||
style="width: 150px"
|
||
>
|
||
<a-option value="all">{{ t('finance.invoiceManage.search.statusAll') }}</a-option>
|
||
<a-option v-for="item in statusOptions" :key="item.value" :value="item.value">
|
||
{{ item.label }}
|
||
</a-option>
|
||
</a-select>
|
||
<a-button class="app-btn-search" @click="handleSearch">
|
||
{{ t('finance.invoiceManage.search.actions.search') }}
|
||
</a-button>
|
||
<a-button @click="handleReset">
|
||
{{ t('finance.invoiceManage.search.actions.reset') }}
|
||
</a-button>
|
||
<a-button @click="openProfiles">
|
||
{{ t('finance.invoiceManage.search.actions.profiles') }}
|
||
</a-button>
|
||
<a-button class="app-btn-primary-soft" @click="openCreate">
|
||
{{ t('finance.invoiceManage.search.actions.apply') }}
|
||
</a-button>
|
||
</a-space>
|
||
</div>
|
||
<div class="toolbar-right">
|
||
<PaginationPro
|
||
:total-count="totalCount"
|
||
v-model:current-page="currentPage"
|
||
v-model:page-size="pageSize"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<a-spin class="list-spin" :loading="listLoading">
|
||
<div ref="tableContainerRef" class="list-wrap">
|
||
<HandsontablePro
|
||
:columns="hotColumns"
|
||
:data="tableRows"
|
||
:total="totalCount"
|
||
:current-page="currentPage"
|
||
:page-size="pageSize"
|
||
:show-action-column="true"
|
||
:action-renderer="actionRenderer"
|
||
:custom-cell-renderer="customCellRenderer"
|
||
:stretch-columns="true"
|
||
:height="handsontableHeight"
|
||
@action-click="handleActionClick"
|
||
/>
|
||
</div>
|
||
</a-spin>
|
||
</div>
|
||
|
||
<a-drawer
|
||
:visible="applyVisible"
|
||
:title="applyTitle"
|
||
:width="760"
|
||
unmount-on-close
|
||
class="invoice-apply-drawer"
|
||
@cancel="applyVisible = false"
|
||
>
|
||
<InvoiceApplyPanel
|
||
:apply-form="applyForm"
|
||
:profiles="profiles"
|
||
:profile-loading="profileLoading"
|
||
:selectable-items="selectableItems"
|
||
:selectable-loading="selectableLoading"
|
||
v-model:selectable-keyword="selectableKeyword"
|
||
v-model:title-fields-expanded="titleFieldsExpanded"
|
||
:selected-keys="selectedKeys"
|
||
:selected-amount-map="selectedAmountMap"
|
||
show-manage-profiles
|
||
@profile-change="onProfileChange"
|
||
@manage-profiles="openProfiles"
|
||
@reload-selectable="reloadSelectable"
|
||
@toggle="toggleSelectable"
|
||
@set-amount="setLineAmount"
|
||
/>
|
||
|
||
<template #footer>
|
||
<div class="apply-foot">
|
||
<div class="apply-foot__sum">
|
||
<span>{{ t('finance.invoiceManage.drawer.selectedAmount') }}</span>
|
||
<strong>¥{{ formatMoney(selectedTotal) }}</strong>
|
||
<em v-if="selectedCount">{{
|
||
t('finance.invoiceManage.drawer.selectedCount', { count: selectedCount })
|
||
}}</em>
|
||
</div>
|
||
<div class="apply-foot__actions">
|
||
<a-button @click="applyVisible = false">{{ t('common.cancel') }}</a-button>
|
||
<a-button
|
||
type="primary"
|
||
class="app-btn-primary-soft"
|
||
:loading="applySaving"
|
||
@click="submitApplyFromFooter"
|
||
>
|
||
{{ t('finance.invoiceManage.drawer.submit') }}
|
||
</a-button>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</a-drawer>
|
||
|
||
<a-drawer
|
||
:visible="detailVisible"
|
||
:title="t('finance.invoiceManage.drawer.detail')"
|
||
:width="560"
|
||
:footer="false"
|
||
unmount-on-close
|
||
@cancel="detailVisible = false"
|
||
>
|
||
<a-spin :loading="detailLoading">
|
||
<template v-if="detail">
|
||
<a-descriptions :column="1" bordered size="small">
|
||
<a-descriptions-item :label="t('finance.invoiceManage.table.applyNo')">
|
||
{{ detail.applyNo }}
|
||
</a-descriptions-item>
|
||
<a-descriptions-item :label="t('finance.invoiceManage.table.status')">
|
||
{{ detail.statusName || detail.status }}
|
||
</a-descriptions-item>
|
||
<a-descriptions-item :label="t('finance.invoiceManage.drawer.titleName')">
|
||
{{ detail.titleName }}
|
||
</a-descriptions-item>
|
||
<a-descriptions-item :label="t('finance.invoiceManage.table.amountTotal')">
|
||
¥{{ formatMoney(detail.amountTotal) }}
|
||
</a-descriptions-item>
|
||
<a-descriptions-item :label="t('finance.invoiceManage.table.invoiceNumber')">
|
||
{{ detail.invoiceNumber || '--' }}
|
||
</a-descriptions-item>
|
||
</a-descriptions>
|
||
<h4 class="detail-lines-title">{{ t('finance.invoiceManage.detail.lines') }}</h4>
|
||
<a-table :data="detail.lines || []" :pagination="false" size="small" row-key="id">
|
||
<a-table-column :title="t('finance.invoiceManage.selectable.sourceNo')" data-index="sourceNo" />
|
||
<a-table-column :title="t('finance.invoiceManage.selectable.sourceType')" data-index="sourceTypeName" />
|
||
<a-table-column :title="t('finance.invoiceManage.selectable.amount')" data-index="amount">
|
||
<template #cell="{ record }">¥{{ formatMoney(record.amount) }}</template>
|
||
</a-table-column>
|
||
</a-table>
|
||
</template>
|
||
</a-spin>
|
||
</a-drawer>
|
||
|
||
<a-drawer
|
||
:visible="profileVisible"
|
||
:title="profileDrawerTitle"
|
||
:width="560"
|
||
unmount-on-close
|
||
:footer="profileDrawerMode === 'form'"
|
||
:ok-loading="profileSaving"
|
||
:ok-text="t('common.save')"
|
||
:cancel-text="t('common.back')"
|
||
@before-ok="saveProfileForm"
|
||
@before-cancel="handleProfileBeforeCancel"
|
||
@cancel="closeProfileDrawer"
|
||
>
|
||
<a-spin :loading="profileLoading" class="profile-drawer-spin">
|
||
<template v-if="profileDrawerMode === 'list'">
|
||
<div v-if="!profiles.length" class="profile-empty">
|
||
<p class="profile-empty__title">{{ t('finance.invoiceManage.profile.empty') }}</p>
|
||
<p class="profile-empty__desc">{{ t('finance.invoiceManage.profile.emptyHint') }}</p>
|
||
<a-button class="app-btn-primary-soft" @click="openProfileForm()">
|
||
{{ t('finance.invoiceManage.profile.add') }}
|
||
</a-button>
|
||
</div>
|
||
<div v-else class="profile-list">
|
||
<div class="profile-toolbar">
|
||
<a-button class="app-btn-primary-soft" @click="openProfileForm()">
|
||
{{ t('finance.invoiceManage.profile.add') }}
|
||
</a-button>
|
||
</div>
|
||
<div v-for="p in profiles" :key="p.id" class="profile-card">
|
||
<div class="profile-card__main">
|
||
<div class="profile-card__head">
|
||
<strong>{{ p.titleName }}</strong>
|
||
<span v-if="p.isDefault" class="profile-default">
|
||
{{ t('finance.invoiceManage.profile.default') }}
|
||
</span>
|
||
</div>
|
||
<p>{{ p.taxNo }}</p>
|
||
<p v-if="p.addressPhone">{{ p.addressPhone }}</p>
|
||
<p v-if="p.bankNameAccount">{{ p.bankNameAccount }}</p>
|
||
</div>
|
||
<div class="profile-card__actions">
|
||
<a-button size="small" @click="openProfileForm(p)">
|
||
{{ t('common.edit') }}
|
||
</a-button>
|
||
<a-button
|
||
v-if="!p.isDefault"
|
||
size="small"
|
||
@click="setDefaultProfile(p)"
|
||
>
|
||
{{ t('finance.invoiceManage.profile.setDefault') }}
|
||
</a-button>
|
||
<a-button size="small" status="danger" @click="removeProfile(p)">
|
||
{{ t('common.delete') }}
|
||
</a-button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<a-form v-else :model="profileForm" layout="vertical" class="profile-form">
|
||
<InvoiceTitleFields :model="profileForm" />
|
||
</a-form>
|
||
</a-spin>
|
||
</a-drawer>
|
||
</div>
|
||
</template>
|
||
|
||
<script lang="ts" setup>
|
||
import { computed, onMounted, reactive, ref } from 'vue'
|
||
import { useI18n } from 'vue-i18n'
|
||
import { Message, Modal } from '@arco-design/web-vue'
|
||
import dayjs from 'dayjs'
|
||
import HandsontablePro from '@/components/HandsontablePro/index.vue'
|
||
import PaginationPro from '@/components/PaginationPro/index.vue'
|
||
import InvoiceApplyPanel from '@/views/finance/components/InvoiceApplyPanel.vue'
|
||
import InvoiceTitleFields from '@/views/finance/components/InvoiceTitleFields.vue'
|
||
import { useTableContainerHeight } from '@/composables/useTableContainerHeight'
|
||
import { renderWarehouseActionBtn, wrapWarehouseActions } from '@/utils/warehouseActionRenderer'
|
||
import { buildStatusTagHtml } from '@/utils/statusTag'
|
||
import {
|
||
DEFAULT_INVOICE_TAX_RATE,
|
||
INVOICE_MEDIUM,
|
||
INVOICE_STATUS,
|
||
INVOICE_TYPE,
|
||
createInvoiceApply,
|
||
deleteInvoiceProfile,
|
||
getInvoiceApplyDetail,
|
||
getInvoiceApplyList,
|
||
getInvoiceProfileList,
|
||
getInvoiceSelectable,
|
||
invoiceLineKey,
|
||
mergeSelectableWithApplyLines,
|
||
roundInvoiceMoney,
|
||
saveInvoiceProfile,
|
||
submitInvoiceApply,
|
||
updateInvoiceApply,
|
||
type InvoiceApply,
|
||
type InvoiceApplyLine,
|
||
type InvoiceProfile,
|
||
type InvoiceSelectableItem,
|
||
} from '@/api/finance/invoice'
|
||
|
||
defineOptions({ name: 'UserInvoice' })
|
||
|
||
const { t } = useI18n()
|
||
const { tableContainerRef, tableHeight } = useTableContainerHeight()
|
||
const handsontableHeight = computed(() => Math.max(tableHeight.value || 0, 400))
|
||
|
||
const keyword = ref('')
|
||
const statusFilter = ref('all')
|
||
const currentPage = ref(1)
|
||
const pageSize = ref(50)
|
||
const totalCount = ref(0)
|
||
const listLoading = ref(false)
|
||
const tableRows = ref<InvoiceApply[]>([])
|
||
|
||
const applyVisible = ref(false)
|
||
const applySaving = ref(false)
|
||
const isEditApply = ref(false)
|
||
const editApplyId = ref(0)
|
||
const profileLoading = ref(false)
|
||
const profiles = ref<InvoiceProfile[]>([])
|
||
const selectableLoading = ref(false)
|
||
const selectableItems = ref<InvoiceSelectableItem[]>([])
|
||
const selectableKeyword = ref('')
|
||
const selectedLines = ref<Record<string, InvoiceApplyLine>>({})
|
||
const editLinesSnapshot = ref<InvoiceApplyLine[]>([])
|
||
|
||
const applyForm = reactive({
|
||
profileId: undefined as number | undefined,
|
||
titleName: '',
|
||
taxNo: '',
|
||
addressPhone: '',
|
||
bankNameAccount: '',
|
||
invoiceType: INVOICE_TYPE.Normal,
|
||
medium: INVOICE_MEDIUM.Electronic,
|
||
taxRate: DEFAULT_INVOICE_TAX_RATE,
|
||
remark: '',
|
||
})
|
||
|
||
const applyTitle = computed(() =>
|
||
isEditApply.value
|
||
? t('finance.invoiceManage.drawer.edit')
|
||
: t('finance.invoiceManage.drawer.create'),
|
||
)
|
||
|
||
const selectedTotal = computed(() =>
|
||
roundInvoiceMoney(
|
||
Object.values(selectedLines.value).reduce((sum, line) => sum + Number(line.amount || 0), 0),
|
||
),
|
||
)
|
||
const selectedCount = computed(() => Object.keys(selectedLines.value).length)
|
||
const selectedKeys = computed(() => {
|
||
const keys: Record<string, boolean> = {}
|
||
for (const key of Object.keys(selectedLines.value)) keys[key] = true
|
||
return keys
|
||
})
|
||
const selectedAmountMap = computed(() => {
|
||
const map: Record<string, number> = {}
|
||
for (const [key, line] of Object.entries(selectedLines.value)) {
|
||
map[key] = Number(line.amount || 0)
|
||
}
|
||
return map
|
||
})
|
||
const titleFieldsExpanded = ref(false)
|
||
|
||
const detailVisible = ref(false)
|
||
const detailLoading = ref(false)
|
||
const detail = ref<InvoiceApply | null>(null)
|
||
|
||
const profileVisible = ref(false)
|
||
const profileDrawerMode = ref<'list' | 'form'>('list')
|
||
const profileSaving = ref(false)
|
||
const profileForm = reactive({
|
||
id: 0,
|
||
titleName: '',
|
||
taxNo: '',
|
||
addressPhone: '',
|
||
bankNameAccount: '',
|
||
isDefault: false,
|
||
remark: '',
|
||
})
|
||
|
||
const profileDrawerTitle = computed(() => {
|
||
if (profileDrawerMode.value === 'form') {
|
||
return profileForm.id
|
||
? t('finance.invoiceManage.profile.edit')
|
||
: t('finance.invoiceManage.profile.add')
|
||
}
|
||
return t('finance.invoiceManage.profile.title')
|
||
})
|
||
|
||
const statusOptions = computed(() => [
|
||
{ value: INVOICE_STATUS.Draft, label: t('finance.invoiceManage.status.draft') },
|
||
{ value: INVOICE_STATUS.PendingApproval, label: t('finance.invoiceManage.status.pendingApproval') },
|
||
{ value: INVOICE_STATUS.Approved, label: t('finance.invoiceManage.status.approved') },
|
||
{ value: INVOICE_STATUS.Issued, label: t('finance.invoiceManage.status.issued') },
|
||
{ value: INVOICE_STATUS.Rejected, label: t('finance.invoiceManage.status.rejected') },
|
||
{ value: INVOICE_STATUS.Voided, label: t('finance.invoiceManage.status.voided') },
|
||
{ value: INVOICE_STATUS.RedFlushed, label: t('finance.invoiceManage.status.redFlushed') },
|
||
])
|
||
|
||
function formatMoney(value?: number) {
|
||
return (Number(value) || 0).toFixed(2)
|
||
}
|
||
|
||
async function loadList() {
|
||
listLoading.value = true
|
||
try {
|
||
const { items, total } = await getInvoiceApplyList({
|
||
page: currentPage.value,
|
||
pageSize: pageSize.value,
|
||
keyword: keyword.value.trim() || undefined,
|
||
status: statusFilter.value !== 'all' ? statusFilter.value : undefined,
|
||
})
|
||
tableRows.value = items
|
||
totalCount.value = total
|
||
} catch (e: any) {
|
||
Message.error(e?.message || t('finance.invoiceManage.message.loadError'))
|
||
tableRows.value = []
|
||
totalCount.value = 0
|
||
} finally {
|
||
listLoading.value = false
|
||
}
|
||
}
|
||
|
||
function handleSearch() {
|
||
currentPage.value = 1
|
||
loadList()
|
||
}
|
||
|
||
function handleReset() {
|
||
keyword.value = ''
|
||
statusFilter.value = 'all'
|
||
currentPage.value = 1
|
||
loadList()
|
||
}
|
||
|
||
function handlePageChange(page: number) {
|
||
currentPage.value = page
|
||
loadList()
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pageSize.value = size
|
||
currentPage.value = 1
|
||
loadList()
|
||
}
|
||
|
||
const hotColumns = computed(() => [
|
||
{ key: 'applyNo', label: t('finance.invoiceManage.table.applyNo'), width: 160 },
|
||
{ key: 'invoiceTypeName', label: t('finance.invoiceManage.table.invoiceType'), width: 110 },
|
||
{ key: 'mediumName', label: t('finance.invoiceManage.table.medium'), width: 90 },
|
||
{ key: 'titleName', label: t('finance.invoiceManage.table.titleName'), width: 180 },
|
||
{ key: 'amountTotal', label: t('finance.invoiceManage.table.amountTotal'), width: 110 },
|
||
{ key: 'statusName', label: t('finance.invoiceManage.table.status'), width: 120 },
|
||
{ key: 'invoiceNumber', label: t('finance.invoiceManage.table.invoiceNumber'), width: 140 },
|
||
{ key: 'createTime', label: t('finance.invoiceManage.table.createTime'), width: 170 },
|
||
])
|
||
|
||
function statusTone(status: string) {
|
||
if (status === INVOICE_STATUS.Draft) return 'neutral'
|
||
if (status === INVOICE_STATUS.PendingApproval) return 'wait'
|
||
if (status === INVOICE_STATUS.Approved) return 'brand'
|
||
if (status === INVOICE_STATUS.Issued) return 'ok'
|
||
if (status === INVOICE_STATUS.Rejected) return 'alert'
|
||
return 'mute'
|
||
}
|
||
|
||
function customCellRenderer(_row: number, col: number, _value: any, rowData: InvoiceApply): string | null {
|
||
const dataColIndex = col - 2
|
||
if (dataColIndex < 0 || dataColIndex >= hotColumns.value.length) return null
|
||
const colKey = hotColumns.value[dataColIndex].key
|
||
if (colKey === 'amountTotal') {
|
||
return rowData?.amountTotal != null ? `¥${formatMoney(rowData.amountTotal)}` : '--'
|
||
}
|
||
if (colKey === 'statusName') {
|
||
return buildStatusTagHtml(rowData?.statusName || rowData?.status || '--', statusTone(rowData?.status))
|
||
}
|
||
if (colKey === 'createTime') {
|
||
return rowData?.createTime ? dayjs(rowData.createTime).format('YYYY-MM-DD HH:mm:ss') : '--'
|
||
}
|
||
return null
|
||
}
|
||
|
||
function actionRenderer(row: InvoiceApply): string {
|
||
const parts = [renderWarehouseActionBtn('detail', t('finance.invoiceManage.actions.detail'), 'view')]
|
||
if (row.status === INVOICE_STATUS.Draft) {
|
||
parts.push(renderWarehouseActionBtn('submit', t('finance.invoiceManage.actions.submit'), 'publish'))
|
||
parts.push(renderWarehouseActionBtn('edit', t('finance.invoiceManage.actions.edit'), 'edit'))
|
||
}
|
||
return wrapWarehouseActions(parts)
|
||
}
|
||
|
||
async function handleActionClick(row: InvoiceApply, _rowIndex: number, action?: string) {
|
||
if (!row?.id) return
|
||
if (action === 'detail') {
|
||
openDetail(row.id)
|
||
return
|
||
}
|
||
if (action === 'edit') {
|
||
await openEdit(row.id)
|
||
return
|
||
}
|
||
if (action === 'submit') {
|
||
try {
|
||
const result = await submitInvoiceApply(row.id)
|
||
Message.success(result.message || t('finance.invoiceManage.message.submitSuccess'))
|
||
await loadList()
|
||
} catch (e: any) {
|
||
Message.error(e?.message || t('finance.invoiceManage.message.loadError'))
|
||
}
|
||
}
|
||
}
|
||
|
||
function resetApplyForm() {
|
||
applyForm.profileId = undefined
|
||
applyForm.titleName = ''
|
||
applyForm.taxNo = ''
|
||
applyForm.addressPhone = ''
|
||
applyForm.bankNameAccount = ''
|
||
applyForm.invoiceType = INVOICE_TYPE.Normal
|
||
applyForm.medium = INVOICE_MEDIUM.Electronic
|
||
applyForm.taxRate = DEFAULT_INVOICE_TAX_RATE
|
||
applyForm.remark = ''
|
||
selectableItems.value = []
|
||
selectableKeyword.value = ''
|
||
selectedLines.value = {}
|
||
editLinesSnapshot.value = []
|
||
titleFieldsExpanded.value = false
|
||
}
|
||
|
||
async function openCreate() {
|
||
isEditApply.value = false
|
||
editApplyId.value = 0
|
||
resetApplyForm()
|
||
applyVisible.value = true
|
||
await Promise.all([loadProfiles(true), loadSelectable()])
|
||
}
|
||
|
||
async function openEdit(id: number) {
|
||
isEditApply.value = true
|
||
editApplyId.value = id
|
||
resetApplyForm()
|
||
applyVisible.value = true
|
||
try {
|
||
const data = await getInvoiceApplyDetail(id)
|
||
applyForm.titleName = data.titleName
|
||
applyForm.taxNo = data.taxNo
|
||
applyForm.addressPhone = data.addressPhone || ''
|
||
applyForm.bankNameAccount = data.bankNameAccount || ''
|
||
applyForm.invoiceType = data.invoiceType || INVOICE_TYPE.Normal
|
||
applyForm.medium = data.medium || INVOICE_MEDIUM.Electronic
|
||
applyForm.taxRate = data.taxRate ?? DEFAULT_INVOICE_TAX_RATE
|
||
applyForm.remark = data.remark || ''
|
||
editLinesSnapshot.value = data.lines || []
|
||
for (const line of editLinesSnapshot.value) {
|
||
selectedLines.value[invoiceLineKey(line.sourceType, line.sourceId)] = { ...line }
|
||
}
|
||
await Promise.all([loadProfiles(), loadSelectable()])
|
||
const matched = profiles.value.find(
|
||
(p) => p.titleName === data.titleName && p.taxNo === data.taxNo,
|
||
)
|
||
if (matched) {
|
||
applyForm.profileId = matched.id
|
||
titleFieldsExpanded.value = false
|
||
} else {
|
||
titleFieldsExpanded.value = true
|
||
}
|
||
} catch (e: any) {
|
||
Message.error(e?.message || t('finance.invoiceManage.message.loadError'))
|
||
}
|
||
}
|
||
|
||
async function loadProfiles(selectDefault = false) {
|
||
profileLoading.value = true
|
||
try {
|
||
profiles.value = await getInvoiceProfileList()
|
||
if (selectDefault && !applyForm.profileId) {
|
||
const def = profiles.value.find((p) => p.isDefault) || profiles.value[0]
|
||
if (def) {
|
||
applyForm.profileId = def.id
|
||
onProfileChange(def.id)
|
||
}
|
||
}
|
||
} catch (e: any) {
|
||
Message.error(e?.message || t('finance.invoiceManage.message.loadError'))
|
||
} finally {
|
||
profileLoading.value = false
|
||
}
|
||
}
|
||
|
||
function onProfileChange(id?: number) {
|
||
if (!id) {
|
||
titleFieldsExpanded.value = true
|
||
return
|
||
}
|
||
const profile = profiles.value.find((p) => p.id === id)
|
||
if (!profile) return
|
||
applyForm.titleName = profile.titleName
|
||
applyForm.taxNo = profile.taxNo
|
||
applyForm.addressPhone = profile.addressPhone || ''
|
||
applyForm.bankNameAccount = profile.bankNameAccount || ''
|
||
titleFieldsExpanded.value = false
|
||
}
|
||
|
||
async function submitApplyFromFooter() {
|
||
await handleApplySave()
|
||
}
|
||
|
||
async function loadSelectable() {
|
||
selectableLoading.value = true
|
||
try {
|
||
const { items } = await getInvoiceSelectable({
|
||
keyword: selectableKeyword.value,
|
||
page: 1,
|
||
pageSize: 100,
|
||
})
|
||
selectableItems.value = mergeSelectableWithApplyLines(items, editLinesSnapshot.value)
|
||
} catch (e: any) {
|
||
Message.error(e?.message || t('finance.invoiceManage.message.loadError'))
|
||
} finally {
|
||
selectableLoading.value = false
|
||
}
|
||
}
|
||
|
||
function reloadSelectable() {
|
||
loadSelectable()
|
||
}
|
||
|
||
function toggleSelectable(item: InvoiceSelectableItem, checked: boolean) {
|
||
const key = invoiceLineKey(item.sourceType, item.sourceId)
|
||
const next = { ...selectedLines.value }
|
||
if (checked) {
|
||
next[key] = {
|
||
sourceType: item.sourceType,
|
||
sourceTypeName: item.sourceTypeName,
|
||
sourceId: item.sourceId,
|
||
sourceNo: item.sourceNo,
|
||
amount: item.remainingAmount,
|
||
currency: item.currency,
|
||
}
|
||
} else {
|
||
delete next[key]
|
||
}
|
||
selectedLines.value = next
|
||
}
|
||
|
||
function setLineAmount(item: InvoiceSelectableItem, amount: number) {
|
||
const key = invoiceLineKey(item.sourceType, item.sourceId)
|
||
const current = selectedLines.value[key]
|
||
if (!current) return
|
||
selectedLines.value = {
|
||
...selectedLines.value,
|
||
[key]: { ...current, amount: roundInvoiceMoney(amount) },
|
||
}
|
||
}
|
||
|
||
async function handleApplySave() {
|
||
if (!applyForm.titleName.trim() || !applyForm.taxNo.trim()) {
|
||
Message.warning(t('finance.invoiceManage.drawer.needTitle'))
|
||
return false
|
||
}
|
||
if (!Object.keys(selectedLines.value).length) {
|
||
Message.warning(t('finance.invoiceManage.drawer.needLines'))
|
||
return false
|
||
}
|
||
applySaving.value = true
|
||
try {
|
||
const payload = {
|
||
invoiceType: applyForm.invoiceType,
|
||
medium: applyForm.medium,
|
||
profileId: applyForm.profileId,
|
||
titleName: applyForm.titleName.trim(),
|
||
taxNo: applyForm.taxNo.trim(),
|
||
addressPhone: applyForm.addressPhone.trim() || undefined,
|
||
bankNameAccount: applyForm.bankNameAccount.trim() || undefined,
|
||
taxRate: applyForm.taxRate,
|
||
remark: applyForm.remark.trim() || undefined,
|
||
submit: true,
|
||
lines: Object.values(selectedLines.value).map((line) => ({
|
||
sourceType: line.sourceType,
|
||
sourceId: line.sourceId,
|
||
amount: roundInvoiceMoney(line.amount),
|
||
})),
|
||
}
|
||
const result = isEditApply.value
|
||
? await updateInvoiceApply({ ...payload, id: editApplyId.value })
|
||
: await createInvoiceApply(payload)
|
||
Message.success(result.message || t('finance.invoiceManage.message.submitSuccess'))
|
||
applyVisible.value = false
|
||
await loadList()
|
||
return true
|
||
} catch (e: any) {
|
||
Message.error(e?.message || t('finance.invoiceManage.message.loadError'))
|
||
return false
|
||
} finally {
|
||
applySaving.value = false
|
||
}
|
||
}
|
||
|
||
async function openDetail(id: number) {
|
||
detailVisible.value = true
|
||
detailLoading.value = true
|
||
try {
|
||
detail.value = await getInvoiceApplyDetail(id)
|
||
} catch (e: any) {
|
||
Message.error(e?.message || t('finance.invoiceManage.message.loadError'))
|
||
detail.value = null
|
||
} finally {
|
||
detailLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function openProfiles() {
|
||
profileDrawerMode.value = 'list'
|
||
profileVisible.value = true
|
||
await loadProfiles(false)
|
||
if (!profiles.value.length) {
|
||
openProfileForm()
|
||
}
|
||
}
|
||
|
||
function openProfileForm(row?: InvoiceProfile) {
|
||
profileForm.id = row?.id || 0
|
||
profileForm.titleName = row?.titleName || ''
|
||
profileForm.taxNo = row?.taxNo || ''
|
||
profileForm.addressPhone = row?.addressPhone || ''
|
||
profileForm.bankNameAccount = row?.bankNameAccount || ''
|
||
profileForm.isDefault = Boolean(row?.isDefault) || !profiles.value.length
|
||
profileForm.remark = row?.remark || ''
|
||
profileDrawerMode.value = 'form'
|
||
}
|
||
|
||
function backToProfileList() {
|
||
profileDrawerMode.value = 'list'
|
||
}
|
||
|
||
function handleProfileBeforeCancel() {
|
||
if (profileDrawerMode.value === 'form') {
|
||
backToProfileList()
|
||
return false
|
||
}
|
||
return true
|
||
}
|
||
|
||
function closeProfileDrawer() {
|
||
profileVisible.value = false
|
||
profileDrawerMode.value = 'list'
|
||
if (applyVisible.value) {
|
||
void loadProfiles()
|
||
}
|
||
}
|
||
|
||
async function saveProfileForm() {
|
||
if (!profileForm.titleName.trim() || !profileForm.taxNo.trim()) {
|
||
Message.warning(t('finance.invoiceManage.drawer.needTitle'))
|
||
return false
|
||
}
|
||
profileSaving.value = true
|
||
try {
|
||
await saveInvoiceProfile({
|
||
id: profileForm.id || undefined,
|
||
titleName: profileForm.titleName.trim(),
|
||
taxNo: profileForm.taxNo.trim(),
|
||
addressPhone: profileForm.addressPhone.trim() || undefined,
|
||
bankNameAccount: profileForm.bankNameAccount.trim() || undefined,
|
||
isDefault: profileForm.isDefault,
|
||
remark: profileForm.remark.trim() || undefined,
|
||
})
|
||
Message.success(t('finance.invoiceManage.message.profileSaved'))
|
||
await loadProfiles(false)
|
||
profileDrawerMode.value = 'list'
|
||
// 留在抬头抽屉,不关闭
|
||
return false
|
||
} catch (e: any) {
|
||
Message.error(e?.message || t('finance.invoiceManage.message.loadError'))
|
||
return false
|
||
} finally {
|
||
profileSaving.value = false
|
||
}
|
||
}
|
||
|
||
async function setDefaultProfile(row: InvoiceProfile) {
|
||
try {
|
||
await saveInvoiceProfile({
|
||
id: row.id,
|
||
titleName: row.titleName,
|
||
taxNo: row.taxNo,
|
||
addressPhone: row.addressPhone,
|
||
bankNameAccount: row.bankNameAccount,
|
||
isDefault: true,
|
||
remark: row.remark,
|
||
})
|
||
Message.success(t('finance.invoiceManage.message.profileSaved'))
|
||
await loadProfiles()
|
||
} catch (e: any) {
|
||
Message.error(e?.message || t('finance.invoiceManage.message.loadError'))
|
||
}
|
||
}
|
||
|
||
function removeProfile(row: InvoiceProfile) {
|
||
Modal.confirm({
|
||
title: t('finance.invoiceManage.profile.deleteConfirm'),
|
||
onOk: async () => {
|
||
await deleteInvoiceProfile(row.id)
|
||
Message.success(t('finance.invoiceManage.message.profileDeleted'))
|
||
await loadProfiles()
|
||
},
|
||
})
|
||
}
|
||
|
||
onMounted(() => {
|
||
loadList()
|
||
})
|
||
</script>
|
||
|
||
<style lang="less" scoped>
|
||
.user-invoice-container {
|
||
width: 100%;
|
||
box-sizing: border-box;
|
||
/* 门户下根 padding=0,与侧栏同高;运营端保留壳留白 */
|
||
padding: var(--app-page-padding, 16px 16px 24px);
|
||
display: flex;
|
||
flex-direction: column;
|
||
background: var(--app-page-bg);
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.user-invoice-page-card {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
background: var(--app-card-bg);
|
||
border-radius: 8px;
|
||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||
overflow: hidden;
|
||
}
|
||
|
||
.table-toolbar {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: flex-start;
|
||
padding: 16px 16px 0;
|
||
margin-bottom: 16px;
|
||
flex-shrink: 0;
|
||
flex-wrap: wrap;
|
||
gap: 12px;
|
||
|
||
.toolbar-left {
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.toolbar-right {
|
||
flex-shrink: 0;
|
||
}
|
||
}
|
||
|
||
.list-spin {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
padding: 0 16px 16px;
|
||
}
|
||
|
||
.list-spin :deep(.arco-spin-container) {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.list-wrap {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.apply-foot {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
width: 100%;
|
||
}
|
||
|
||
.apply-foot__sum {
|
||
display: flex;
|
||
align-items: baseline;
|
||
gap: 8px;
|
||
min-width: 0;
|
||
font-size: 13px;
|
||
color: var(--color-text-2);
|
||
|
||
strong {
|
||
font-size: 18px;
|
||
color: var(--app-primary-color);
|
||
}
|
||
|
||
em {
|
||
font-style: normal;
|
||
font-size: 12px;
|
||
color: var(--color-text-3);
|
||
}
|
||
}
|
||
|
||
.apply-foot__actions {
|
||
display: flex;
|
||
gap: 8px;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.detail-lines-title {
|
||
margin: 16px 0 8px;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.profile-drawer-spin {
|
||
width: 100%;
|
||
min-height: 200px;
|
||
}
|
||
|
||
.profile-toolbar {
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.profile-empty {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 8px;
|
||
min-height: 280px;
|
||
padding: 24px;
|
||
text-align: center;
|
||
}
|
||
|
||
.profile-empty__title {
|
||
margin: 0;
|
||
font-size: 15px;
|
||
font-weight: 600;
|
||
color: var(--color-text-1);
|
||
}
|
||
|
||
.profile-empty__desc {
|
||
margin: 0 0 8px;
|
||
font-size: 13px;
|
||
color: var(--color-text-3);
|
||
}
|
||
|
||
.profile-list {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
}
|
||
|
||
.profile-card {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: flex-start;
|
||
gap: 12px;
|
||
padding: 12px;
|
||
border-radius: 8px;
|
||
background: #f7f8fa;
|
||
|
||
p {
|
||
margin: 4px 0 0;
|
||
color: var(--color-text-3);
|
||
font-size: 12px;
|
||
line-height: 1.4;
|
||
}
|
||
}
|
||
|
||
.profile-card__main {
|
||
min-width: 0;
|
||
flex: 1;
|
||
}
|
||
|
||
.profile-card__head {
|
||
display: flex;
|
||
align-items: center;
|
||
flex-wrap: wrap;
|
||
gap: 6px;
|
||
}
|
||
|
||
.profile-card__actions {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 8px;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.profile-default {
|
||
font-size: 12px;
|
||
color: var(--app-primary-color);
|
||
}
|
||
|
||
.profile-form {
|
||
padding-top: 4px;
|
||
}
|
||
</style>
|