仰望星辰工作室

better-staridc-MNBT

better-staridc-MNBT/ templates/tdesign/spa/src/account/views/BalanceView.vue 5.4 KB · 239 行 原始文件
Z zfhsh first commit 2 个月前
1<template>
2 <div class="td-page">
3 <!-- 余额总览 -->
4 <div class="balance-hero td-card">
5 <div class="balance-hero-left">
6 <div class="balance-hero-icon"><i class="mdi mdi-wallet"></i></div>
7 <div>
8 <div class="balance-hero-label">当前余额</div>
9 <div class="balance-hero-amount">¥{{ balanceText }}</div>
10 </div>
11 </div>
12 <div class="balance-hero-right">
13 <t-button theme="primary" @click="router.push('/balance/recharge')">
14 <i class="mdi mdi-plus"></i> 立即充值
15 </t-button>
16 </div>
17 </div>
18
19 <!-- 流水列表 -->
20 <div class="td-card">
21 <div class="td-card-head">余额流水</div>
22 <div class="log-list" v-if="logs.length">
23 <div class="log-item" v-for="log in logs" :key="log.id">
24 <div class="log-type" :class="'log-type-' + (log.amount >= 0 ? 'in' : 'out')">
25 <i class="mdi" :class="typeIcon(log.type)"></i>
26 </div>
27 <div class="log-main">
28 <div class="log-title">
29 <strong>{{ typeText(log.type) }}</strong>
30 <span class="log-no" v-if="log.order_no">单号 {{ log.order_no }}</span>
31 </div>
32 <div class="log-meta">
33 <span v-if="log.remark">{{ log.remark }}</span>
34 <span class="log-time">{{ log.created_at }}</span>
35 </div>
36 </div>
37 <div class="log-amount" :class="log.amount >= 0 ? 'amount-in' : 'amount-out'">
38 {{ log.amount >= 0 ? '+' : '' }}{{ centsToYuan(log.amount) }}
39 </div>
40 <div class="log-balance">余额 ¥{{ centsToYuan(log.balance_after) }}</div>
41 </div>
42 </div>
43 <t-empty v-else description="暂无流水记录" style="padding: 40px 0" />
44
45 <!-- 分页 -->
46 <div class="pager" v-if="total > perPage">
47 <t-pagination
48 v-model:current="page"
49 :page-size="perPage"
50 :total="total"
51 :show-jumper="true"
52 @change="load"
53 />
54 </div>
55 </div>
56 </div>
57</template>
58
59<script setup>
60import { ref, computed, onMounted } from 'vue'
61import { useRouter } from 'vue-router'
62import { getBalanceInfo, centsToYuan } from '@/account/api/plugins'
63
64const router = useRouter()
65const balanceCents = ref(0)
66const logs = ref([])
67const page = ref(1)
68const perPage = 15
69const total = ref(0)
70
71const balanceText = computed(() => centsToYuan(balanceCents.value))
72
73function typeText(type) {
74 return { recharge: '充值', consume: '消费', refund: '退款', adjust: '调整' }[type] || type
75}
76
77function typeIcon(type) {
78 return {
79 recharge: 'mdi-cash',
80 consume: 'mdi-cart-outline',
81 refund: 'mdi-currency-cny',
82 adjust: 'mdi-tune',
83 }[type] || 'mdi-history'
84}
85
86async function load() {
87 const res = await getBalanceInfo(page.value, perPage)
88 if (!res.ok) return
89 balanceCents.value = res.data.balance_cents ?? 0
90 const logsData = res.data.logs || {}
91 logs.value = logsData.list || []
92 total.value = logsData.total || 0
93}
94
95onMounted(load)
96</script>
97
98<style scoped>
99.balance-hero {
100 display: flex;
101 align-items: center;
102 justify-content: space-between;
103 gap: 16px;
104 padding: 24px;
105 margin-bottom: 16px;
106 background: linear-gradient(135deg, var(--td-brand) 0%, var(--td-brand-dark) 100%);
107 border: none;
108 flex-wrap: wrap;
109}
110.balance-hero-left {
111 display: flex;
112 align-items: center;
113 gap: 16px;
114 min-width: 0;
115}
116.balance-hero-icon {
117 width: 52px;
118 height: 52px;
119 border-radius: 12px;
120 background: rgba(255, 255, 255, 0.18);
121 display: grid;
122 place-items: center;
123 color: #fff;
124 font-size: 28px;
125 flex-shrink: 0;
126}
127.balance-hero-label {
128 font-size: 13px;
129 color: rgba(255, 255, 255, 0.85);
130}
131.balance-hero-amount {
132 font-size: 28px;
133 font-weight: 700;
134 color: #fff;
135 letter-spacing: -0.02em;
136 margin-top: 2px;
137}
138.balance-hero-right :deep(.t-button) {
139 --td-brand-color: #fff;
140 --td-brand-color-hover: rgba(255, 255, 255, 0.92);
141 --td-brand-color-active: rgba(255, 255, 255, 0.85);
142 --td-brand-color-focus: rgba(255, 255, 255, 0.2);
143 color: var(--td-brand);
144 border: none;
145}
146
147/* 流水列表 */
148.log-list {
149 padding: 4px 0;
150}
151.log-item {
152 display: flex;
153 align-items: center;
154 gap: 14px;
155 padding: 14px 18px;
156 border-bottom: 1px solid var(--td-border);
157}
158.log-item:last-child {
159 border-bottom: none;
160}
161.log-type {
162 width: 38px;
163 height: 38px;
164 border-radius: 10px;
165 display: grid;
166 place-items: center;
167 font-size: 19px;
168 flex-shrink: 0;
169}
170.log-type-in {
171 background: #e8f8f0;
172 color: #2ba471;
173}
174.log-type-out {
175 background: #fdeeee;
176 color: #d54941;
177}
178.log-main {
179 flex: 1;
180 min-width: 0;
181}
182.log-title {
183 display: flex;
184 align-items: center;
185 gap: 10px;
186 flex-wrap: wrap;
187}
188.log-title strong {
189 font-size: 14px;
190 color: var(--td-text);
191 font-weight: 600;
192}
193.log-no {
194 font-size: 12px;
195 color: var(--td-text-placeholder);
196}
197.log-meta {
198 display: flex;
199 align-items: center;
200 gap: 12px;
201 font-size: 12px;
202 color: var(--td-text-secondary);
203 margin-top: 3px;
204 flex-wrap: wrap;
205}
206.log-time {
207 color: var(--td-text-placeholder);
208}
209.log-amount {
210 font-size: 15px;
211 font-weight: 600;
212 white-space: nowrap;
213}
214.amount-in {
215 color: #2ba471;
216}
217.amount-out {
218 color: #d54941;
219}
220.log-balance {
221 font-size: 12px;
222 color: var(--td-text-secondary);
223 white-space: nowrap;
224 text-align: right;
225}
226
227.pager {
228 display: flex;
229 justify-content: flex-end;
230 padding: 16px 18px;
231 border-top: 1px solid var(--td-border);
232}
233
234@media (max-width: 640px) {
235 .log-balance {
236 display: none;
237 }
238}
239</style>