feat 搭建架构骨架
This commit is contained in:
207
src/views/finance/invoice-titles.vue
Normal file
207
src/views/finance/invoice-titles.vue
Normal file
@@ -0,0 +1,207 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { AppButton, 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)
|
||||
|
||||
type TypeFilter = 'all' | InvoiceTitle['type']
|
||||
|
||||
const typeFilter = ref<TypeFilter>('all')
|
||||
|
||||
const TYPE_TABS: Array<{ label: string; value: TypeFilter }> = [
|
||||
{ label: '全部', value: 'all' },
|
||||
{ label: '企业单位', value: '企业单位' },
|
||||
{ label: '非企业单位', value: '非企业单位' },
|
||||
]
|
||||
|
||||
const filteredTitles = computed(() =>
|
||||
typeFilter.value === 'all'
|
||||
? titles.value
|
||||
: titles.value.filter((item) => item.type === typeFilter.value),
|
||||
)
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const editing = ref<InvoiceTitle | undefined>(undefined)
|
||||
|
||||
const confirmVisible = ref(false)
|
||||
const pendingDeleteId = ref('')
|
||||
|
||||
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
|
||||
if (item.isDefault) {
|
||||
ElMessage.info('演示环境暂不支持取消默认,可设其他抬头为默认')
|
||||
return
|
||||
}
|
||||
await financeStore.setDefaultTitle(id)
|
||||
ElMessage.success('已设为默认抬头')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void financeStore.fetchTitles()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="invoice-titles">
|
||||
<nav class="invoice-titles__breadcrumb text-secondary">
|
||||
<RouterLink to="/finance" class="link">
|
||||
财务中心
|
||||
</RouterLink>
|
||||
<span> > </span>
|
||||
<span>发票抬头</span>
|
||||
</nav>
|
||||
|
||||
<header class="invoice-titles__head">
|
||||
<h2 class="invoice-titles__title">
|
||||
发票管理
|
||||
</h2>
|
||||
<div class="invoice-titles__filters">
|
||||
<button
|
||||
v-for="tab in TYPE_TABS"
|
||||
:key="tab.value"
|
||||
class="invoice-titles__filter"
|
||||
:class="{ 'is-active': typeFilter === tab.value }"
|
||||
@click="typeFilter = tab.value"
|
||||
>
|
||||
{{ tab.label }}
|
||||
</button>
|
||||
<AppButton type="primary" @click="onCreate">
|
||||
+新增抬头
|
||||
</AppButton>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="invoice-titles__grid">
|
||||
<InvoiceTitleCard
|
||||
v-for="item in filteredTitles"
|
||||
:key="item.id"
|
||||
:invoice-title="item"
|
||||
@set-default="onSetDefault"
|
||||
@edit="onEdit"
|
||||
@delete="onDelete"
|
||||
/>
|
||||
<p v-if="filteredTitles.length === 0" class="invoice-titles__empty text-secondary">
|
||||
暂无发票抬头,点击右上角新增
|
||||
</p>
|
||||
</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>
|
||||
.invoice-titles {
|
||||
.flex(column, flex-start);
|
||||
gap: @spacing-base;
|
||||
padding-top: @spacing-lg;
|
||||
padding-bottom: @spacing-xxl;
|
||||
|
||||
&__breadcrumb {
|
||||
font-size: @font-size-base;
|
||||
}
|
||||
|
||||
&__head {
|
||||
.flex(row, space-between, center);
|
||||
flex-wrap: wrap;
|
||||
gap: @spacing-base;
|
||||
}
|
||||
|
||||
&__title {
|
||||
font-size: @font-size-xl;
|
||||
font-weight: 600;
|
||||
color: @heading-color;
|
||||
}
|
||||
|
||||
&__filters {
|
||||
.flex(row, flex-end, center);
|
||||
gap: @spacing-sm;
|
||||
}
|
||||
|
||||
&__filter {
|
||||
height: 34px;
|
||||
padding: 0 @spacing-base;
|
||||
border: 1px solid @border-color;
|
||||
border-radius: @radius-base;
|
||||
background: @white;
|
||||
color: @text-color;
|
||||
font-size: @font-size-base;
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
border-color: @primary-color;
|
||||
color: @primary-color;
|
||||
}
|
||||
|
||||
&.is-active {
|
||||
border-color: @primary-color;
|
||||
background: @primary-color;
|
||||
color: @white;
|
||||
}
|
||||
}
|
||||
|
||||
&__grid {
|
||||
.flex(row, flex-start);
|
||||
flex-wrap: wrap;
|
||||
gap: @spacing-base;
|
||||
}
|
||||
|
||||
&__empty {
|
||||
padding: @spacing-xl 0;
|
||||
font-size: @font-size-base;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user