"use client" import { Badge } from "@/components/ui/badge" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" import { getShopIncomeStats } from "@/lib/api" import type { ShopIncomeStats } from "@/lib/api/shops" import { listWalletTransactions } from "@/lib/api/transactions" import { toApiError } from "@/lib/errors" import { useMyShop } from "@/lib/hooks/use-my-shop" import type { WalletTransaction } from "@/lib/types" import { ArrowDownLeft, ArrowUpRight, CreditCard, DollarSign } from "lucide-react" import { useEffect, useState } from "react" const emptyStats: ShopIncomeStats = { monthlyIncome: "0", pendingSettlement: "0", totalWithdrawn: "0", totalOrders: 0, completedOrders: 0, } export default function ShopIncomePage() { const { shop, loading, error } = useMyShop() const [transactions, setTransactions] = useState([]) const [stats, setStats] = useState(emptyStats) const [isLoading, setIsLoading] = useState(false) const [loadError, setLoadError] = useState(null) useEffect(() => { if (!shop) return const shopId = shop.id let cancelled = false async function load() { setIsLoading(true) setLoadError(null) try { const [nextStats, nextTransactions] = await Promise.all([ getShopIncomeStats(shopId), listWalletTransactions({ offset: 0, limit: 1000 }), ]) if (cancelled) return setStats(nextStats) setTransactions(nextTransactions) } catch (error) { if (cancelled) return setLoadError(toApiError(error).msg) } finally { if (!cancelled) setIsLoading(false) } } void load() return () => { cancelled = true } }, [shop]) if (loading) { return
加载中...
} if (error) { return
{error}
} if (!shop) { return
当前账号没有可管理的店铺
} const relatedTransactions = transactions.filter( (transaction) => transaction.type === "income" || transaction.type === "withdrawal", ) return (

收入统计

本月收入
¥{stats.monthlyIncome}
待结算
¥{stats.pendingSettlement}
累计提现
¥{stats.totalWithdrawn}
交易明细 类型 描述 金额 时间 {isLoading ? ( 加载中... ) : loadError ? ( {loadError} ) : relatedTransactions.length > 0 ? ( relatedTransactions.map((transaction) => (
{Number(transaction.amount) > 0 ? ( ) : ( )} 0 ? "default" : "secondary"}> {transaction.type === "topup" ? "充值" : transaction.type === "payment" ? "支付" : transaction.type === "income" ? "收入" : transaction.type === "withdrawal" ? "提现" : "退款"}
{transaction.description} 0 ? "text-green-600" : "text-red-600"} > {Number(transaction.amount) > 0 ? "+" : ""} {transaction.amount} {new Date(transaction.createdAt).toLocaleString()}
)) ) : ( 暂无交易记录 )}
) }