房屋管理功能完成,接下来储藏室

This commit is contained in:
Zy
2026-04-09 12:40:17 +08:00
parent 6e998d4e87
commit 267a9a5f29
19 changed files with 1569 additions and 451 deletions

View File

@@ -1,6 +1,6 @@
import { getCommunitylistAPI } from '@/api/system/community';
import { communitylist_rows_type } from '@/api/system/community/type';
import { getBuildinglistAPI, getHouselistAPI } from '@/api/system/house';
import { deleteHouseApi, getBuildinglistAPI, getHouselistAPI } from '@/api/system/house';
import type { addBuildingType, BuildingUnit, BuildingVo } from '@/api/system/house/type';
import { defineStore } from 'pinia';
// 数字排序
@@ -16,89 +16,20 @@ function sortNumberStr(a: string, b: string) {
// 否则按自然语言排
return a.localeCompare(b, 'zh-CN', { numeric: true });
}
export const useHouseStore = defineStore('house', () => {
// 当前小区信息
const currentVilageInfo = ref<communitylist_rows_type>();
export const useHouseStore = defineStore(
'house',
() => {
// 当前小区信息
const currentVilageInfo = ref<communitylist_rows_type>();
// 住宅类型
const buildingtype = ref<number>(0);
// 住宅列表
const buildingtypelist = ref([]);
const buildingtype = ref<number>(0);
// 当前小区 所有楼栋信息
const currentBuildingInfoList = ref<BuildingVo[]>([]);
// 当前楼栋信息
const currentBuildingInfo = ref<BuildingVo>({
'id': null,
'villageId': null,
'villageName': '',
'buildingName': '',
'buildingUse': null,
'buildToward': '',
'buildTall': '',
'buildStructure': '',
'unitCount': null,
'floorCount': null,
'remark': ''
});
// 当前楼栋 所有房屋信息
const currentHouseInfoList = ref<BuildingUnit>();
// 当前楼栋 所有楼层数据
const currentFloorInfoList = computed(() => {
return (Array.from(floorslist.value) as string[]).sort(sortNumberStr);
});
// 楼层列表 set
const floorslist = ref<Set<string>>(new Set());
// 初始化
const initHouse = async (buildingtype: number) => {
// 查找当前小区
const res = await getCommunitylistAPI();
const currentVilage = res.rows.find((item) => item.choiceStatus === 0);
currentVilageInfo.value = currentVilage;
// 获取当前小区 所有楼栋信息
const res2 = await getBuildinglistAPI(currentVilage.villageId, buildingtype);
currentBuildingInfoList.value = res2.data;
if (!currentBuildingInfo.value) {
// 获取当前小区 第一个楼栋信息
currentBuildingInfo.value = res2.data[0];
console.log(currentBuildingInfo.value);
}
// 获取当前 第一个楼栋的所有信息
const res3 = await getHouselistAPI(currentBuildingInfo.value.id);
currentHouseInfoList.value = res3.data;
console.log(currentHouseInfoList.value);
floorslist.value = new Set();
// 得到所有的有房屋的 楼层 数组
currentHouseInfoList.value.units.forEach((item) => {
item.floors.forEach((floor) => {
floorslist.value.add(floor.floorNo);
});
});
};
// 选中的房屋
const checkoutHouses = ref<string[]>([]);
// 选中的房屋方法
const checkoutHousesFun = (data: string[]) => {
checkoutHouses.value = data;
};
// 切换住宅类型
const switchHouseType = (housetype: number) => {
getBuildinglistAPI(currentVilageInfo.value.villageId, housetype)
.then(() => {
buildingtype.value = housetype;
initHouse(housetype);
ElMessage.success('切换成功');
})
.catch(() => ElMessage.error('切换失败'));
};
// 切换楼栋
const switchBuilding = (buildingId: number) => {
// 切换之前 清空当前楼栋信息
currentBuildingInfo.value = {
// 当前小区 所有楼栋信息
const currentBuildingInfoList = ref<BuildingVo[]>([]);
// 当前楼栋信息
const currentBuildingInfo = ref<BuildingVo>({
'id': null,
'villageId': null,
'villageName': '',
@@ -110,67 +41,139 @@ export const useHouseStore = defineStore('house', () => {
'unitCount': null,
'floorCount': null,
'remark': ''
};
getHouselistAPI(buildingId).then((res) => {
currentHouseInfoList.value = res.data;
// 获取当前楼栋信息并 赋值
currentBuildingInfo.value = currentBuildingInfoList.value.find((item) => item.id === buildingId);
});
// 清空 楼层信息
// 当前楼栋 所有房屋信息
const currentHouseInfoList = ref<BuildingUnit>(null);
// 当前楼栋 所有楼层数据
const currentFloorInfoList = computed(() => {
return (Array.from(floorslist.value) as string[]).sort(sortNumberStr);
});
// 楼层列表 set
const floorslist = ref<Set<string>>(new Set());
// 初始化
const initHouse = async (buildingtype: number) => {
// 查找当前小区
const res = await getCommunitylistAPI();
const currentVilage = res.rows.find((item) => item.choiceStatus === 0);
currentVilageInfo.value = currentVilage;
// 获取当前小区 所有楼栋信息
const res2 = await getBuildinglistAPI(currentVilage.villageId, buildingtype);
currentBuildingInfoList.value = res2.data;
// 获取当前小区 第一个楼栋信息
if (currentBuildingInfo.value.id === null) {
currentBuildingInfo.value = res2.data[0];
} else {
// 更新当前楼栋的 信息
currentBuildingInfo.value = res2.data.find((item) => item.id === currentBuildingInfo.value.id);
}
// 获取当前 第一个楼栋的所有信息
const res3 = await getHouselistAPI(currentBuildingInfo.value.id);
currentHouseInfoList.value = res3.data;
floorslist.value = new Set();
// 重新获取楼层信息
// 得到所有的有房屋的 楼层 数组
currentHouseInfoList.value.units.forEach((item) => {
item.floors.forEach((floor) => {
floorslist.value.add(floor.floorNo);
});
});
ElMessage.success('切换成功');
return;
});
};
};
// 更新数据
const updateHouse = () => {
initHouse(buildingtype.value);
};
// 删除指定楼栋
const deleteBuildingFun = (buildingId: number) => {
console.log('删除楼栋');
// 手动 从 楼栋列表中删除 指定楼栋
currentBuildingInfoList.value = currentBuildingInfoList.value.filter((item) => item.id !== buildingId);
// 判断指定楼栋是 当前楼栋
if (currentBuildingInfo.value.id === buildingId) {
// 获取楼栋列表中的第一个楼栋,并切换到第一个楼栋
if (currentBuildingInfoList.value[0]) {
currentBuildingInfo.value = currentBuildingInfoList.value[0];
switchBuilding(currentBuildingInfo.value.id);
// 选中的房屋
const checkoutHouses = ref<string[]>([]);
// 选中的房屋方法
const checkoutHousesFun = (data: string[]) => {
checkoutHouses.value = data;
};
// 切换住宅类型
const switchHouseType = (housetype: number) => {
getBuildinglistAPI(currentVilageInfo.value.villageId, housetype)
.then(() => {
buildingtype.value = housetype;
initHouse(housetype);
ElMessage.success('切换成功');
})
.catch(() => ElMessage.error('切换失败'));
};
// 切换楼栋
const switchBuilding = (buildingId: string) => {
// 切换之前 清空当前楼栋信息
currentBuildingInfo.value = {
'id': null,
'villageId': null,
'villageName': '',
'buildingName': '',
'buildingUse': null,
'buildToward': '',
'buildTall': '',
'buildStructure': '',
'unitCount': null,
'floorCount': null,
'remark': ''
};
currentHouseInfoList.value = null;
getHouselistAPI(buildingId).then((res) => {
currentHouseInfoList.value = res.data;
console.log(currentHouseInfoList.value);
// 获取当前楼栋信息并 赋值
currentBuildingInfo.value = currentBuildingInfoList.value.find((item) => item.id === buildingId);
// 清空 楼层信息
floorslist.value = new Set();
// 重新获取楼层信息
currentHouseInfoList.value.units.forEach((item) => {
item.floors.forEach((floor) => {
floorslist.value.add(floor.floorNo);
});
});
return;
});
};
// 更新数据
const updateHouse = () => {
initHouse(buildingtype.value);
};
// 删除指定楼栋
const deleteBuildingFun = (buildingId: string) => {
console.log('删除楼栋');
// 手动 从 楼栋列表中删除 指定楼栋
currentBuildingInfoList.value = currentBuildingInfoList.value.filter((item) => item.id !== buildingId);
// 判断指定楼栋是 当前楼栋
if (currentBuildingInfo.value.id === buildingId) {
// 获取楼栋列表中的第一个楼栋,并切换到第一个楼栋
if (currentBuildingInfoList.value[0]) {
currentBuildingInfo.value = currentBuildingInfoList.value[0];
switchBuilding(currentBuildingInfo.value.id);
}
}
}
};
// 删除指定房屋
const deleteHouseFun = (houseId: string | string[]) => {
console.log('删除房屋');
if (typeof houseId === 'string') {
console.log('单条删除');
} else if (Array.isArray(houseId)) {
console.log('批量删除');
}
};
};
return {
currentVilageInfo,
currentBuildingInfoList,
currentBuildingInfo,
currentHouseInfoList,
currentFloorInfoList,
checkoutHouses,
buildingtype,
checkoutHousesFun,
initHouse,
switchHouseType,
switchBuilding,
deleteHouseFun,
updateHouse,
deleteBuildingFun
};
});
return {
currentVilageInfo,
currentBuildingInfoList,
currentBuildingInfo,
currentHouseInfoList,
currentFloorInfoList,
checkoutHouses,
buildingtype,
buildingtypelist,
checkoutHousesFun,
initHouse,
switchHouseType,
switchBuilding,
updateHouse,
deleteBuildingFun
};
},
{
persist: {
storage: sessionStorage
}
}
);