import { useEffect, useState } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import TabMainHeader from '../components/TabMainHeader'; import AppImage from '@dukang/shared-ui/AppImage'; import { clearAuth, request } from '../lib/api'; const DEFAULT_AVATAR = 'https://lh3.googleusercontent.com/aida-public/AB6AXuAz_9Pnpk_Md4sEU6PXkeybus8oLZO9e-3pOpLuSwBX0jm_Z0JCfX1w2oZxz1VZayTh0PKUPjwjSuxJVX410fjtWFGR_f55f-nWppXWUweHRnEC7WyIWEqx4AyVHt-k02OhyaSGQfvY5cHG5IuRe9EqdcHy47gBQ82_cxGgX-DrKV4oYcwLoNRynAV0_xv2p1GOhisnQVulHwZcQClUJcP8q4nTY0Y3DR1w4ioa0DYTHePE43mLDJptjZcQqS7V8LihJdn4ze6fvQA'; const ORDER_SHORTCUTS = [ { tab: 'pending_pay', icon: 'payments', label: '待付款' }, { tab: 'pending_ship', icon: 'package_2', label: '待发货' }, { tab: 'pending_receive', icon: 'local_shipping', label: '配送中' }, { tab: 'completed', icon: 'task_alt', label: '已完成' }, ] as const; const SERVICES = [ { icon: 'location_on', label: '地址管理', to: '/addresses' }, { icon: 'storefront', label: '可用门店', to: '/stores' }, { icon: 'headset_mic', label: '联系客服', badge: '在线中', action: 'cs' as const }, { icon: 'info', label: '关于我们', action: 'about' as const }, ] as const; function formatMoney(amount: number) { return amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); } export default function MinePage() { const navigate = useNavigate(); const [profile, setProfile] = useState | null>(null); const [benefitBalance, setBenefitBalance] = useState(0); const [orderCounts, setOrderCounts] = useState>({}); const [toast, setToast] = useState(''); useEffect(() => { Promise.all([ request>('USER_H5', '/auth/me'), request>>('USER_H5', '/benefit/coupons'), ...ORDER_SHORTCUTS.map((s) => request<{ total: number }>('USER_H5', `/trade/orders?tab=${s.tab}&pageSize=1`), ), ]) .then(([me, coupons, ...totals]) => { setProfile(me); const balance = coupons.reduce((sum, c) => { if (String(c.status) === 'ACTIVE') return sum + Number(c.balance || 0); return sum; }, 0); setBenefitBalance(balance); const counts: Record = {}; ORDER_SHORTCUTS.forEach((s, i) => { counts[s.tab] = totals[i]?.total ?? 0; }); setOrderCounts(counts); }) .catch(() => {}); }, []); function showToast(msg: string) { setToast(msg); window.setTimeout(() => setToast(''), 2200); } function handleService(item: (typeof SERVICES)[number]) { if ('to' in item && item.to) return; if (item.action === 'cs') showToast('preV1:在线客服即将开放'); if (item.action === 'about') showToast('杜康好客 · 传承千年酒文化'); } function logout() { clearAuth(); navigate('/login'); } const nickname = String(profile?.nickname || '用户'); const userNo = String(profile?.userNo || ''); const avatar = String(profile?.avatarUrl || DEFAULT_AVATAR); return (
verified

{nickname}

{userNo && ID: {userNo}} 好客会员

account_balance_wallet 我的资产

查看明细 chevron_right

好客权益余额

¥ {formatMoney(benefitBalance)}
去使用

我的订单

全部订单 chevron_right
{ORDER_SHORTCUTS.map((item) => { const count = orderCounts[item.tab] ?? 0; return (
{item.icon} {count > 0 && ( {count > 99 ? '99+' : count} )}
{item.label} ); })}
{SERVICES.map((item, index) => { const inner = ( <>
{item.icon} {item.label}
{'badge' in item && item.badge && ( {item.badge} )} chevron_right
); if ('to' in item && item.to) { return ( {inner} ); } return ( ); })}

杜康好客 V2.4.0

{toast &&
{toast}
}
); }