271 lines
7.2 KiB
Vue
271 lines
7.2 KiB
Vue
<script setup lang="ts">
|
||
import { computed, onMounted, ref } from 'vue'
|
||
import { storeToRefs } from 'pinia'
|
||
import { ElMessage } from 'element-plus'
|
||
import { ConfirmDialog } from '@/components'
|
||
// 页面容器:数据只经 store,不直接 import api
|
||
import { useFinanceStore } from '@/stores/modules/finance'
|
||
import type { InvoiceTitle, InvoiceTitlePayload } from '@/types/business/finance'
|
||
import InvoiceTitleCard from './cpns/InvoiceTitleCard.vue'
|
||
import InvoiceTitleDialog from './cpns/InvoiceTitleDialog.vue'
|
||
|
||
const financeStore = useFinanceStore()
|
||
const { titles } = storeToRefs(financeStore)
|
||
|
||
const dialogVisible = ref(false)
|
||
const editing = ref<InvoiceTitle | undefined>(undefined)
|
||
|
||
const confirmVisible = ref(false)
|
||
const pendingDeleteId = ref('')
|
||
|
||
const PAGE_SIZE = 2
|
||
const page = ref(1)
|
||
|
||
const pageCount = computed(() => Math.max(1, Math.ceil(titles.value.length / PAGE_SIZE)))
|
||
const pagedTitles = computed(() =>
|
||
titles.value.slice((page.value - 1) * PAGE_SIZE, page.value * PAGE_SIZE),
|
||
)
|
||
/** 页码序列:设计 35 实取 1~5 */
|
||
const pages = computed(() => Array.from({ length: Math.max(5, pageCount.value) }, (_, i) => i + 1))
|
||
|
||
function go(next: number): void {
|
||
if (next < 1 || next > pageCount.value) return
|
||
page.value = next
|
||
}
|
||
|
||
function onCreate(): void {
|
||
editing.value = undefined
|
||
dialogVisible.value = true
|
||
}
|
||
|
||
function onEdit(item: InvoiceTitle): void {
|
||
editing.value = item
|
||
dialogVisible.value = true
|
||
}
|
||
|
||
async function onSave(payload: InvoiceTitlePayload): Promise<void> {
|
||
if (editing.value) {
|
||
await financeStore.updateTitle(editing.value.id, payload)
|
||
ElMessage.success('抬头已更新')
|
||
}
|
||
else {
|
||
await financeStore.createTitle(payload)
|
||
ElMessage.success('抬头已新增')
|
||
}
|
||
}
|
||
|
||
function onDelete(id: string): void {
|
||
pendingDeleteId.value = id
|
||
confirmVisible.value = true
|
||
}
|
||
|
||
async function onConfirmDelete(): Promise<void> {
|
||
await financeStore.deleteTitle(pendingDeleteId.value)
|
||
pendingDeleteId.value = ''
|
||
ElMessage.success('抬头已删除')
|
||
}
|
||
|
||
async function onSetDefault(id: string): Promise<void> {
|
||
const item = titles.value.find((title) => title.id === id)
|
||
if (!item) return
|
||
await financeStore.setDefaultTitle(id)
|
||
ElMessage.success(item.isDefault ? '已取消默认抬头' : '已设为默认抬头')
|
||
}
|
||
|
||
onMounted(() => {
|
||
void financeStore.fetchTitles()
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<div class="invoice-titles">
|
||
<div class="container">
|
||
<!-- 面包屑 (70,124)「财务中心 /」13/400 #9CA3AF +「发票抬头管理」13/500 #4B5563 -->
|
||
<nav class="invoice-titles__breadcrumb">
|
||
<RouterLink to="/finance" class="invoice-titles__breadcrumb-link">
|
||
财务中心 /
|
||
</RouterLink>
|
||
<span class="invoice-titles__breadcrumb-current">发票抬头管理</span>
|
||
</nav>
|
||
|
||
<!-- 标题条 (70,153) 1780×62:标题 x106 y174 15/700 + 右侧「+ 新增抬头」 -->
|
||
<header class="invoice-titles__head">
|
||
<h2 class="invoice-titles__title">
|
||
发票管理
|
||
</h2>
|
||
<button class="invoice-titles__create" @click="onCreate">
|
||
+ 新增抬头
|
||
</button>
|
||
</header>
|
||
|
||
<!-- 抬头卡列表 (70,229) 起 1780×129 / (70,372) 1780×88 -->
|
||
<div class="invoice-titles__list">
|
||
<InvoiceTitleCard
|
||
v-for="item in pagedTitles"
|
||
:key="item.id"
|
||
:invoice-title="item"
|
||
@set-default="onSetDefault"
|
||
@edit="onEdit"
|
||
@delete="onDelete"
|
||
/>
|
||
<p v-if="pagedTitles.length === 0" class="invoice-titles__empty">
|
||
暂无发票抬头,点击右上角新增
|
||
</p>
|
||
</div>
|
||
|
||
<!-- 分页 (1684.93~1881.07,505) 12/400 -->
|
||
<nav class="invoice-titles__pager" aria-label="分页">
|
||
<button class="invoice-titles__page" :disabled="page <= 1" @click="go(page - 1)">
|
||
‹
|
||
</button>
|
||
<button
|
||
v-for="item in pages"
|
||
:key="item"
|
||
class="invoice-titles__page"
|
||
:class="{ 'is-active': item === page }"
|
||
@click="go(item)"
|
||
>
|
||
{{ item }}
|
||
</button>
|
||
<button class="invoice-titles__page" :disabled="page >= pageCount" @click="go(page + 1)">
|
||
›
|
||
</button>
|
||
</nav>
|
||
</div>
|
||
|
||
<InvoiceTitleDialog
|
||
v-model:visible="dialogVisible"
|
||
:invoice-title="editing"
|
||
@save="onSave"
|
||
/>
|
||
|
||
<ConfirmDialog
|
||
v-model:visible="confirmVisible"
|
||
title="删除抬头"
|
||
message="删除后无法恢复,是否继续?"
|
||
confirm-text="删除"
|
||
danger
|
||
@confirm="onConfirmDelete"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<style lang="less" scoped>
|
||
// 设计 35/36 发票抬头管理(1920 画布 1:1)——内容区 x70→1850 = 1780
|
||
.invoice-titles {
|
||
width: 100%;
|
||
padding-bottom: 459px; // 分页底 521 → 页脚 1087
|
||
background: @contract-page-bg;
|
||
|
||
// 面包屑 (70,124)
|
||
&__breadcrumb {
|
||
.flex(row, flex-start, center);
|
||
height: 81px; // 顶栏 72 → 标题条 153,面包屑盒 72..133
|
||
padding-top: 36px;
|
||
font-size: 13px;
|
||
font-weight: 400;
|
||
line-height: 17px;
|
||
color: @project-muted;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
&__breadcrumb-link {
|
||
color: @project-muted;
|
||
|
||
&:hover {
|
||
color: @primary-strong;
|
||
}
|
||
}
|
||
|
||
&__breadcrumb-current {
|
||
margin-left: 5.25px; // 「财务中心 /」墨迹宽 65.25 → 发票抬头管理 x135.25
|
||
color: @finance-entry-text;
|
||
font-weight: 500;
|
||
}
|
||
|
||
// 标题条 (70,153) 1780×62
|
||
&__head {
|
||
.flex(row, space-between, center);
|
||
height: 62px;
|
||
padding: 0 33.56px 0 36px; // 标题 x106;按钮右缘 1822
|
||
border: 1px solid @finance-card-line;
|
||
border-radius: @radius-base;
|
||
background: @white;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
&__title {
|
||
font-size: 15px;
|
||
font-weight: 700;
|
||
line-height: 20px;
|
||
color: @finance-ink;
|
||
}
|
||
|
||
// 「+ 新增抬头」(1735.56,167) 110.44×34
|
||
&__create {
|
||
width: 110.44px;
|
||
height: 34px;
|
||
margin-right: -5px; // 按钮右缘 1822 → 卡内缩 33.56 得 1816.44,再右移 5
|
||
border: none;
|
||
border-radius: 4px;
|
||
background: @primary-strong;
|
||
color: @white;
|
||
font-size: 12px;
|
||
font-weight: 500;
|
||
transition: background 0.2s;
|
||
|
||
&:hover {
|
||
background: @primary-color;
|
||
}
|
||
}
|
||
|
||
// 抬头卡纵排:首卡 (70,229)、次卡 (70,372) → 间距 14
|
||
&__list {
|
||
.flex(column, flex-start, stretch);
|
||
gap: 14px;
|
||
margin-top: 14px; // 标题条底 215 → 首卡 229
|
||
}
|
||
|
||
&__empty {
|
||
padding: 60px 0;
|
||
color: @project-muted;
|
||
font-size: 13px;
|
||
text-align: center;
|
||
}
|
||
|
||
// 分页:右对齐到内容区右缘,页码 12/400
|
||
&__pager {
|
||
.flex(row, flex-end, center);
|
||
gap: 3.7px;
|
||
margin-top: 8px; // 次卡底 460 → 页码 ink 505
|
||
padding-right: 2.4px; // 末位「›」右缘 1881.07 → 内容右缘 1850
|
||
}
|
||
|
||
&__page {
|
||
min-width: 21.45px;
|
||
height: 16px;
|
||
padding: 0 3px;
|
||
border: none;
|
||
border-radius: 0;
|
||
background: transparent;
|
||
color: @finance-muted-text;
|
||
font-size: 12px;
|
||
font-weight: 400;
|
||
transition: color 0.2s;
|
||
|
||
&:hover:not(:disabled) {
|
||
color: @primary-strong;
|
||
}
|
||
|
||
&.is-active {
|
||
color: @primary-strong;
|
||
}
|
||
|
||
&:disabled {
|
||
cursor: not-allowed;
|
||
opacity: 0.5;
|
||
}
|
||
}
|
||
}
|
||
</style>
|