import { useCallback, useEffect, useMemo, useState } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import { isLoggedIn, request } from '../lib/api'; import { storeStatusLabel, storeStatusPillClass, type StoreStatusValue } from '../lib/storeStatus'; type StatusFilter = 'ALL' | StoreStatusValue; const FILTERS: { key: StatusFilter; label: string }[] = [ { key: 'ALL', label: '全部' }, { key: 'OPEN', label: '营业中' }, { key: 'PAUSED', label: '暂时闭店' }, { key: 'CLOSED', label: '关闭' }, ]; export default function StoreListPage() { const navigate = useNavigate(); const [stores, setStores] = useState>>([]); const [q, setQ] = useState(''); const [filter, setFilter] = useState('ALL'); const [updatingId, setUpdatingId] = useState(null); const [error, setError] = useState(''); const loadStores = useCallback(() => { return request>>('PARTNER_H5', '/partner/stores').then(setStores); }, []); useEffect(() => { if (!isLoggedIn()) { navigate('/login'); return; } void loadStores(); }, [navigate, loadStores]); const filtered = useMemo(() => stores.filter((s) => { const matchQ = !q || String(s.name).includes(q) || String(s.address).includes(q); const matchStatus = filter === 'ALL' || String(s.status).toUpperCase() === filter; return matchQ && matchStatus; }), [stores, q, filter]); async function updateStatus(storeId: string, next: StoreStatusValue) { if (next === 'CLOSED') { const ok = window.confirm('关闭后不可恢复营业,确认关闭该门店?'); if (!ok) return; } setUpdatingId(storeId); setError(''); try { await request('PARTNER_H5', `/partner/stores/${storeId}/status`, { method: 'PUT', body: JSON.stringify({ status: next }), }); await loadStores(); } catch (e) { setError(e instanceof Error ? e.message : '状态更新失败'); } finally { setUpdatingId(null); } } return (

杜康好客

门店管理

管理您的合作门店及其运营状态

{error &&

{error}

}
search setQ(e.target.value)} />
{FILTERS.map((f) => ( ))}
{filtered.length === 0 &&
暂无门店
} {filtered.map((s) => { const storeId = String(s.id); const currentStatus = String(s.status).toUpperCase() as StoreStatusValue; const dim = currentStatus === 'CLOSED'; const storeName = String(s.name || '未命名门店'); const busy = updatingId === storeId; return (

门店名称

{storeName}

{String(s.address || s.district || '')}

{storeStatusLabel(currentStatus)}
{currentStatus === 'PAUSED' && ( )} edit
); })}
); }