// 统计页面模块 const StatsPage = { // 初始化 init() { this.loadStats(); }, // 加载统计数据 async loadStats() { try { const [dishesRes, ordersRes] = await Promise.all([ fetch(`${API_BASE}/dishes/`), fetch(`${API_BASE}/orders/`) ]); const allDishes = await dishesRes.json(); const allOrders = await ordersRes.json(); // 计算菜品出现次数 const dishCompletedCounts = {}; allOrders .filter(o => o.status === 'completed') .forEach(order => { (order.dishes_detail || []).forEach(dish => { dishCompletedCounts[dish.id] = (dishCompletedCounts[dish.id] || 0) + 1; }); }); AppState.setDishCompletedCounts(dishCompletedCounts); // 统计数据 const totalDishes = allDishes.length; const completedOrders = allOrders.filter(o => o.status === 'completed').length; const inProgressOrders = allOrders.filter(o => o.status === 'in_progress').length; // 统计参与人员 const participantCounts = {}; allOrders.forEach(order => { (order.participants || []).forEach(p => { participantCounts[p] = (participantCounts[p] || 0) + 1; }); }); const uniqueParticipants = Object.keys(participantCounts).length; // 渲染统计卡片 this.renderStatCards({ totalDishes, completedOrders, inProgressOrders, uniqueParticipants }); // 渲染菜品排行榜 this.renderDishRank(allDishes, dishCompletedCounts); } catch (e) { console.error('加载统计失败:', e); } }, // 渲染统计卡片 renderStatCards(stats) { const container = document.getElementById('stats-cards'); if (!container) return; container.innerHTML = `
暂无数据