文件
Henglianshutong/uniapp/pages/user/wallet/money.vue

617 行
16 KiB
Vue

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

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

<template>
<s-layout class="money-wrap" title="钱包">
<!-- 顶部黑金尊享资产卡片 -->
<view class="header-box">
<view class="asset-card">
<!-- 卡片顶栏 -->
<view class="card-top ss-flex ss-row-between ss-col-center">
<view class="top-tag ss-flex ss-col-center">
<text class="tag-badge">现金资产</text>
</view>
<view
class="eye-btn ss-flex ss-col-center"
@tap="state.showMoney = !state.showMoney"
>
<text class="eye-btn-text">{{ state.showMoney ? '隐藏金额' : '显示金额' }}</text>
<text
class="ss-m-l-6"
:class="state.showMoney ? 'cicon-eye' : 'cicon-eye-off'"
></text>
</view>
</view>
<!-- 余额核心大字数 -->
<view class="money-hero ss-flex ss-col-bottom ss-row-between">
<view class="hero-left ss-flex ss-col-bottom">
<text class="hero-symbol">¥</text>
<text class="hero-num">{{ state.showMoney ? (userInfo.money || '0.00') : '*****' }}</text>
<text class="hero-unit">元</text>
</view>
<button
v-if="state.canWithdraw"
class="ss-reset-button topup-btn ss-flex ss-row-center ss-col-center"
@tap="onWithdraw"
>
<text class="cicon-moneybag ss-m-r-6"></text>
<text>提现</text>
</button>
</view>
<!-- 底部数据栏:当前周期总收入 / 总支出 -->
<view class="card-footer ss-flex ss-row-between ss-col-center">
<view class="footer-metric">
<text class="metric-label">周期总收入</text>
<view class="metric-val-wrap ss-flex ss-col-bottom">
<text class="currency-symbol">¥</text>
<text class="metric-val">{{ state.showMoney ? (state.pagination.income || 0).toFixed(2) : '***' }}</text>
</view>
</view>
<view class="footer-metric">
<text class="metric-label">周期总支出</text>
<view class="metric-val-wrap ss-flex ss-col-bottom">
<text class="currency-symbol">¥</text>
<text class="metric-val">{{ state.showMoney ? (-state.pagination.expense || 0).toFixed(2) : '***' }}</text>
</view>
</view>
</view>
</view>
</view>
<!-- 吸顶筛选与 Tabs -->
<su-sticky>
<view class="filter-box ss-p-x-30 ss-flex ss-col-center ss-row-between">
<uni-datetime-picker
v-model="state.date"
type="daterange"
@change="onChangeTime"
:end="state.today"
>
<button class="ss-reset-button date-btn ss-flex ss-col-center">
<text class="cicon-calendar ss-m-r-8"></text>
<text>{{ dateFilterText }}</text>
<text class="cicon-drop-down ss-m-l-6"></text>
</button>
</uni-datetime-picker>
<view class="stats-summary ss-flex ss-col-center">
<view class="stat-tag income ss-m-r-12">
入 +¥{{ (state.pagination.income || 0).toFixed(2) }}
</view>
<view class="stat-tag expense">
出 -¥{{ (-state.pagination.expense || 0).toFixed(2) }}
</view>
</view>
</view>
<su-tabs
:list="tabMaps"
@change="onChange"
:scrollable="false"
:current="state.currentTab"
></su-tabs>
</su-sticky>
<!-- 列表标题区 -->
<view class="section-header ss-flex ss-row-between ss-col-center">
<view class="section-title-wrap ss-flex ss-col-center">
<view class="title-bar"></view>
<text class="section-title">收支明细</text>
</view>
<text class="section-subtitle">实时流水入账</text>
</view>
<!-- 空状态 -->
<view class="empty-wrap" v-if="state.pagination.total === 0">
<s-empty text="暂无收支明细" icon="/static/data-empty.png" />
</view>
<!-- 流水卡片列表 -->
<view class="list-container" v-if="state.pagination.total > 0">
<view
class="log-card"
v-for="item in state.pagination.data"
:key="item.id"
>
<view class="log-top ss-flex ss-row-between ss-col-center">
<view class="log-title-box ss-flex ss-col-center">
<view
class="coin-icon ss-flex ss-row-center ss-col-center"
:class="item.amount >= 0 ? 'income' : 'expense'"
>
<text :class="item.amount >= 0 ? 'cicon-wallet' : 'cicon-order'"></text>
</view>
<view class="log-main-info">
<text class="log-title">{{ item.event_text }}{{ item.memo ? ' · ' + item.memo : '' }}</text>
<text class="log-date">{{ item.createtime }}</text>
</view>
</view>
<view class="log-amount ss-flex ss-col-center">
<text v-if="item.amount >= 0" class="amount-plus">+</text>
<text class="amount-num" :class="item.amount >= 0 ? 'income-num' : 'expense-num'">
{{ item.amount }}
</text>
<text class="amount-unit">元</text>
</view>
</view>
</view>
</view>
<!-- 加载更多 -->
<uni-load-more
v-if="state.pagination.total > 0"
:status="state.loadStatus"
:content-text="{
contentdown: '上拉加载更多',
}"
/>
</s-layout>
</template>
<script setup>
import { computed, reactive } from 'vue';
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app';
import sheep from '@/sheep';
import dayjs from 'dayjs';
import _ from 'lodash';
const pagination = {
data: [],
current_page: 1,
total: 1,
last_page: 1,
expense: 0,
income: 0,
};
const state = reactive({
showMoney: true,
canWithdraw: false,
date: [],
currentTab: 0,
pagination,
loadStatus: '',
today: '',
});
const tabMaps = [
{
name: '全部',
value: 'all',
},
{
name: '收益分成',
value: 'reward',
},
{
name: '收入',
value: 'income',
},
{
name: '支出',
value: 'expense',
},
];
const userInfo = computed(() => sheep.$store('user').userInfo || {});
const dateFilterText = computed(() => {
if (!state.date || state.date.length === 0) return '选择日期';
if (state.date[0] === state.date[1]) {
return state.date[0];
} else {
return `${state.date[0]} ~ ${state.date[1]}`;
}
});
async function checkWithdrawStatus() {
try {
const appStore = sheep.$store('app');
if (appStore?.platform && typeof appStore.platform.withdraw_status === 'boolean') {
state.canWithdraw = appStore.platform.withdraw_status;
}
const res = await sheep.$api.pay.withdraw.rules();
if (res?.code === 1 && res.data) {
const isOpen = (res.data.status === undefined || Number(res.data.status) === 1)
&& Array.isArray(res.data.methods)
&& res.data.methods.length > 0;
state.canWithdraw = Boolean(isOpen);
}
} catch (e) {
state.canWithdraw = false;
}
}
function onWithdraw() {
if (!state.canWithdraw) {
sheep.$helper.toast('暂未开启提现功能');
return;
}
sheep.$router.go('/pages/pay/withdraw');
}
async function getLogList(page = 1, list_rows = 10) {
state.loadStatus = 'loading';
try {
const res = await sheep.$api.user.wallet.log({
type: 'money',
tab: tabMaps[state.currentTab].value,
list_rows,
page,
date: appendTimeHMS(state.date),
});
if (res?.code === 1) {
const list = page === 1 ? res.data.list.data : _.concat(state.pagination.data, res.data.list.data);
state.pagination = {
...res.data.list,
data: list,
income: res.data.income || 0,
expense: res.data.expense || 0,
};
state.loadStatus = state.pagination.current_page < state.pagination.last_page ? 'more' : 'noMore';
return;
}
} catch (e) {}
state.loadStatus = 'noMore';
}
onLoad(async () => {
state.today = dayjs().format('YYYY-MM-DD');
state.date = [state.today, state.today];
sheep.$store('user').getInfo();
checkWithdrawStatus();
getLogList(1);
});
onPullDownRefresh(async () => {
await sheep.$store('user').getInfo();
await checkWithdrawStatus();
await getLogList(1);
uni.stopPullDownRefresh();
});
function onChange(e) {
state.pagination = { ...pagination, data: [] };
state.currentTab = e.index;
getLogList(1);
}
function onChangeTime(e) {
state.date[0] = e[0];
state.date[1] = e[e.length - 1];
state.pagination = { ...pagination, data: [] };
getLogList(1);
}
function appendTimeHMS(arr) {
if (!arr || arr.length < 2) return undefined;
return [`${arr[0]} 00:00:00`, `${arr[1]} 23:59:59`];
}
onReachBottom(() => {
if (state.loadStatus !== 'noMore') {
getLogList(state.pagination.current_page + 1);
}
});
</script>
<style lang="scss" scoped>
.money-wrap {
min-height: 100vh;
background-color: #f7f8fa;
}
/* 顶部资产区域 */
.header-box {
padding: 24rpx 30rpx 10rpx;
.asset-card {
width: 100%;
box-sizing: border-box;
padding: 36rpx 32rpx 30rpx;
border-radius: 28rpx;
background: linear-gradient(138deg, #20222a 0%, #15161a 52%, #2c2419 100%);
box-shadow: 0 16rpx 36rpx rgba(18, 19, 23, 0.18), inset 0 1rpx 0 rgba(247, 219, 168, 0.28);
border: 1rpx solid rgba(235, 197, 131, 0.26);
position: relative;
overflow: hidden;
&::before {
content: '';
position: absolute;
right: -60rpx;
top: -60rpx;
width: 240rpx;
height: 240rpx;
background: radial-gradient(circle, rgba(235, 197, 131, 0.16) 0%, rgba(235, 197, 131, 0) 70%);
border-radius: 50%;
pointer-events: none;
}
.card-top {
position: relative;
z-index: 2;
.top-tag {
.tag-badge {
font-size: 20rpx;
color: #2a2012;
background: linear-gradient(90deg, #f7dfa6 0%, #e2be78 100%);
padding: 4rpx 14rpx;
border-radius: 8rpx;
font-weight: 600;
}
}
.eye-btn {
padding: 6rpx 18rpx;
background: rgba(255, 255, 255, 0.08);
border: 1rpx solid rgba(235, 197, 131, 0.3);
border-radius: 24rpx;
.eye-btn-text {
font-size: 22rpx;
color: #f2cf8f;
}
.cicon-eye,
.cicon-eye-off {
font-size: 24rpx;
color: #f2cf8f;
}
}
}
/* 核心数值展示 */
.money-hero {
margin-top: 24rpx;
position: relative;
z-index: 2;
.hero-left {
.hero-symbol {
font-size: 36rpx;
font-weight: 700;
color: #ffffff;
margin-right: 6rpx;
margin-bottom: 6rpx;
}
.hero-num {
font-size: 64rpx;
font-weight: 700;
color: #ffffff;
line-height: 1.1;
font-family: OPPOSANS, DIN, -apple-system, sans-serif;
letter-spacing: 1rpx;
}
.hero-unit {
font-size: 26rpx;
color: #f4d397;
font-weight: 600;
margin-left: 12rpx;
margin-bottom: 6rpx;
}
}
.topup-btn {
height: 56rpx;
padding: 0 28rpx;
background: linear-gradient(90deg, #f7dfa6 0%, #e2be78 100%);
border-radius: 28rpx;
color: #3b2b10;
font-size: 24rpx;
font-weight: 600;
box-shadow: 0 6rpx 16rpx rgba(226, 190, 120, 0.28);
}
}
/* 底部收支汇总栏 */
.card-footer {
margin-top: 26rpx;
padding-top: 22rpx;
border-top: 1rpx solid rgba(255, 255, 255, 0.08);
position: relative;
z-index: 2;
.footer-metric {
flex: 1;
.metric-label {
font-size: 22rpx;
color: rgba(255, 255, 255, 0.55);
display: block;
margin-bottom: 6rpx;
}
.metric-val-wrap {
.currency-symbol {
font-size: 24rpx;
color: #f4d397;
font-weight: 600;
margin-right: 2rpx;
margin-bottom: 2rpx;
}
.metric-val {
font-size: 30rpx;
font-weight: 700;
color: #f4d397;
font-family: OPPOSANS, DIN, -apple-system, sans-serif;
}
}
}
}
}
}
/* 筛选区域 */
.filter-box {
height: 104rpx;
background-color: #ffffff;
border-bottom: 1rpx solid #f1f2f5;
.date-btn {
background-color: #f7f8fa;
height: 60rpx;
line-height: 60rpx;
border-radius: 30rpx;
padding: 0 24rpx;
font-size: 24rpx;
color: #374151;
font-weight: 500;
.cicon-calendar {
font-size: 28rpx;
color: #9ca3af;
}
.cicon-drop-down {
font-size: 24rpx;
color: #9ca3af;
}
}
.stats-summary {
.stat-tag {
font-size: 22rpx;
font-family: OPPOSANS;
padding: 4rpx 14rpx;
border-radius: 8rpx;
font-weight: 500;
&.income {
background-color: #e6f9f0;
color: #10b981;
}
&.expense {
background-color: #fef2f2;
color: #ef4444;
}
}
}
}
/* 列表标题区 */
.section-header {
padding: 30rpx 32rpx 16rpx;
.section-title-wrap {
.title-bar {
width: 6rpx;
height: 28rpx;
border-radius: 4rpx;
background: linear-gradient(180deg, #dfb775 0%, #ba8938 100%);
margin-right: 14rpx;
}
.section-title {
font-size: 30rpx;
font-weight: 600;
color: #22252a;
}
}
.section-subtitle {
font-size: 22rpx;
color: #999ea6;
}
}
.empty-wrap {
padding: 60rpx 0;
}
/* 卡片流列表 */
.list-container {
padding: 0 30rpx 20rpx;
.log-card {
background: #ffffff;
border-radius: 20rpx;
padding: 26rpx 28rpx;
margin-bottom: 20rpx;
box-shadow: 0 4rpx 16rpx rgba(35, 42, 60, 0.04);
border: 1rpx solid #f0f1f5;
.log-top {
.log-title-box {
.coin-icon {
width: 64rpx;
height: 64rpx;
border-radius: 50%;
margin-right: 18rpx;
&.income {
background: linear-gradient(135deg, #e6f9f0 0%, #c9f4de 100%);
.cicon-wallet {
font-size: 32rpx;
color: #10b981;
}
}
&.expense {
background: linear-gradient(135deg, #fef2f2 0%, #fde2e2 100%);
.cicon-order {
font-size: 32rpx;
color: #ef4444;
}
}
}
.log-main-info {
display: flex;
flex-direction: column;
.log-title {
font-size: 28rpx;
font-weight: 600;
color: #23272e;
margin-bottom: 6rpx;
max-width: 380rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.log-date {
font-size: 22rpx;
color: #9ea4af;
}
}
}
.log-amount {
.amount-plus {
font-size: 30rpx;
font-weight: 700;
color: #b58028;
margin-right: 2rpx;
}
.amount-num {
font-size: 34rpx;
font-weight: 700;
font-family: OPPOSANS, DIN, -apple-system, sans-serif;
&.income-num {
color: #b58028;
}
&.expense-num {
color: #1f2937;
}
}
.amount-unit {
font-size: 22rpx;
color: #6b7280;
margin-left: 4rpx;
}
}
}
}
}
</style>