文件
fenleixinxi/uniapp/pages/member/flows.vue

226 行
5.5 KiB
Vue

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

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

<template>
<view class="flows">
<!-- 渐变头部:导航 + 类型筛选融为一体,避免筛选行贴状态栏 -->
<view class="flows__hero">
<fc-navbar title="余额明细" theme="gradient" :show-back="true" />
<view class="flows__tabs">
<view v-for="t in tabs" :key="t.key" class="flows__tab"
:class="{ 'flows__tab--active': type === t.key }" @click="switchType(t.key)">
<text>{{ t.name }}</text>
</view>
</view>
</view>
<!-- 明细列表 -->
<view class="flows__list">
<fc-empty v-if="list.length === 0 && !loading" icon="receipt" :text="'暂无' + typeText + '记录'" />
<template v-else>
<view v-for="f in list" :key="f.flowNo" class="flows__item">
<view class="flows__item-main">
<text class="flows__item-scene">{{ f.scene }}</text>
<text class="flows__item-time">{{ formatTime(f.createdAt) }}</text>
</view>
<view class="flows__item-side">
<text class="flows__item-amount" :class="f.type === 'income' ? 'is-income' : 'is-expense'">
{{ f.type === 'income' ? '+' : '-' }}{{ Number(f.amount).toFixed(2) }}
</text>
<text class="flows__item-balance">余额 {{ Number(f.balance).toFixed(2) }}</text>
</view>
</view>
<text v-if="loading" class="flows__more">加载中…</text>
<text v-else-if="hasMore" class="flows__more">上拉加载更多</text>
<text v-else-if="list.length > 0" class="flows__more">没有更多了</text>
</template>
</view>
</view>
</template>
<script>
import FcNavbar from '@/components/fc-navbar/fc-navbar.vue'
import FcEmpty from '@/components/fc-empty/fc-empty.vue'
import memberApi from '@/common/api/member.js'
export default {
components: { FcNavbar, FcEmpty },
data() {
return {
tabs: [
{ key: '', name: '全部' },
{ key: 'recharge', name: '充值' },
{ key: 'expense', name: '消费' },
{ key: 'refund', name: '退款' },
],
type: '',
list: [],
page: 1,
hasMore: false,
loading: false,
}
},
computed: {
typeText() {
const t = this.tabs.find((x) => x.key === this.type)
return t && t.name !== '全部' ? t.name : ''
},
},
onLoad() {
this.reload()
},
/** 上拉加载更多 */
onReachBottom() {
if (this.hasMore && !this.loading) {
this.loadMore()
}
},
methods: {
switchType(key) {
if (this.type === key) return
this.type = key
this.reload()
},
/** 切换类型 / 首次进入:重置并加载第一页 */
reload() {
this.page = 1
this.list = []
this.hasMore = false
return this.loadMore()
},
async loadMore() {
if (this.loading) return
this.loading = true
try {
const res = await memberApi.flows({ page: this.page, size: 15, type: this.type })
const rows = (res && res.list) || []
this.list = this.page === 1 ? rows : this.list.concat(rows)
this.hasMore = !!(res && res.hasMore)
if (this.hasMore) this.page++
} catch (e) {
uni.showToast({ title: e.message || '加载失败', icon: 'none' })
} finally {
this.loading = false
}
},
/** ISO 时间转本地短格式(今天显示时分,其余显示月-日) */
formatTime(iso) {
if (!iso) return ''
const d = new Date(iso)
if (isNaN(d.getTime())) return ''
const now = new Date()
const pad = (n) => String(n).padStart(2, '0')
if (d.toDateString() === now.toDateString()) {
return `今天 ${pad(d.getHours())}:${pad(d.getMinutes())}`
}
return `${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
},
},
}
</script>
<style lang="scss" scoped>
.flows {
min-height: 100vh;
background: $fc-bg;
padding-bottom: calc(60rpx + env(safe-area-inset-bottom));
}
/* 渐变头部:导航与筛选一体,底部圆角过渡到列表区 */
.flows__hero {
background: $fc-gradient-hero;
border-radius: 0 0 40rpx 40rpx;
padding-bottom: 24rpx;
}
/* 类型筛选(胶囊分段控件) */
.flows__tabs {
display: flex;
gap: 16rpx;
padding: 12rpx 28rpx 0;
}
.flows__tab {
flex: 1;
height: 68rpx;
border-radius: $fc-radius-pill;
background: rgba(255, 255, 255, 0.9);
border: 2rpx solid $fc-border;
display: flex;
align-items: center;
justify-content: center;
font-size: $fc-font-sm;
color: $fc-text-secondary;
transition: all 0.2s ease;
&--active {
background: $fc-gradient-primary;
border-color: transparent;
color: $fc-primary-ink;
font-weight: 700;
box-shadow: 0 6rpx 18rpx rgba(0, 210, 106, 0.22);
}
}
/* 明细列表 */
.flows__list {
margin: 24rpx 28rpx 0;
background: #ffffff;
border-radius: $fc-radius-lg;
padding: 8rpx 28rpx;
box-shadow: $fc-shadow-sm;
}
.flows__item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 28rpx 0;
border-bottom: 2rpx solid $fc-border;
&:last-of-type {
border-bottom: none;
}
}
.flows__item-main {
display: flex;
flex-direction: column;
min-width: 0;
}
.flows__item-scene {
font-size: $fc-font-base;
color: $fc-text;
font-weight: 500;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.flows__item-time {
margin-top: 8rpx;
font-size: $fc-font-xs;
color: $fc-text-placeholder;
}
.flows__item-side {
display: flex;
flex-direction: column;
align-items: flex-end;
flex-shrink: 0;
margin-left: 20rpx;
}
.flows__item-amount {
font-size: $fc-font-base;
font-weight: 700;
&.is-income {
color: $fc-primary-text;
}
&.is-expense {
color: $fc-price;
}
}
.flows__item-balance {
margin-top: 8rpx;
font-size: $fc-font-xs;
color: $fc-text-placeholder;
}
.flows__more {
display: block;
padding: 24rpx 0 16rpx;
text-align: center;
font-size: $fc-font-xs;
color: $fc-text-placeholder;
}
</style>