diff --git a/apps/admin/src/pages/RoomVisual/index.tsx b/apps/admin/src/pages/RoomVisual/index.tsx
index feb8849..4844bb1 100644
--- a/apps/admin/src/pages/RoomVisual/index.tsx
+++ b/apps/admin/src/pages/RoomVisual/index.tsx
@@ -86,11 +86,9 @@ const RoomVisualPage: React.FC = () => {
const emptyRooms = rooms.filter(
(r: any) => r.currentCount === 0 && r.status !== 'maintenance',
).length;
- const availableBeds = rooms.reduce(
- (sum: number, r: any) =>
- r.status !== 'maintenance' ? sum + (r.capacity - r.currentCount) : sum,
- 0,
- );
+ const totalBeds = rooms.reduce((sum: number, r: any) => sum + (r.totalBeds || 0), 0);
+ const occupiedBeds = rooms.reduce((sum: number, r: any) => sum + (r.occupiedBeds || 0), 0);
+ const availableBedsCount = totalBeds - occupiedBeds;
const fullRooms = rooms.filter((r: any) => r.currentCount >= r.capacity).length;
/* getCardStyle, getStatusLabel, getTenantTags are now standalone functions outside the component */
@@ -180,7 +178,7 @@ const RoomVisualPage: React.FC = () => {
-
+
@@ -230,6 +228,11 @@ const RoomVisualPage: React.FC = () => {
{room.building && {room.building} }
{room.floor && {room.floor}F}
+ {room.totalBeds > 0 && (
+ = room.totalBeds ? '#FF3B30' : '#34C759', marginBottom: 6 }}>
+ 床位: {room.occupiedBeds}/{room.totalBeds}
+
+ )}
r.status !== 'archived' || (occMap.get(r.id)?.length ?? 0) > 0)
: rooms;
+ // 批量获取床位统计
+ const allBeds = await this.bedRepo.find({
+ where: { roomId: In(visibleRooms.map((r) => r.id)) },
+ });
+ const bedMap = new Map();
+ for (const bed of allBeds) {
+ if (!bedMap.has(bed.roomId)) bedMap.set(bed.roomId, { total: 0, occupied: 0 });
+ const entry = bedMap.get(bed.roomId)!;
+ entry.total++;
+ if (bed.status === 'occupied') entry.occupied++;
+ }
+
return {
buildings,
rooms: visibleRooms.map((room) => {
const occ = occMap.get(room.id) || [];
- // 计算机构标注
const orgs = [...new Set(occ.map((o: any) => o.organization).filter(Boolean))];
let orgLabel: string | null = null;
if (orgs.length > 0 && occ.length > 0) {
const allSameOrg = occ.every((o: any) => o.organization && o.organization === orgs[0]);
- if (allSameOrg) {
- orgLabel = `均为${orgs[0]}人员`;
- } else {
- orgLabel = `存在${orgs.join('、')}人员`;
- }
+ orgLabel = allSameOrg ? `均为${orgs[0]}人员` : `存在${orgs.join('、')}人员`;
}
- // 计算租户颜色:所有住户同一租户则使用该颜色
const tenantColors = [...new Set(occ.map((o: any) => o.tenantColor).filter(Boolean))];
const tenantColor: string | null = tenantColors.length === 1 ? tenantColors[0] : null;
- // 房间涉及的租户 id(供前端按租赁方筛选)
const tenantIds = [...new Set(occ.map((o: any) => o.tenantId).filter(Boolean))];
return {
id: room.id,
@@ -263,6 +268,8 @@ export class RoomsService {
capacity: room.capacity,
status: room.status,
currentCount: occ.length,
+ totalBeds: bedMap.get(room.id)?.total ?? 0,
+ occupiedBeds: bedMap.get(room.id)?.occupied ?? 0,
occupants: occ,
orgLabel,
tenantColor,