Files
cz-web/src/views/finance/cpns/InvoiceTitleDialog.vue
wangzzpeng 7bc84bbe5e first
2026-09-24 10:10:43 +08:00

193 lines
4.4 KiB
Vue

<script setup lang="ts">
import { reactive, watch } from 'vue'
import { ElMessage } from 'element-plus'
import type { InvoiceTitle, InvoiceTitlePayload } from '@/types/business/finance'
interface Props {
invoiceTitle?: InvoiceTitle
}
const props = defineProps<Props>()
const visible = defineModel<boolean>('visible', { default: false })
const emit = defineEmits<{ save: [payload: InvoiceTitlePayload] }>()
const form = reactive<InvoiceTitlePayload>({
type: '企业单位',
title: '',
taxNo: '',
})
watch(visible, (open) => {
if (!open) return
form.type = props.invoiceTitle?.type ?? '企业单位'
form.title = props.invoiceTitle?.title ?? ''
form.taxNo = props.invoiceTitle?.taxNo ?? ''
})
function onSave(): void {
if (!form.title.trim() || !form.taxNo.trim()) {
ElMessage.warning('请填写发票抬头与税号')
return
}
emit('save', { type: form.type, title: form.title.trim(), taxNo: form.taxNo.trim() })
visible.value = false
}
function onCancel(): void {
visible.value = false
}
</script>
<template>
<Teleport to="body">
<div v-if="visible" class="title-dialog" @click.self="onCancel">
<div class="title-dialog__panel">
<h3 class="title-dialog__title">
{{ invoiceTitle ? '编辑抬头' : '新增抬头' }}
</h3>
<div class="title-dialog__field">
<span class="title-dialog__label">抬头类型</span>
<label class="title-dialog__radio">
<input v-model="form.type" type="radio" value="企业单位">
企业单位
</label>
<label class="title-dialog__radio">
<input v-model="form.type" type="radio" value="非企业单位">
非企业单位
</label>
</div>
<div class="title-dialog__field">
<span class="title-dialog__label">发票抬头</span>
<input
v-model="form.title"
class="title-dialog__input"
placeholder="请输入发票抬头"
>
</div>
<div class="title-dialog__field">
<span class="title-dialog__label">税号</span>
<input
v-model="form.taxNo"
class="title-dialog__input"
placeholder="请输入税号"
>
</div>
<div class="title-dialog__footer">
<button class="title-dialog__btn" @click="onCancel">
取消
</button>
<button class="title-dialog__btn title-dialog__btn--confirm" @click="onSave">
保存
</button>
</div>
</div>
</div>
</Teleport>
</template>
<style lang="less" scoped>
.title-dialog {
position: fixed;
inset: 0;
z-index: 1000;
.flex(row, center);
background: rgba(0, 0, 0, 0.45);
&__panel {
width: 440px;
max-width: calc(100vw - 32px);
padding: @spacing-lg;
border-radius: @radius-lg;
background: @white;
box-shadow: @shadow-lg;
}
&__title {
margin-bottom: @spacing-base;
font-size: @font-size-lg;
font-weight: 600;
color: @heading-color;
}
&__field {
.flex(row, flex-start, center);
gap: @spacing-sm;
margin-bottom: @spacing-base;
}
&__label {
width: 72px;
flex-shrink: 0;
font-size: @font-size-base;
color: @text-color;
}
&__radio {
.flex(row, flex-start, center);
gap: @spacing-xs;
font-size: @font-size-base;
color: @text-color;
cursor: pointer;
input {
accent-color: @primary-color;
}
}
&__input {
flex: 1;
height: 34px;
padding: 0 @spacing-sm;
border: 1px solid @border-color;
border-radius: @radius-base;
background: @bg-color-light;
font-size: @font-size-base;
outline: none;
transition: border-color 0.2s;
&:focus {
border-color: @primary-color;
}
}
&__footer {
.flex(row, flex-end);
gap: @spacing-sm;
margin-top: @spacing-lg;
}
&__btn {
height: 34px;
padding: 0 @spacing-base;
border: 1px solid @border-color-dark;
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;
}
&--confirm {
border-color: @primary-color;
background: @primary-color;
color: @white;
&:hover {
background: @primary-hover;
color: @white;
}
}
}
}
</style>