fix: 添加默认床位生成逻辑并优化床位添加验证

This commit is contained in:
xyx
2026-07-13 16:11:53 +08:00
parent acb11b87a3
commit ceb0e2bf14
2 changed files with 42 additions and 9 deletions

View File

@@ -156,6 +156,11 @@ const RoomsPage: React.FC = () => {
if (filterStatus) result = result.filter((r: Record<string, unknown>) => r.status === filterStatus);
return result;
}, [data, searchText, filterBuilding, filterStatus]);
const remainingBedSlots = useMemo(() => {
const capacity = Number(drawerRoom?.capacity) || 0;
return Math.max(capacity - beds.length, 0);
}, [drawerRoom?.capacity, beds.length]);
const defaultBatchBedCount = Math.min(4, Math.max(remainingBedSlots, 1));
const handleSave = async () => {
const values = await form.validateFields();
@@ -167,7 +172,7 @@ const RoomsPage: React.FC = () => {
message.success('更新成功');
} else {
await api.post('/rooms', payload);
message.success('创建成功');
message.success(`创建成功,已自动生成 ${values.capacity} 张床位`);
}
setModalOpen(false);
form.resetFields();
@@ -634,24 +639,26 @@ const RoomsPage: React.FC = () => {
type="primary"
size="small"
icon={<PlusOutlined />}
disabled={drawerRoom?.status === 'archived'}
disabled={drawerRoom?.status === 'archived' || remainingBedSlots === 0}
onClick={() => { setBedEditing(null); bedForm.resetFields(); setBedModalOpen(true); }}
>
</Button>
<Popconfirm
title="批量生成床位"
title={remainingBedSlots > 0 ? '批量生成床位' : '床位已达到额定人数'}
description={
<InputNumber min={1} max={20} defaultValue={4} id="batch-bed-count" style={{ width: 80 }} />
remainingBedSlots > 0
? <InputNumber min={1} max={remainingBedSlots} defaultValue={defaultBatchBedCount} id="batch-bed-count" style={{ width: 80 }} />
: '如需增加床位,请先调整宿舍额定人数'
}
onConfirm={() => {
const input = document.getElementById('batch-bed-count') as HTMLInputElement;
handleBatchBeds(input ? parseInt(input.value) || 4 : 4);
handleBatchBeds(input ? parseInt(input.value) || defaultBatchBedCount : defaultBatchBedCount);
}}
okText="生成"
disabled={drawerRoom?.status === 'archived'}
disabled={drawerRoom?.status === 'archived' || remainingBedSlots === 0}
>
<Button size="small" disabled={drawerRoom?.status === 'archived'}></Button>
<Button size="small" disabled={drawerRoom?.status === 'archived' || remainingBedSlots === 0}></Button>
</Popconfirm>
</div>
<Table