import { useState } from 'react' import { useQuery } from '@tanstack/react-query' import api from '@/lib/api' import { CollapsibleSection } from '@/components/CollapsibleSection' import { FilterableTable } from '@/components/FilterableTable' import { LoadingSpinner } from '@/components/LoadingSpinner' import { MetricCard } from '@/components/MetricCard' import { formatCurrency, formatPercent, formatNumber } from '@/lib/utils' const PAGE_SIZE = 20 const EVAL_COLORS: Record = { '关停评估': 'bg-red-100 text-red-700', '关停或迁址评估': 'bg-red-100 text-red-700', '改造评估': 'bg-orange-100 text-orange-700', '续租评估': 'bg-yellow-100 text-yellow-700', '关注观察': 'bg-blue-100 text-blue-700', '正常经营': 'bg-green-100 text-green-700', } const PRIORITY_COLORS: Record = { 'P0': 'text-red-600 font-medium', 'P1': 'text-orange-600 font-medium', 'P2': 'text-yellow-600', 'P3': 'text-blue-600', 'P4': 'text-green-600', } interface EvalStoreDetail { sales_store_name: string received: string actual_food_cost: string operating_expense: string actual_store_contribution: string actual_store_contribution_rate_pct: string wage_rate_pct: string rent_rate_pct: string received_per_sqm: string area_sqm: string lease_expiry_date: string theoretical_store_contribution: string evaluation_type: string evaluation_detail: string evaluation_suggestion: string priority: string } function EvalDetailModal({ store, onClose }: { store: EvalStoreDetail | null, onClose: () => void }) { if (!store) return null const metrics = [ { label: '实收', value: formatCurrency(store.received) }, { label: '食材成本', value: formatCurrency(store.actual_food_cost) }, { label: '营业费用', value: formatCurrency(store.operating_expense) }, { label: '贡献利润', value: formatCurrency(store.actual_store_contribution), red: parseFloat(store.actual_store_contribution) < 0 }, { label: '贡献率', value: formatPercent(store.actual_store_contribution_rate_pct), red: parseFloat(store.actual_store_contribution_rate_pct) < 0 }, { label: '理论贡献', value: formatCurrency(store.theoretical_store_contribution) }, { label: '人工成本率', value: formatPercent(store.wage_rate_pct), warn: parseFloat(store.wage_rate_pct) > 30 }, { label: '租金率', value: formatPercent(store.rent_rate_pct), warn: parseFloat(store.rent_rate_pct) > 20 }, { label: '坪效', value: formatNumber(store.received_per_sqm), warn: parseFloat(store.received_per_sqm) < 1000 }, { label: '面积(㎡)', value: formatNumber(store.area_sqm) }, { label: '租约到期', value: store.lease_expiry_date ? String(store.lease_expiry_date).substring(0, 10) : '-' }, ] return (
e.stopPropagation()}>

{store.sales_store_name}

{store.evaluation_type} {store.priority}

关键指标

{metrics.map((m, i) => (

{m.label}

{m.value}

))}

评估详情

{store.evaluation_detail}

建议

{store.evaluation_suggestion}

) } export function StoreEvaluationTab({ month }: { month: string }) { const [page, setPage] = useState(1) const [sort, setSort] = useState('actual_store_contribution_rate_pct') const [filter, setFilter] = useState('') const [order, setOrder] = useState<'asc' | 'desc'>('asc') const [selectedStore, setSelectedStore] = useState(null) const { data, isLoading } = useQuery({ queryKey: ['se/evaluation', month, page, sort, filter, order], queryFn: () => api.get(`/store-expense/store-evaluation?page=${page}&page_size=${PAGE_SIZE}&sort=${sort}&filter=${filter}&order=${order}&month=${month}`) }) if (isLoading) return const rows = (data as any)?.data || [] const meta = (data as any)?.meta || { page, pageSize: PAGE_SIZE, total: 0 } const evalStats = (data as any)?.meta?.evalStats || {} return (
setSelectedStore(r as EvalStoreDetail)} columns={[ { key: 'sales_store_name', label: '门店', render: (r) => }, { key: 'priority', label: '优先级', render: (r) => {r.priority} }, { key: 'evaluation_type', label: '评估类型', render: (r) => {r.evaluation_type} }, { key: 'received', label: '实收', align: 'right', render: (r) => formatCurrency(r.received) }, { key: 'actual_store_contribution', label: '贡献利润', align: 'right', render: (r) => {formatCurrency(r.actual_store_contribution)} }, { key: 'actual_store_contribution_rate_pct', label: '贡献率', align: 'right', render: (r) => formatPercent(r.actual_store_contribution_rate_pct) }, { key: 'received_per_sqm', label: '坪效', align: 'right', render: (r) => formatNumber(r.received_per_sqm) }, { key: 'lease_expiry_date', label: '租约到期', render: (r) => r.lease_expiry_date ? String(r.lease_expiry_date).substring(0, 10) : '-' }, { key: 'evaluation_detail', label: '评估详情', render: (r) => {r.evaluation_detail} }, ]} /> setSelectedStore(null)} />
) }