文件
yjyf/yjyf-app/pages/invoice/title-edit.vue
MiAn fafddceaf2 feat: 新增发票抬头、晒单、钱包日志等模型及后台管理功能
- 新增 invoice_title、showcase、wallet_log 模型及对应语言包
- 新增后台控制器、视图及搜索字段配置
- 修复服务类目删除保护逻辑
- 优化后台登录页面文案及样式
- 新增前端角色切换逻辑及页面拦截
- 新增 SVG 图标及样式变量
- 修复接口权限及下拉框默认值问题
2026-11-11 17:02:35 +08:00

550 行
14 KiB
Vue

<template>
<view class="page">
<YjyfNavBar
theme="orange"
:title="form.id ? '编辑发票抬头' : '新增发票抬头'"
:fixed="true"
:placeholder="true"
/>
<view class="form-container">
<!-- #ifdef MP-WEIXIN -->
<view class="wx-quick-card clickable-hover" @tap="chooseFromWechat">
<view class="wx-l">
<image class="wx-ico" src="/static/icons/invoice-wx.svg" mode="aspectFit" />
<text class="wx-title">获取微信发票抬头</text>
</view>
<image class="arrow-ico" src="/static/icons/arrow-right.svg" mode="aspectFit" />
</view>
<!-- #endif -->
<!-- 1. 主体类型选择与基础信息 -->
<view class="card">
<view class="subject-grid">
<view
class="sub-card clickable-hover"
:class="{ active: form.title_type === 'personal' }"
@tap="switchTitleType('personal')"
>
<image class="sub-ico" src="/static/icons/invoice-personal.svg" mode="aspectFit" />
<text class="sub-name">个人 / 非企业</text>
<image
class="sub-chk"
v-if="form.title_type === 'personal'"
src="/static/icons/invoice-check-on.svg"
mode="aspectFit"
/>
</view>
<view
class="sub-card clickable-hover"
:class="{ active: form.title_type === 'enterprise' }"
@tap="switchTitleType('enterprise')"
>
<image class="sub-ico" src="/static/icons/invoice-enterprise.svg" mode="aspectFit" />
<text class="sub-name">企业单位</text>
<image
class="sub-chk"
v-if="form.title_type === 'enterprise'"
src="/static/icons/invoice-check-on.svg"
mode="aspectFit"
/>
</view>
</view>
<view class="fi" v-if="form.title_type === 'enterprise'">
<text class="fk">常用票种</text>
<view class="seg-track">
<view
class="seg-item clickable-hover"
:class="{ on: form.default_invoice_type === 'normal' }"
@tap="form.default_invoice_type = 'normal'"
>
普通发票
</view>
<view
class="seg-item clickable-hover"
:class="{ on: form.default_invoice_type === 'special' }"
@tap="form.default_invoice_type = 'special'"
>
专用发票
</view>
</view>
</view>
<view class="fi" :class="{ 'no-border': form.title_type === 'personal' }">
<text class="fk required">{{ form.title_type === 'enterprise' ? '企业名称' : '抬头名称' }}</text>
<input
class="fv"
v-model="form.title"
maxlength="100"
:placeholder="form.title_type === 'enterprise' ? '请输入企业全称' : '请输入姓名或单位名称'"
/>
</view>
<view class="fi no-border" v-if="form.title_type === 'enterprise'">
<text class="fk required">纳税人识别号</text>
<input
class="fv mono"
v-model="form.tax_no"
maxlength="20"
placeholder="15-20位统一社会信用代码"
/>
</view>
</view>
<!-- 2. 企业扩展信息 -->
<view class="card" v-if="form.title_type === 'enterprise'">
<view class="sec-head">
<text class="sec-title">开户行与地址电话</text>
<text class="sec-tag" :class="{ req: form.default_invoice_type === 'special' }">
{{ form.default_invoice_type === 'special' ? '专票必填' : '普票选填' }}
</text>
</view>
<view class="fi">
<text class="fk" :class="{ required: form.default_invoice_type === 'special' }">开户银行</text>
<input class="fv" v-model="form.bank_name" maxlength="100" placeholder="请输入开户银行" />
</view>
<view class="fi">
<text class="fk" :class="{ required: form.default_invoice_type === 'special' }">银行账号</text>
<input class="fv mono" v-model="form.bank_account" maxlength="50" placeholder="请输入银行账号" />
</view>
<view class="fi">
<text class="fk" :class="{ required: form.default_invoice_type === 'special' }">注册地址</text>
<input class="fv" v-model="form.reg_address" maxlength="255" placeholder="请输入企业注册地址" />
</view>
<view class="fi no-border">
<text class="fk" :class="{ required: form.default_invoice_type === 'special' }">注册电话</text>
<input class="fv mono" v-model="form.reg_mobile" maxlength="30" placeholder="请输入企业注册电话" />
</view>
</view>
<!-- 3. 接收方式与默认设置 -->
<view class="card">
<view class="fi">
<text class="fk">接收邮箱</text>
<input class="fv" v-model="form.email" maxlength="100" placeholder="选填,默认接收电子票" />
</view>
<view class="fi">
<text class="fk">通知手机</text>
<input class="fv mono" type="number" maxlength="11" v-model="form.receive_mobile" placeholder="选填" />
</view>
<view class="fi no-border">
<text class="fk">设为默认抬头</text>
<switch :checked="form.is_default === 1" color="#F0710D" @change="onDefaultChange" />
</view>
</view>
</view>
<!-- 底部固定保存栏 -->
<view class="bottom-bar">
<view class="submit-btn clickable-hover" :class="{ disabled: saving }" @tap="save">
{{ saving ? '保存中...' : '保存抬头' }}
</view>
</view>
</view>
</template>
<script setup>
import { ref, reactive } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import YjyfNavBar from '@/components/YjyfNavBar.vue';
import api from '@/utils/api.js';
import { isLogin, toLogin } from '@/utils/request.js';
const saving = ref(false);
const form = reactive({
id: 0,
title_type: 'personal',
default_invoice_type: 'normal',
title: '',
tax_no: '',
bank_name: '',
bank_account: '',
reg_address: '',
reg_mobile: '',
email: '',
receive_mobile: '',
is_default: 0
});
onLoad(async (opts) => {
if (!isLogin()) {
toLogin();
return;
}
if (opts && Number(opts.id) > 0) {
await loadDetail(Number(opts.id));
} else if (opts && opts.type === 'enterprise') {
form.title_type = 'enterprise';
}
if (opts && opts.invoice_type === 'special') {
form.title_type = 'enterprise';
form.default_invoice_type = 'special';
}
});
async function loadDetail(id) {
try {
const res = await api.invoiceTitleDetail(id);
const d = res && res.detail ? res.detail : null;
if (!d) return;
form.id = Number(d.id);
form.title_type = d.title_type || 'personal';
form.default_invoice_type = d.default_invoice_type || 'normal';
form.title = d.title || '';
form.tax_no = d.tax_no || '';
form.bank_name = d.bank_name || '';
form.bank_account = d.bank_account || '';
form.reg_address = d.reg_address || '';
form.reg_mobile = d.reg_mobile || '';
form.email = d.email || '';
form.receive_mobile = d.receive_mobile || '';
form.is_default = Number(d.is_default) ? 1 : 0;
} catch (e) {}
}
function switchTitleType(type) {
form.title_type = type;
if (type === 'personal') {
form.default_invoice_type = 'normal';
}
}
function onDefaultChange(e) {
form.is_default = e.detail.value ? 1 : 0;
}
function chooseFromWechat() {
// #ifdef MP-WEIXIN
if (typeof uni.chooseInvoiceTitle !== 'function') {
uni.showToast({ title: '当前环境不支持读取微信抬头', icon: 'none' });
return;
}
uni.chooseInvoiceTitle({
success: (res) => {
if (!res) return;
const isEnt = String(res.type) === '0';
form.title_type = isEnt ? 'enterprise' : 'personal';
form.title = res.title || form.title;
if (isEnt) {
form.tax_no = (res.taxNumber || '').toUpperCase();
form.bank_name = res.bankName || '';
form.bank_account = res.bankAccount || '';
form.reg_address = res.companyAddress || '';
form.reg_mobile = res.telephone || '';
if (form.bank_name && form.bank_account && form.reg_address && form.reg_mobile) {
form.default_invoice_type = 'special';
}
} else {
form.default_invoice_type = 'normal';
}
},
fail: () => {}
});
// #endif
}
async function save() {
if (saving.value) return;
const title = form.title.trim();
const taxNo = form.tax_no.replace(/\s+/g, '').toUpperCase();
if (!title) {
uni.showToast({ title: form.title_type === 'enterprise' ? '请填写企业名称' : '请填写抬头名称', icon: 'none' });
return;
}
if (form.title_type === 'enterprise') {
if (!taxNo) {
uni.showToast({ title: '请填写纳税人识别号', icon: 'none' });
return;
}
if (!/^[0-9A-Z]{15,20}$/.test(taxNo)) {
uni.showToast({ title: '纳税人识别号需为15-20位字母或数字', icon: 'none' });
return;
}
if (form.default_invoice_type === 'special') {
if (!form.bank_name.trim() || !form.bank_account.trim()) {
uni.showToast({ title: '专用发票需填写开户银行与账号', icon: 'none' });
return;
}
if (!form.reg_address.trim() || !form.reg_mobile.trim()) {
uni.showToast({ title: '专用发票需填写注册地址与电话', icon: 'none' });
return;
}
}
}
if (form.email.trim() && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(form.email.trim())) {
uni.showToast({ title: '接收邮箱格式不正确', icon: 'none' });
return;
}
if (form.receive_mobile.trim() && !/^1\d{10}$/.test(form.receive_mobile.trim())) {
uni.showToast({ title: '通知手机号格式不正确', icon: 'none' });
return;
}
saving.value = true;
try {
const res = await api.invoiceTitleSave({
id: form.id,
title_type: form.title_type,
default_invoice_type: form.title_type === 'personal' ? 'normal' : form.default_invoice_type,
title,
tax_no: form.title_type === 'enterprise' ? taxNo : '',
bank_name: form.title_type === 'enterprise' ? form.bank_name.trim() : '',
bank_account: form.title_type === 'enterprise' ? form.bank_account.replace(/\s+/g, '') : '',
reg_address: form.title_type === 'enterprise' ? form.reg_address.trim() : '',
reg_mobile: form.title_type === 'enterprise' ? form.reg_mobile.trim() : '',
email: form.email.trim(),
receive_mobile: form.receive_mobile.trim(),
is_default: form.is_default
});
uni.showToast({ title: '保存成功' });
if (res && res.detail) {
uni.$emit('yjyf:savedInvoiceTitle', res.detail);
}
setTimeout(() => {
saving.value = false;
uni.navigateBack();
}, 400);
} catch (e) {
saving.value = false;
}
}
</script>
<style lang="scss" scoped>
.page {
min-height: 100vh;
background: $yjyf-bg-page;
padding-bottom: calc(176rpx + env(safe-area-inset-bottom));
box-sizing: border-box;
}
.form-container {
padding: $yjyf-space-md $yjyf-space-lg 0;
}
.wx-quick-card {
padding: 20rpx $yjyf-space-md;
margin-bottom: 20rpx;
background: $yjyf-bg-card;
border-radius: $yjyf-radius-card;
display: flex;
align-items: center;
justify-content: space-between;
box-shadow: 0 6rpx 20rpx rgba(31, 31, 31, 0.04);
}
.wx-l {
display: flex;
align-items: center;
}
.wx-ico {
width: 44rpx;
height: 44rpx;
margin-right: 16rpx;
}
.wx-title {
font-size: $yjyf-font-body;
font-weight: 600;
color: $yjyf-text-main;
}
.arrow-ico {
width: 24rpx;
height: 24rpx;
}
.card {
padding: $yjyf-space-md;
margin-bottom: 20rpx;
background: $yjyf-bg-card;
border-radius: $yjyf-radius-card;
box-shadow: 0 6rpx 20rpx rgba(31, 31, 31, 0.04);
}
.sec-head {
display: flex;
align-items: center;
justify-content: space-between;
padding-bottom: 16rpx;
border-bottom: 1rpx solid $yjyf-border-color;
}
.sec-title {
font-size: $yjyf-font-body;
font-weight: 700;
color: $yjyf-text-main;
}
.sec-tag {
height: 36rpx;
padding: 0 14rpx;
border-radius: 8rpx;
font-size: $yjyf-font-micro;
background: $yjyf-bg-page;
color: $yjyf-text-secondary;
display: inline-flex;
align-items: center;
&.req {
background: $yjyf-primary-bg;
color: $yjyf-primary;
font-weight: 600;
}
}
.subject-grid {
display: flex;
gap: $yjyf-space-sm;
padding-bottom: 20rpx;
border-bottom: 1rpx solid $yjyf-border-color;
}
.sub-card {
position: relative;
flex: 1;
min-width: 0;
height: 92rpx;
padding: 0 20rpx;
border-radius: 16rpx;
background: $yjyf-bg-page;
border: 2rpx solid transparent;
display: flex;
align-items: center;
transition: all 0.18s ease;
&.active {
background: $yjyf-primary-bg;
border-color: $yjyf-primary;
}
}
.sub-ico {
width: 52rpx;
height: 52rpx;
flex-shrink: 0;
margin-right: 14rpx;
}
.sub-name {
font-size: $yjyf-font-sub;
font-weight: 700;
color: $yjyf-text-main;
}
.sub-chk {
position: absolute;
top: 10rpx;
right: 10rpx;
width: 28rpx;
height: 28rpx;
}
.fi {
display: flex;
align-items: center;
justify-content: space-between;
min-height: 92rpx;
padding: 4rpx 0;
border-bottom: 1rpx solid $yjyf-border-color;
&.no-border {
border-bottom: none;
padding-bottom: 0;
}
}
.fk {
width: 180rpx;
flex-shrink: 0;
font-size: $yjyf-font-body;
color: $yjyf-text-regular;
&.required::after {
content: '*';
color: $yjyf-danger;
margin-left: 4rpx;
}
}
.fv {
flex: 1;
height: 80rpx;
font-size: $yjyf-font-body;
color: $yjyf-text-main;
text-align: right;
&.mono {
font-variant-numeric: tabular-nums;
}
}
.seg-track {
display: inline-flex;
align-items: center;
padding: 6rpx;
border-radius: $yjyf-radius-pill;
background: $yjyf-bg-page;
}
.seg-item {
height: 54rpx;
padding: 0 26rpx;
border-radius: $yjyf-radius-pill;
font-size: $yjyf-font-sub;
color: $yjyf-text-secondary;
display: inline-flex;
align-items: center;
justify-content: center;
transition: all 0.18s ease;
&.on {
background: $yjyf-bg-card;
color: $yjyf-primary;
font-weight: 700;
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
}
}
.bottom-bar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 20;
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(16px);
border-top: 1rpx solid $yjyf-border-color;
box-shadow: $yjyf-shadow-bar;
padding: 20rpx $yjyf-space-lg calc(20rpx + env(safe-area-inset-bottom));
}
.submit-btn {
height: 88rpx;
border-radius: $yjyf-radius-pill;
background: $yjyf-gradient-primary;
box-shadow: $yjyf-shadow-button;
color: $yjyf-text-inverse;
font-size: $yjyf-font-body;
font-weight: 700;
display: flex;
align-items: center;
justify-content: center;
&.disabled {
background: $yjyf-text-disabled;
box-shadow: none;
}
}
</style>