forked from wangziqi/gongxue-base
fix: 添加默认床位生成逻辑并优化床位添加验证
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user