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

507 行
11 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view class="page">
<YjyfNavBar theme="orange" title="开票记录" :fixed="true" :placeholder="true" />
<!-- 顶部吸顶状态筛选栏 -->
<view class="tabs-bar" :style="{ top: navHeight + 'px' }">
<view
class="tab-item clickable-hover"
:class="{ active: activeTab === t.value }"
v-for="t in tabs"
:key="t.value"
@tap="switchTab(t.value)"
>
<text class="tab-txt">{{ t.label }}</text>
<view class="tab-line" v-if="activeTab === t.value"></view>
</view>
</view>
<!-- 初始加载态 -->
<view class="state-box" v-if="loading && !list.length">
<text class="state-txt">加载中...</text>
</view>
<!-- 错误重试态 -->
<view class="state-box" v-else-if="loadError && !list.length">
<image class="empty-ico" src="/static/icons/empty-invoice-records.svg" mode="aspectFit" />
<text class="state-title">{{ loadError }}</text>
<view class="retry-btn clickable-hover" @tap="reload">重新加载</view>
</view>
<!-- 空数据态 -->
<view class="state-box" v-else-if="!list.length">
<image class="empty-ico" src="/static/icons/empty-invoice-records.svg" mode="aspectFit" />
<text class="state-title">暂无开票记录</text>
<view class="ghost-btn clickable-hover" @tap="goOrders">去开票</view>
</view>
<!-- 精简电子票根列表 -->
<view class="list-wrap" v-else>
<view class="rec-card clickable-hover" v-for="item in list" :key="item.id" @tap="goDetail(item.id)">
<view class="rc-upper">
<view class="rc-top">
<text class="tag-type" :class="{ special: item.type === 'special' }">
{{ item.type === 'special' ? '专用发票' : '普通发票' }}
</text>
<text class="rc-status" :class="'st-' + item.status">{{ item.status_text }}</text>
</view>
<view class="rc-main">
<view class="rc-info">
<text class="rc-title">{{ item.title }}</text>
<text class="rc-sub">
{{ item.time_text }}{{ item.order_count > 0 ? ' · ' + item.order_count + '笔订单' : '' }}
</text>
</view>
<view class="rc-amt-box">
<text class="amt-sym">¥</text>
<text class="amt-int">{{ splitAmt(item.amount).int }}</text>
<text class="amt-dec">.{{ splitAmt(item.amount).dec }}</text>
</view>
</view>
<view class="reject-reason" v-if="item.status === 'reject' && item.audit_msg">
<text class="reject-txt">驳回原因:{{ item.audit_msg }}</text>
</view>
</view>
<template v-if="item.can_cancel || (item.status === 'issued' && item.invoice_file)">
<view class="rec-divider">
<view class="notch notch-l"></view>
<view class="dash-line"></view>
<view class="notch notch-r"></view>
</view>
<view class="rc-foot" @tap.stop>
<view class="op-btn outline clickable-hover" v-if="item.can_cancel" @tap="cancelItem(item)">撤回申请</view>
<view class="op-btn primary clickable-hover" v-if="item.status === 'issued' && item.invoice_file" @tap="goDetail(item.id)">
查看电子票
</view>
</view>
</template>
</view>
<view class="more-tip" v-if="loadingMore || !hasMore">
<text class="more-txt">{{ loadingMore ? '加载中...' : '没有更多了' }}</text>
</view>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue';
import { onLoad, onShow, onReachBottom } from '@dcloudio/uni-app';
import YjyfNavBar from '@/components/YjyfNavBar.vue';
import api from '@/utils/api.js';
import { isLogin, toLogin } from '@/utils/request.js';
import { getNavBarMetrics } from '@/utils/system.js';
const navHeight = ref(getNavBarMetrics().totalNavHeight);
const tabs = [
{ label: '全部', value: 'all' },
{ label: '开票中', value: 'wait' },
{ label: '已开票', value: 'issued' },
{ label: '已驳回', value: 'reject' },
{ label: '已撤回', value: 'cancel' }
];
const activeTab = ref('all');
const list = ref([]);
const page = ref(1);
const hasMore = ref(false);
const loading = ref(false);
const loadingMore = ref(false);
const loadError = ref('');
let reqSeq = 0;
function splitAmt(v) {
const n = Number(v || 0);
const s = (Number.isFinite(n) ? n : 0).toFixed(2);
const p = s.split('.');
return { int: p[0] || '0', dec: p[1] || '00' };
}
onLoad((opts) => {
if (opts && opts.status && tabs.some((t) => t.value === opts.status)) {
activeTab.value = opts.status;
}
});
function switchTab(val) {
if (activeTab.value === val) return;
activeTab.value = val;
reload();
}
async function reload() {
if (!isLogin()) {
toLogin();
return;
}
const seq = ++reqSeq;
page.value = 1;
loading.value = true;
loadError.value = '';
try {
const res = await api.invoiceRecords({ status: activeTab.value, page: 1, limit: 20 });
if (seq !== reqSeq) return;
list.value = (res && res.list) ? res.list : [];
hasMore.value = !!(res && res.has_more);
} catch (e) {
if (seq !== reqSeq) return;
loadError.value = (e && e.msg) ? e.msg : '获取开票记录失败';
} finally {
if (seq === reqSeq) {
loading.value = false;
}
}
}
async function loadMore() {
if (loading.value || loadingMore.value || !hasMore.value) return;
const seq = reqSeq;
const nextPage = page.value + 1;
loadingMore.value = true;
try {
const res = await api.invoiceRecords({ status: activeTab.value, page: nextPage, limit: 20 });
if (seq !== reqSeq) return;
const rows = (res && res.list) ? res.list : [];
list.value = list.value.concat(rows);
page.value = nextPage;
hasMore.value = !!(res && res.has_more);
} catch (e) {
} finally {
if (seq === reqSeq) {
loadingMore.value = false;
}
}
}
function goDetail(id) {
uni.navigateTo({ url: `/pages/invoice/detail?id=${id}` });
}
function goOrders() {
uni.navigateTo({ url: '/pages/invoice/orders' });
}
const cancelingId = ref(0);
function cancelItem(item) {
if (!item || cancelingId.value) return;
uni.showModal({
title: '撤回开票申请',
content: '撤回后可开票额度及关联订单将立即释放,确认撤回吗?',
confirmColor: '#F0710D',
success: async (r) => {
if (!r.confirm || cancelingId.value) return;
cancelingId.value = item.id;
try {
await api.invoiceCancel(item.id);
uni.showToast({ title: '已撤回开票申请' });
reload();
} catch (e) {
} finally {
cancelingId.value = 0;
}
}
});
}
onShow(() => {
navHeight.value = getNavBarMetrics().totalNavHeight;
reload();
});
onReachBottom(() => {
loadMore();
});
</script>
<style lang="scss" scoped>
.page {
min-height: 100vh;
background: $yjyf-bg-page;
padding-bottom: calc(48rpx + env(safe-area-inset-bottom));
box-sizing: border-box;
}
.tabs-bar {
position: sticky;
z-index: 15;
background: $yjyf-bg-card;
display: flex;
align-items: center;
border-bottom: 1rpx solid $yjyf-border-color;
}
.tab-item {
flex: 1;
height: 88rpx;
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.tab-txt {
font-size: $yjyf-font-sub;
color: $yjyf-text-secondary;
}
.tab-item.active .tab-txt {
font-size: $yjyf-font-body;
font-weight: 700;
color: $yjyf-primary;
}
.tab-line {
position: absolute;
bottom: 6rpx;
width: 40rpx;
height: 6rpx;
border-radius: $yjyf-radius-pill;
background: $yjyf-gradient-primary;
}
.state-box {
padding: 160rpx $yjyf-space-lg;
display: flex;
flex-direction: column;
align-items: center;
}
.empty-ico {
width: 168rpx;
height: 168rpx;
margin-bottom: $yjyf-space-md;
}
.state-title {
font-size: $yjyf-font-title;
font-weight: 600;
color: $yjyf-text-main;
}
.state-txt {
font-size: $yjyf-font-sub;
color: $yjyf-text-secondary;
}
.retry-btn,
.ghost-btn {
margin-top: $yjyf-space-lg;
height: 72rpx;
padding: 0 $yjyf-space-xl;
border-radius: $yjyf-radius-pill;
border: 2rpx solid $yjyf-primary;
background: $yjyf-bg-card;
color: $yjyf-primary;
font-size: $yjyf-font-sub;
font-weight: 600;
display: inline-flex;
align-items: center;
justify-content: center;
}
.list-wrap {
padding: $yjyf-space-md $yjyf-space-lg 0;
}
.rec-card {
position: relative;
overflow: hidden;
background: $yjyf-bg-card;
border-radius: $yjyf-radius-card;
margin-bottom: 20rpx;
box-shadow: 0 6rpx 20rpx rgba(31, 31, 31, 0.04);
}
.rc-upper {
padding: $yjyf-space-md;
}
.rc-top {
display: flex;
align-items: center;
justify-content: space-between;
}
.tag-type {
height: 36rpx;
padding: 0 14rpx;
border-radius: 8rpx;
background: rgba(74, 124, 255, 0.1);
color: $yjyf-info;
font-size: $yjyf-font-micro;
font-weight: 600;
display: inline-flex;
align-items: center;
&.special {
background: $yjyf-primary-bg;
color: $yjyf-primary;
}
}
.rc-status {
font-size: $yjyf-font-sub;
font-weight: 600;
color: $yjyf-warning;
&.st-issued {
color: $yjyf-success;
}
&.st-reject {
color: $yjyf-danger;
}
&.st-cancel {
color: $yjyf-text-muted;
}
}
.rc-main {
margin-top: 18rpx;
display: flex;
align-items: center;
justify-content: space-between;
gap: $yjyf-space-sm;
}
.rc-info {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
}
.rc-title {
font-size: $yjyf-font-body;
font-weight: 700;
color: $yjyf-text-main;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.rc-sub {
font-size: $yjyf-font-micro;
color: $yjyf-text-muted;
margin-top: 6rpx;
font-variant-numeric: tabular-nums;
}
.rc-amt-box {
display: flex;
align-items: baseline;
flex-shrink: 0;
}
.amt-sym {
font-size: $yjyf-font-sub;
font-weight: 700;
color: $yjyf-text-main;
margin-right: 2rpx;
}
.amt-int {
font-size: 36rpx;
font-weight: 700;
color: $yjyf-text-main;
font-variant-numeric: tabular-nums;
}
.amt-dec {
font-size: $yjyf-font-sub;
font-weight: 700;
color: $yjyf-text-main;
font-variant-numeric: tabular-nums;
}
.reject-reason {
margin-top: 16rpx;
padding: 12rpx 16rpx;
border-radius: 10rpx;
background: rgba(232, 51, 27, 0.08);
}
.reject-txt {
font-size: $yjyf-font-micro;
color: $yjyf-danger;
line-height: 1.45;
}
.rec-divider {
position: relative;
height: 20rpx;
display: flex;
align-items: center;
}
.dash-line {
flex: 1;
margin: 0 20rpx;
border-top: 2rpx dashed $yjyf-border-color;
}
.notch {
position: absolute;
top: 0;
width: 20rpx;
height: 20rpx;
border-radius: $yjyf-radius-pill;
background: $yjyf-bg-page;
}
.notch-l {
left: -10rpx;
}
.notch-r {
right: -10rpx;
}
.rc-foot {
padding: 10rpx $yjyf-space-md 18rpx;
display: flex;
align-items: center;
justify-content: flex-end;
gap: $yjyf-space-sm;
}
.op-btn {
height: 56rpx;
padding: 0 26rpx;
border-radius: $yjyf-radius-pill;
font-size: $yjyf-font-micro;
font-weight: 600;
display: inline-flex;
align-items: center;
justify-content: center;
&.outline {
border: 1rpx solid $yjyf-border-color;
color: $yjyf-text-regular;
background: $yjyf-bg-card;
}
&.primary {
background: $yjyf-gradient-primary;
color: $yjyf-text-inverse;
}
}
.more-tip {
padding: $yjyf-space-md 0;
text-align: center;
}
.more-txt {
font-size: $yjyf-font-micro;
color: $yjyf-text-muted;
}
</style>