diff --git a/src/api/system/house/index.ts b/src/api/system/house/index.ts index fb4f578..ed883a6 100644 --- a/src/api/system/house/index.ts +++ b/src/api/system/house/index.ts @@ -1,6 +1,7 @@ import request from '@/utils/request'; import { AxiosPromise } from 'axios'; import { addBuildingType, BuildingUnit, BuildingVo } from './type'; +import { number } from 'vue-types'; // 楼栋--------------------------------------------------------------------------------------- // 根据 小区id 和 类型 查询楼栋信息 @@ -23,10 +24,25 @@ export function addBuildingApi(data: addBuildingType) { data }); } +/** 编辑楼栋 */ +export function editBuildingApi(data: addBuildingType & { id: number }) { + return request({ + url: '/building', + method: 'PUT', + data + }); +} +/** 删除楼栋 */ +export function deleteBuildingApi(id: number) { + return request({ + url: `/building/${id}`, + method: 'DELETE' + }); +} // 房屋---------------------------------------------------------------------------------------------- // 根据 楼栋id 查询房屋信息 -export function getHouselistAPI(buildingId: number): AxiosPromise { +export function getHouselistAPI(buildingId: number): AxiosPromise { return request({ url: `/house/groupByUnitTree/${buildingId}`, method: 'get' diff --git a/src/api/system/house/type.ts b/src/api/system/house/type.ts index 3d66078..913ad26 100644 --- a/src/api/system/house/type.ts +++ b/src/api/system/house/type.ts @@ -42,16 +42,16 @@ export interface BuildingVo { villageName?: string; } -// 楼栋 +// 楼栋总信息 export interface BuildingUnit { - actualFloorCount: number; - buildingFloorCount: number; buildingId: number; buildingName: string; - totalHouses: number; - unitNo: string; - floors: string; - floors_Json?: FloorsType[]; + units: BuildingUnitlist[]; +} +// 单元 +export interface BuildingUnitlist { + floors: FloorsType[]; + unitNo: number; } // 楼层 export interface FloorsType { diff --git a/src/components/Pageheader/index.vue b/src/components/Pageheader/index.vue index 48c29ad..f7aa71f 100644 --- a/src/components/Pageheader/index.vue +++ b/src/components/Pageheader/index.vue @@ -9,12 +9,12 @@
{{ props.title }}
- -
+ +
- +
@@ -23,7 +23,10 @@ import Breadcrumb from '@/components/Breadcrumb/index.vue'; const slots = useSlots(); const showSlot = computed(() => { - return slots.content && slots.content().length > 0; + return { + content: slots.content ?? null, + operate: slots.operate ?? null + }; }); const props = defineProps({ diff --git a/src/store/modules/house.ts b/src/store/modules/house.ts index 8b1fa6a..57b45fa 100644 --- a/src/store/modules/house.ts +++ b/src/store/modules/house.ts @@ -1,7 +1,7 @@ import { getCommunitylistAPI } from '@/api/system/community'; import { communitylist_rows_type } from '@/api/system/community/type'; import { getBuildinglistAPI, getHouselistAPI } from '@/api/system/house'; -import { BuildingUnit, BuildingVo } from '@/api/system/house/type'; +import type { addBuildingType, BuildingUnit, BuildingVo } from '@/api/system/house/type'; import { defineStore } from 'pinia'; // 数字排序 function sortNumberStr(a: string, b: string) { @@ -20,6 +20,8 @@ export const useHouseStore = defineStore('house', () => { // 当前小区信息 const currentVilageInfo = ref(); + const buildingtype = ref(0); + // 当前小区 所有楼栋信息 const currentBuildingInfoList = ref([]); // 当前楼栋信息 @@ -38,14 +40,15 @@ export const useHouseStore = defineStore('house', () => { }); // 当前楼栋 所有房屋信息 - const currentHouseInfoList = ref([]); + const currentHouseInfoList = ref(); // 当前楼栋 所有楼层数据 - const currentFloorInfoList = ref([]); - // 最大楼层 - const maxFloors = ref(0); + const currentFloorInfoList = computed(() => { + return (Array.from(floorslist.value) as string[]).sort(sortNumberStr); + }); // 楼层列表 set const floorslist = ref>(new Set()); + // 初始化 const initHouse = async (buildingtype: number) => { // 查找当前小区 @@ -55,42 +58,96 @@ export const useHouseStore = defineStore('house', () => { // 获取当前小区 所有楼栋信息 const res2 = await getBuildinglistAPI(currentVilage.villageId, buildingtype); currentBuildingInfoList.value = res2.data; - // 获取当前小区 楼栋信息 - currentBuildingInfo.value = res2.data[0]; - console.log(currentBuildingInfo.value); + if (!currentBuildingInfo.value) { + // 获取当前小区 第一个楼栋信息 + currentBuildingInfo.value = res2.data[0]; + console.log(currentBuildingInfo.value); + } - // 获取当前楼栋 所有房屋信息 + // 获取当前 第一个楼栋的所有信息 const res3 = await getHouselistAPI(currentBuildingInfo.value.id); currentHouseInfoList.value = res3.data; - currentHouseInfoList.value.forEach((item) => { - maxFloors.value = Math.max(maxFloors.value, item.actualFloorCount); - item.floors_Json = JSON.parse(`[${item.floors.replaceAll('\\', '')}]`); - item.floors_Json.forEach((floor) => { + console.log(currentHouseInfoList.value); + floorslist.value = new Set(); + // 得到所有的有房屋的 楼层 数组 + currentHouseInfoList.value.units.forEach((item) => { + item.floors.forEach((floor) => { floorslist.value.add(floor.floorNo); }); }); - // 对当前小区的 楼层进行排序 - currentFloorInfoList.value = (Array.from(floorslist.value) as string[]).sort(sortNumberStr); }; - // 选中房屋 + // 选中的房屋 const checkoutHouses = ref([]); + // 选中的房屋方法 const checkoutHousesFun = (data: string[]) => { checkoutHouses.value = data; }; // 切换住宅类型 - const switchHouseType = (housetype: 0 | 1 | 2 | 3) => { + const switchHouseType = (housetype: number) => { getBuildinglistAPI(currentVilageInfo.value.villageId, housetype) - .then(() => ElMessage.success('切换成功')) + .then(() => { + buildingtype.value = housetype; + initHouse(housetype); + ElMessage.success('切换成功'); + }) .catch(() => ElMessage.error('切换失败')); }; // 切换楼栋 const switchBuilding = (buildingId: number) => { - getHouselistAPI(buildingId).then(() => ElMessage.success('切换成功')); + // 切换之前 清空当前楼栋信息 + currentBuildingInfo.value = { + 'id': null, + 'villageId': null, + 'villageName': '', + 'buildingName': '', + 'buildingUse': null, + 'buildToward': '', + 'buildTall': '', + 'buildStructure': '', + 'unitCount': null, + 'floorCount': null, + 'remark': '' + }; + getHouselistAPI(buildingId).then((res) => { + currentHouseInfoList.value = res.data; + // 获取当前楼栋信息并 赋值 + 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); + }); + }); + 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 deleteHouseFun = (houseId: string | string[]) => { console.log('删除房屋'); if (typeof houseId === 'string') { @@ -107,10 +164,13 @@ export const useHouseStore = defineStore('house', () => { currentHouseInfoList, currentFloorInfoList, checkoutHouses, + buildingtype, checkoutHousesFun, initHouse, switchHouseType, switchBuilding, - deleteHouseFun + deleteHouseFun, + updateHouse, + deleteBuildingFun }; }); diff --git a/src/views/system/house/AddBuilding.vue b/src/views/system/house/AddBuilding.vue index 23b7221..62dfdfd 100644 --- a/src/views/system/house/AddBuilding.vue +++ b/src/views/system/house/AddBuilding.vue @@ -1,6 +1,10 @@