import {useEffect, useState} from "react"; import Taro from '@tarojs/taro' import {Button, Cell, Space, Empty, ConfigProvider, InfiniteLoading} from '@nutui/nutui-react-taro' import {View, ScrollView} from '@tarojs/components' import {pageUserBalanceLog} from "@/api/user/balance-log"; import {UserBalanceLog} from "@/api/user/balance-log/model"; import {formatCurrency} from "@/utils/common"; const Wallet = () => { const [list, setList] = useState([]) const [loading, setLoading] = useState(false) const [loadingMore, setLoadingMore] = useState(false) const [refreshing, setRefreshing] = useState(false) const [hasMore, setHasMore] = useState(true) const [currentPage, setCurrentPage] = useState(1) const [total, setTotal] = useState(0) const pageSize = 20 const reload = () => { setLoading(true) const userId = Taro.getStorageSync('UserId') console.log('Loading balance log for userId:', userId) if (!userId) { console.warn('No userId found in storage') Taro.showToast({ title: '请先登录', icon: 'error' }); setLoading(false) return } pageUserBalanceLog({ userId: parseInt(userId), page: 1, limit: 20 }) .then((res: any) => { console.log('Balance log response:', res) setList(res?.list || []) }) .catch((error: any) => { console.error('Balance log error:', error) Taro.showToast({ title: error?.message || '获取失败', icon: 'error' }); }) .finally(() => { setLoading(false) }) } useEffect(() => { reload() }, []); if (loading) { return (
加载中...
) } if (list.length == 0) { return (
) } return ( {list.map((item, index) => ( {item.scene === 10 ? '会员充值' : item.scene === 20 ? '用户消费' : item.scene === 30 ? '管理员操作' : '订单退款'} {item.comments} {item.scene === 10 ? '+' : '-'} {formatCurrency(Number(item.money), 'CNY') || '0.00'} {item.createTime} {item.remark && ( 备注: {item.remark} )} ))} ); }; export default Wallet;