@@ -13,9 +13,12 @@ export default function SelectStorePage() {
|
||||
const navigate = useNavigate();
|
||||
const { applySession, store, authenticated } = useStoreSession();
|
||||
const [stores, setStores] = useState<ShopStoreOption[]>(store?.stores ?? []);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [loadingId, setLoadingId] = useState<string | null>(null);
|
||||
const [msg, setMsg] = useState('');
|
||||
|
||||
const currentStoreId = store?.storeId || '';
|
||||
const canGoBack = Boolean(currentStoreId);
|
||||
|
||||
useEffect(() => {
|
||||
if (!authenticated) {
|
||||
navigate('/login', { replace: true });
|
||||
@@ -27,7 +30,12 @@ export default function SelectStorePage() {
|
||||
}, [authenticated, navigate]);
|
||||
|
||||
async function onSelect(storeId: string) {
|
||||
setLoading(true);
|
||||
if (loadingId) return;
|
||||
if (storeId === currentStoreId) {
|
||||
navigate('/', { replace: true });
|
||||
return;
|
||||
}
|
||||
setLoadingId(storeId);
|
||||
setMsg('');
|
||||
try {
|
||||
const session = await selectStore(storeId);
|
||||
@@ -36,7 +44,7 @@ export default function SelectStorePage() {
|
||||
} catch (e) {
|
||||
setMsg(e instanceof Error ? e.message : '选店失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
setLoadingId(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,31 +56,101 @@ export default function SelectStorePage() {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [stores.length]);
|
||||
|
||||
function statusLabel(status: string) {
|
||||
if (status === 'OPEN') return '营业中';
|
||||
if (status === 'PAUSED') return '暂停营业';
|
||||
return status || '门店';
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="shop-select-store-page">
|
||||
<header className="shop-select-store-header">
|
||||
<h1>选择门店</h1>
|
||||
<p>该账号绑定了多家门店,请选择本次要进入的门店</p>
|
||||
<header className="shop-subpage-header">
|
||||
{canGoBack ? (
|
||||
<button
|
||||
type="button"
|
||||
className="shop-subpage-back"
|
||||
onClick={() => navigate('/mine')}
|
||||
aria-label="返回"
|
||||
>
|
||||
<span className="material-symbols-outlined">arrow_back</span>
|
||||
</button>
|
||||
) : (
|
||||
<span className="shop-subpage-header-spacer" />
|
||||
)}
|
||||
<h1 className="app-page-title">切换门店</h1>
|
||||
<span className="shop-subpage-header-spacer" />
|
||||
</header>
|
||||
{msg ? <p className="shop-select-store-msg">{msg}</p> : null}
|
||||
<ul className="shop-select-store-list">
|
||||
{stores.map((item) => (
|
||||
<li key={item.storeId}>
|
||||
<button
|
||||
type="button"
|
||||
className="shop-select-store-item"
|
||||
disabled={loading}
|
||||
onClick={() => void onSelect(item.storeId)}
|
||||
>
|
||||
<span className="shop-select-store-name">{item.name}</span>
|
||||
<span className="shop-select-store-meta">
|
||||
{[item.district, item.address].filter(Boolean).join(' · ') || item.status}
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{!stores.length && !msg ? <p className="shop-select-store-empty">暂无绑定门店</p> : null}
|
||||
|
||||
<div className="shop-subpage-content">
|
||||
<section className="shop-subpage-hero">
|
||||
<div className="shop-subpage-hero-icon">
|
||||
<span className="material-symbols-outlined shop-fill-icon">store</span>
|
||||
</div>
|
||||
<div>
|
||||
<h2 className="shop-subpage-hero-title">选择要进入的门店</h2>
|
||||
<p className="shop-subpage-hero-desc">
|
||||
该账号绑定了 {stores.length || '多'} 家门店,进入后可直接核销与查看营业数据
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{msg ? (
|
||||
<p className="shop-subpage-msg" role="alert">
|
||||
{msg}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<section>
|
||||
<h3 className="shop-subpage-section-title">我的门店</h3>
|
||||
<ul className="shop-select-store-list">
|
||||
{stores.map((item) => {
|
||||
const active = item.storeId === currentStoreId;
|
||||
const busy = loadingId === item.storeId;
|
||||
return (
|
||||
<li key={item.storeId}>
|
||||
<button
|
||||
type="button"
|
||||
className={`shop-select-store-item${active ? ' is-active' : ''}`}
|
||||
disabled={Boolean(loadingId)}
|
||||
onClick={() => void onSelect(item.storeId)}
|
||||
>
|
||||
<div className="shop-select-store-item-icon">
|
||||
<span className="material-symbols-outlined shop-fill-icon">storefront</span>
|
||||
</div>
|
||||
<div className="shop-select-store-item-body">
|
||||
<div className="shop-select-store-item-top">
|
||||
<span className="shop-select-store-name">{item.name}</span>
|
||||
{active ? (
|
||||
<span className="shop-select-store-badge">当前</span>
|
||||
) : (
|
||||
<span className="shop-select-store-status">{statusLabel(item.status)}</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="shop-select-store-meta">
|
||||
{[item.district, item.address].filter(Boolean).join(' · ') ||
|
||||
statusLabel(item.status)}
|
||||
</span>
|
||||
</div>
|
||||
<span className="shop-select-store-item-action">
|
||||
{busy ? (
|
||||
'进入中…'
|
||||
) : (
|
||||
<span className="material-symbols-outlined">chevron_right</span>
|
||||
)}
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
{!stores.length && !msg ? (
|
||||
<div className="shop-subpage-empty">
|
||||
<span className="material-symbols-outlined">store</span>
|
||||
<p>暂无绑定门店</p>
|
||||
</div>
|
||||
) : null}
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user