修改
This commit is contained in:
@@ -1,81 +1,166 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { RouterLink } from 'vue-router'
|
||||
import { ElMessage, ElButton, ElTable, ElTableColumn } from 'element-plus'
|
||||
import { FilterPanel, PaginationBar, StatusTag } from '@/components'
|
||||
import { RouterLink, useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessage, ElMessageBox, ElButton, ElTable, ElTableColumn } from 'element-plus'
|
||||
import { PaginationBar, StatusTag } from '@/components'
|
||||
import { useFinanceStore } from '@/stores/modules/finance'
|
||||
import type { Invoice, InvoiceStatus } from '@/types/business/finance'
|
||||
import { useProfileStore } from '@/stores/modules/profile'
|
||||
import type { Invoice, InvoiceApplyPayload, InvoiceStatus } from '@/types/business/finance'
|
||||
import { formatMoney } from '@/utils/format'
|
||||
import { INVOICE_TYPE_LABELS } from '@/utils/invoiceVo'
|
||||
import InvoiceApplyDialog from './cpns/InvoiceApplyDialog.vue'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const financeStore = useFinanceStore()
|
||||
const { titles, invoices, invoiceQuery, invoiceTotal } = storeToRefs(financeStore)
|
||||
const { titles, invoices, invoiceQuery, invoiceTotal, availableBills, invoiceStatusOptions } = storeToRefs(financeStore)
|
||||
|
||||
const keyword = ref('')
|
||||
const selectedIds = ref<string[]>([])
|
||||
const profileStore = useProfileStore()
|
||||
const { profile } = storeToRefs(profileStore)
|
||||
|
||||
const applyVisible = ref(false)
|
||||
const applying = ref(false)
|
||||
const applyBillId = ref<string | undefined>(undefined)
|
||||
|
||||
const defaultTitle = computed(() => titles.value.find((item) => item.isDefault) ?? titles.value[0] ?? null)
|
||||
|
||||
const STATUS_TABS: Array<{ label: string; value: InvoiceStatus | 'all' }> = [
|
||||
{ label: '全部', value: 'all' },
|
||||
{ label: '已开票', value: '已开票' },
|
||||
{ label: '开票中', value: '开票中' },
|
||||
{ label: '未开票', value: '未开票' },
|
||||
]
|
||||
type TagVariant = 'primary' | 'success' | 'warning' | 'danger' | 'info'
|
||||
|
||||
const STATUS_VARIANTS: Record<InvoiceStatus, 'success' | 'warning' | 'info'> = {
|
||||
已开票: 'success',
|
||||
开票中: 'warning',
|
||||
未开票: 'info',
|
||||
/** 发票状态选项卡:字典 + 首项「全部」(value 为空,表示不传 status)。 */
|
||||
const STATUS_TABS = computed<Array<{ label: string; value: InvoiceStatus | '' }>>(() => [
|
||||
{ label: '全部', value: '' },
|
||||
...invoiceStatusOptions.value.map((item) => ({
|
||||
label: item.dictLabel,
|
||||
value: item.dictValue as InvoiceStatus,
|
||||
})),
|
||||
])
|
||||
|
||||
/** 状态文案优先用后端 statusName,缺失时回退字典文案。 */
|
||||
function statusLabel(invoice: Invoice): string {
|
||||
return invoice.statusName
|
||||
|| invoiceStatusOptions.value.find((item) => item.dictValue === invoice.status)?.dictLabel
|
||||
|| '—'
|
||||
}
|
||||
|
||||
function onTab(value: InvoiceStatus | 'all'): void {
|
||||
/** 标签颜色取字典 listClass(info/warning/success)。 */
|
||||
function statusVariant(status: InvoiceStatus): TagVariant {
|
||||
const listClass = invoiceStatusOptions.value.find((item) => item.dictValue === status)?.listClass
|
||||
if (listClass === 'primary' || listClass === 'success' || listClass === 'warning' || listClass === 'danger') {
|
||||
return listClass
|
||||
}
|
||||
return 'info'
|
||||
}
|
||||
|
||||
function onTab(value: InvoiceStatus | ''): void {
|
||||
if (invoiceQuery.value.status === value) return
|
||||
financeStore.setInvoiceQuery({ ...invoiceQuery.value, status: value, keyword: keyword.value })
|
||||
selectedIds.value = []
|
||||
financeStore.setInvoiceQuery({ ...invoiceQuery.value, status: value })
|
||||
void financeStore.searchInvoices()
|
||||
}
|
||||
|
||||
function onSearch(): void {
|
||||
financeStore.setInvoiceQuery({ ...invoiceQuery.value, keyword: keyword.value })
|
||||
void financeStore.searchInvoices()
|
||||
}
|
||||
|
||||
function onReset(): void {
|
||||
keyword.value = ''
|
||||
selectedIds.value = []
|
||||
financeStore.setInvoiceQuery({ keyword: '', status: 'all', page: 1, pageSize: invoiceQuery.value.pageSize })
|
||||
void financeStore.fetchInvoices()
|
||||
}
|
||||
|
||||
function onPageChange(page: number): void {
|
||||
void financeStore.changeInvoicePage(page)
|
||||
}
|
||||
|
||||
async function onApply(invoice: Invoice): Promise<void> {
|
||||
await financeStore.applyInvoice(invoice.id)
|
||||
ElMessage.success('开票申请已提交')
|
||||
async function onOpenApply(billId?: string): Promise<void> {
|
||||
applyBillId.value = billId || undefined
|
||||
try {
|
||||
await financeStore.fetchAvailableBills()
|
||||
applyVisible.value = true
|
||||
}
|
||||
catch {
|
||||
// 请求异常已由 request.ts 统一提示
|
||||
}
|
||||
}
|
||||
|
||||
function onPreview(): void {
|
||||
ElMessage.info('附件待接口接入')
|
||||
async function onSubmitApply(payload: InvoiceApplyPayload): Promise<void> {
|
||||
applying.value = true
|
||||
try {
|
||||
await financeStore.applyInvoice(payload)
|
||||
applyVisible.value = false
|
||||
ElMessage.success('开票申请已提交')
|
||||
}
|
||||
catch {
|
||||
// 请求异常已由 request.ts 统一提示
|
||||
}
|
||||
finally {
|
||||
applying.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function onDownload(): void {
|
||||
ElMessage.info('附件待接口接入')
|
||||
/** 已驳回的发票可重新发起开票申请。 */
|
||||
function onApplyForRow(invoice: Invoice): void {
|
||||
void onOpenApply(invoice.billId)
|
||||
}
|
||||
|
||||
function onSendEmail(): void {
|
||||
ElMessage.success('发票已发送至绑定邮箱(演示)')
|
||||
async function onPreview(invoice: Invoice): Promise<void> {
|
||||
try {
|
||||
const url = await financeStore.fetchPreviewUrl(invoice.id)
|
||||
if (!url) {
|
||||
ElMessage.warning('暂无可预览的发票文件')
|
||||
return
|
||||
}
|
||||
window.open(url, '_blank', 'noopener')
|
||||
}
|
||||
catch {
|
||||
// 请求异常已由 request.ts 统一提示
|
||||
}
|
||||
}
|
||||
|
||||
function onSelectionChange(rows: Invoice[]): void {
|
||||
selectedIds.value = rows.map((row) => row.id)
|
||||
async function onDownload(invoice: Invoice): Promise<void> {
|
||||
try {
|
||||
const { blob, fileName } = await financeStore.fetchDownloadFile(invoice.id)
|
||||
if (!blob || blob.size === 0) {
|
||||
ElMessage.warning('暂无可下载的发票文件')
|
||||
return
|
||||
}
|
||||
const url = URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = fileName || `${invoice.invoiceNo || 'invoice'}.pdf`
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
catch {
|
||||
// 请求异常已由 request.ts 统一提示
|
||||
}
|
||||
}
|
||||
|
||||
async function onSendEmail(invoice: Invoice): Promise<void> {
|
||||
if (!profile.value?.email) {
|
||||
try {
|
||||
await ElMessageBox.confirm('您还未绑定邮箱,请先绑定邮箱后再发送发票', '提示', {
|
||||
confirmButtonText: '去绑定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
void router.push({ name: 'ProfileBindEmail', query: { redirect: route.fullPath } })
|
||||
}
|
||||
catch {
|
||||
// 用户取消
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await financeStore.sendInvoiceEmail(invoice.id)
|
||||
ElMessage.success('发票已发送至绑定邮箱')
|
||||
}
|
||||
catch {
|
||||
// 请求异常已由 request.ts 统一提示
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
keyword.value = invoiceQuery.value.keyword
|
||||
void Promise.all([financeStore.fetchTitles(), financeStore.fetchInvoices()])
|
||||
void Promise.all([
|
||||
financeStore.fetchInvoiceStatusOptions(),
|
||||
financeStore.fetchTitles(),
|
||||
financeStore.fetchInvoices(),
|
||||
profileStore.fetchProfile().catch(() => null),
|
||||
])
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -108,59 +193,44 @@ onMounted(() => {
|
||||
</RouterLink>
|
||||
</section>
|
||||
|
||||
<div class="invoices__tabs">
|
||||
<el-button
|
||||
v-for="tab in STATUS_TABS"
|
||||
:key="tab.value"
|
||||
class="invoices__tab"
|
||||
:class="{ 'is-active': invoiceQuery.status === tab.value }"
|
||||
@click="onTab(tab.value)"
|
||||
>
|
||||
{{ tab.label }}
|
||||
<div class="invoices__toolbar">
|
||||
<div class="invoices__tabs">
|
||||
<el-button
|
||||
v-for="tab in STATUS_TABS"
|
||||
:key="tab.value"
|
||||
class="invoices__tab"
|
||||
:class="{ 'is-active': invoiceQuery.status === tab.value }"
|
||||
@click="onTab(tab.value)"
|
||||
>
|
||||
{{ tab.label }}
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-button class="invoices__apply" @click="onOpenApply()">
|
||||
+ 申请开票
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<FilterPanel
|
||||
v-model:keyword="keyword"
|
||||
keyword-placeholder="搜索发票抬头 / 账单号 / 项目名称"
|
||||
@search="onSearch"
|
||||
@reset="onReset"
|
||||
/>
|
||||
|
||||
<div class="invoices__table card">
|
||||
<el-table
|
||||
class="invoices__table-el"
|
||||
:data="invoices"
|
||||
row-key="id"
|
||||
@selection-change="onSelectionChange"
|
||||
>
|
||||
<el-table-column
|
||||
type="selection"
|
||||
width="48"
|
||||
/>
|
||||
<el-table-column
|
||||
type="index"
|
||||
label="序号"
|
||||
width="60"
|
||||
/>
|
||||
<el-table-column
|
||||
prop="planName"
|
||||
label="账单名称"
|
||||
min-width="180"
|
||||
label="发票号码"
|
||||
min-width="150"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
prop="billNo"
|
||||
label="账单号"
|
||||
width="150"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
prop="tradeNo"
|
||||
label="交易流水号"
|
||||
min-width="180"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
>
|
||||
<template #default="{ row }">
|
||||
{{ (row as Invoice).invoiceNo || '—' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="projectName"
|
||||
label="项目名称"
|
||||
@@ -168,21 +238,41 @@ onMounted(() => {
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="订单金额"
|
||||
prop="titleName"
|
||||
label="发票抬头"
|
||||
min-width="180"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="发票类型"
|
||||
width="100"
|
||||
>
|
||||
<template #default="{ row }">
|
||||
{{ INVOICE_TYPE_LABELS[(row as Invoice).invoiceType ?? ''] ?? '—' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
label="开票金额"
|
||||
width="110"
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<span class="invoices__amount">¥{{ formatMoney((row as Invoice).amount) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
prop="transactionNo"
|
||||
label="交易流水号"
|
||||
min-width="180"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="状态"
|
||||
width="90"
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<StatusTag
|
||||
:label="(row as Invoice).status"
|
||||
:variant="STATUS_VARIANTS[(row as Invoice).status]"
|
||||
:label="statusLabel(row as Invoice)"
|
||||
:variant="statusVariant((row as Invoice).status)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -199,12 +289,12 @@ onMounted(() => {
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<span class="invoices__ops">
|
||||
<template v-if="(row as Invoice).status === '已开票'">
|
||||
<template v-if="(row as Invoice).status === '2'">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
class="invoices__link"
|
||||
@click="onPreview"
|
||||
@click="onPreview(row as Invoice)"
|
||||
>
|
||||
预览
|
||||
</el-button>
|
||||
@@ -212,7 +302,7 @@ onMounted(() => {
|
||||
link
|
||||
type="primary"
|
||||
class="invoices__link"
|
||||
@click="onDownload"
|
||||
@click="onDownload(row as Invoice)"
|
||||
>
|
||||
下载
|
||||
</el-button>
|
||||
@@ -220,21 +310,21 @@ onMounted(() => {
|
||||
link
|
||||
type="primary"
|
||||
class="invoices__link"
|
||||
@click="onSendEmail"
|
||||
@click="onSendEmail(row as Invoice)"
|
||||
>
|
||||
发送邮箱
|
||||
</el-button>
|
||||
</template>
|
||||
<span v-else-if="(row as Invoice).status === '开票中'" class="invoices__dash">—</span>
|
||||
<el-button
|
||||
v-else
|
||||
v-else-if="(row as Invoice).status === '0'"
|
||||
link
|
||||
type="primary"
|
||||
class="invoices__link"
|
||||
@click="onApply(row as Invoice)"
|
||||
@click="onApplyForRow(row as Invoice)"
|
||||
>
|
||||
申请开票
|
||||
</el-button>
|
||||
<span v-else class="invoices__dash">—</span>
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -253,8 +343,18 @@ onMounted(() => {
|
||||
/>
|
||||
|
||||
<p class="invoices__tip text-secondary">
|
||||
开票将使用默认抬头,如需调整请前往 <RouterLink to="/finance/invoice-titles" class="link">管理抬头</RouterLink>。
|
||||
仅已支付且未开票的账单可申请开票,开票进度可在本页查看。抬头管理请前往
|
||||
<RouterLink to="/finance/invoice-titles" class="link">管理抬头</RouterLink>。
|
||||
</p>
|
||||
|
||||
<InvoiceApplyDialog
|
||||
v-model:visible="applyVisible"
|
||||
:bills="availableBills"
|
||||
:titles="titles"
|
||||
:preselect-bill-id="applyBillId"
|
||||
:submitting="applying"
|
||||
@submit="onSubmitApply"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -321,6 +421,11 @@ onMounted(() => {
|
||||
}
|
||||
}
|
||||
|
||||
&__toolbar {
|
||||
.flex(row, space-between, center);
|
||||
gap: @spacing-base;
|
||||
}
|
||||
|
||||
&__tabs {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
@@ -328,6 +433,23 @@ onMounted(() => {
|
||||
gap: @spacing-sm;
|
||||
}
|
||||
|
||||
&__apply {
|
||||
height: 34px;
|
||||
padding: 0 @spacing-base;
|
||||
border: none;
|
||||
border-radius: @radius-base;
|
||||
background: @primary-strong;
|
||||
color: @white;
|
||||
font-size: @font-size-base;
|
||||
font-weight: 500;
|
||||
transition: background 0.2s;
|
||||
|
||||
&:hover {
|
||||
background: @primary-color;
|
||||
color: @white;
|
||||
}
|
||||
}
|
||||
|
||||
&__tab {
|
||||
height: 34px;
|
||||
margin: 0;
|
||||
|
||||
Reference in New Issue
Block a user