+
自动添加床位
添加床位
已达到床位上限 ({{ bedList.length }}/{{ bedManageDialog.maxBeds }})
@@ -205,12 +213,12 @@
import { ref, computed, reactive, onMounted, nextTick, watch } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { InfoFilled, Search } from '@element-plus/icons-vue';
-import { DormTreeNode, BedInfo, DormQuery } from '@/api/xgss/xsssfjgl/types';
+import { DormTreeNode, BedInfo, DormQuery, BedForm } from '@/api/xgss/xsssfjgl/types';
import { DormRoomVO, DormRoomQuery } from '@/api/xgss/dormRoom/types';
import { getDormTree } from '@/api/xgss/xsssfjgl';
-import { listDormBed, delDormBed } from '@/api/xgss/dormBed';
+import { listDormBed, delDormBed, addDormBed } from '@/api/xgss/dormBed';
import type { DormBedQuery } from '@/api/xgss/dormBed/types';
-import { listDormRoom, delDormRoom } from '@/api/xgss/dormRoom';
+import { listDormRoom, delDormRoom, addDormRoom } from '@/api/xgss/dormRoom';
// 引入子组件
import RoomDialog from './components/RoomDialog.vue';
@@ -247,7 +255,7 @@ const floorList = computed(() => {
// 查询参数
const queryParams = reactive
({
pageNum: 1,
- pageSize: 100,
+ pageSize: 10000,
buildingId: undefined,
roomName: '',
roomStatus: undefined
@@ -389,6 +397,87 @@ const resetQuery = () => {
handleQuery();
};
+/** 批量自动添加房间 */
+const handleAddAllRoom = (floor: number) => {
+ if (!selectedBuilding.value) return;
+
+ // 使用Element Plus的对话框提示用户输入寝室数量
+ ElMessageBox.prompt('请输入要添加的寝室数量', '批量添加房间', {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ inputPattern: /^[1-9]\d*$/,
+ inputErrorMessage: '请输入正整数',
+ inputValue: '10' // 默认值
+ })
+ .then(async ({ value }) => {
+ const roomCount = parseInt(value);
+
+ try {
+ // 先获取当前楼层的房间列表,确定起始房间号
+ const floorRooms = getRoomsByFloor(floor);
+ let startRoomNumber = 1;
+
+ // 如果已有房间,确定起始编号(避免房间号重复)
+ if (floorRooms.length > 0) {
+ // 提取现有房间号中的数字部分
+ const existingRoomNumbers = floorRooms
+ .map((room) => {
+ // 假设房间名称格式为:楼层+编号,如"3201"
+ const match = room.roomName.match(/\d+$/);
+ return match ? parseInt(match[0].substring(floor.toString().length), 10) : 0;
+ })
+ .filter((num) => !isNaN(num));
+
+ // 找出最大编号并加1作为起始编号
+ if (existingRoomNumbers.length > 0) {
+ startRoomNumber = Math.max(...existingRoomNumbers) + 1;
+ }
+ }
+
+ // 显示加载提示
+ ElMessage.info(`正在添加 ${roomCount} 个房间,请稍候...`);
+
+ // 批量添加房间
+ for (let i = 0; i < roomCount; i++) {
+ const roomNumber = startRoomNumber + i;
+ // 房间号格式:楼栋首字符+楼层+编号(如A栋2层1号房间为A201)
+ // 补零确保房间号长度一致
+ const paddedRoomNumber = roomNumber.toString().padStart(2, '0');
+ const buildingFirstChar = selectedBuilding.value.label.charAt(0);
+ const roomCode = `${buildingFirstChar}${floor}${paddedRoomNumber}`;
+
+ const roomData = {
+ buildingId: selectedBuilding.value.id,
+ floorNum: floor,
+ roomCode: `${roomCode}`,
+ roomName: `${roomCode}`,
+ roomType: '1', // 1: 标准间
+ actualBeds: 6, // 默认6个床位
+ roomArea: 0, // 默认面积为0
+ roomStatus: '0' // 0: 正常
+ };
+
+ // 调用添加房间API
+ await addDormRoom(roomData);
+
+ // 添加延迟避免请求过快
+ await new Promise((resolve) => setTimeout(resolve, 300));
+ }
+
+ ElMessage.success(`成功添加 ${roomCount} 个房间`);
+ // 重新加载房间数据
+ loadRoomData();
+ } catch (error) {
+ console.error('批量添加房间失败', error);
+ ElMessage.error('添加房间失败,请重试');
+ }
+ })
+ .catch(() => {
+ // 用户取消操作
+ ElMessage.info('已取消添加房间');
+ });
+};
+
/** 添加房间 */
const handleAddRoom = (floor: number) => {
if (!selectedBuilding.value) return;
@@ -528,6 +617,103 @@ const handleSaveBeds = async () => {
}
};
+/** 自动添加床位 */
+const handleAddALlBed = async () => {
+ // 计算需要添加的床位数量
+ const maxBeds = bedManageDialog.maxBeds;
+ const currentBeds = bedList.value.length;
+
+ if (currentBeds >= maxBeds) {
+ ElMessage.warning(`已达到床位上限 (${currentBeds}/${maxBeds})`);
+ return;
+ }
+
+ // 计算要添加的床位数量,床位按成对添加(上铺和下铺)
+ const needToAdd = maxBeds - currentBeds;
+ const pairCount = Math.ceil(needToAdd / 2); // 需要添加的床位对数
+
+ try {
+ bedLoading.value = true;
+
+ // 计算起始编号(基于已有床位计算)
+ let startIndex = 1;
+ if (bedList.value.length > 0) {
+ // 尝试从现有床位编号中提取最大数字
+ const existingNumbers = bedList.value
+ .map((bed) => {
+ // 假设bedName中包含数字,如"1上"中的1
+ const match = bed.bedName.match(/^(\d+)/);
+ return match ? parseInt(match[1], 10) : 0;
+ })
+ .filter((num) => !isNaN(num));
+
+ if (existingNumbers.length > 0) {
+ startIndex = Math.max(...existingNumbers) + 1;
+ }
+ }
+
+ // 添加床位计数
+ let addedCount = 0;
+
+ // 创建延迟函数
+ const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
+
+ for (let i = 0; i < pairCount; i++) {
+ const bedIndex = startIndex + i;
+
+ // 如果当前床位数 + 已添加的床位数 < 最大床位数,则添加上铺
+ if (currentBeds + addedCount < maxBeds) {
+ // 使用API需要的格式
+ const upperBed = {
+ id: '', // 新增时为空
+ bedCode: `${addedCount + 1}`,
+ bedName: `${addedCount + 1}`,
+ roomId: bedManageDialog.roomId,
+ bedStatus: '0', // 空闲
+ bedType: '2', // 上铺
+ remark: ''
+ };
+ await addDormBed(upperBed);
+ addedCount++;
+
+ // 添加0.5秒延迟
+ await delay(100);
+ }
+
+ // 如果当前床位数 + 已添加的床位数 < 最大床位数,则添加下铺
+ if (currentBeds + addedCount < maxBeds) {
+ // 使用API需要的格式
+ const lowerBed = {
+ id: '', // 新增时为空
+ bedCode: `${addedCount + 1}`,
+ bedName: `${addedCount + 1}`,
+ roomId: bedManageDialog.roomId,
+ bedStatus: '0', // 空闲
+ bedType: '1', // 下铺
+ remark: ''
+ };
+ await addDormBed(lowerBed);
+ addedCount++;
+ }
+ }
+
+ if (addedCount > 0) {
+ ElMessage.success(`成功添加 ${addedCount} 个床位`);
+ // 重新加载床位数据
+ await loadBedData(bedManageDialog.roomId);
+ // 更新房间的当前床位数
+ if (selectedBuilding.value) {
+ loadRoomData();
+ }
+ }
+ } catch (error) {
+ console.error('批量添加床位失败', error);
+ ElMessage.error('添加床位失败,请重试');
+ } finally {
+ bedLoading.value = false;
+ }
+};
+
onMounted(() => {
getDormTreeData();
});
diff --git a/web/src/views/xgss/xsssfpejxy/index.vue b/web/src/views/xgss/xsssfpejxy/index.vue
index 1d30b518..9da45cef 100644
--- a/web/src/views/xgss/xsssfpejxy/index.vue
+++ b/web/src/views/xgss/xsssfpejxy/index.vue
@@ -129,7 +129,13 @@
- {{ selectedBuilding?.label }} - 房间管理
+ {{ selectedBuilding?.label }}
+
+ {{ selectedBuilding?.buildingType === '1' ? '(男生楼)' : '(女生楼)' }}
+
+ - 房间管理
已选择: {{ selectedRoomCount }}个房间 / {{ selectedBedCount }}个床位