基础菜单页面搭建,开发房屋管理页面、设备页面

This commit is contained in:
zhouyanli
2026-10-20 08:09:10 +08:00
parent 0a2328d8e0
commit c2e2509c94
25 changed files with 1524 additions and 4163 deletions

View File

@@ -0,0 +1,289 @@
<template>
<div class="AddBuildingBox">
<PageHeader></PageHeader>
<div class="AddBuildingBody">
<div class="title">基本信息</div>
<div class="addBuildingFormBody">
<el-form class="formBody" label-position="left" ref="formRef" :model="form" :rules="rules" label-width="130px">
<el-row>
<el-col :span="11">
<el-form-item label="区号" prop="buildingId">
<el-cascader v-model="userHousePath" :options="treeData" @change="handleChange" />
</el-form-item>
</el-col>
<el-col :span="2"></el-col>
<el-col :span="11">
<el-form-item label="房间号" prop="houseNo">
<el-input maxlength="10" show-word-limit v-model.trim="form.houseNo" placeholder="请输入房号" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="11">
<el-form-item label="楼层" prop="floorNo">
<el-input-number v-model="form.floorNo" :min="1" :max="999" controls-position="right" placeholder="请输入楼层" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="11">
<el-form-item label="建筑面积(㎡)" prop="houseArea">
<el-input maxlength="10" v-model.trim="form.houseArea" placeholder="请输入建筑面积" />
</el-form-item>
</el-col>
<el-col :span="2"></el-col>
<el-col :span="11">
<el-form-item label="套内面积(㎡)" prop="internalArea">
<el-input maxlength="10" v-model.trim="form.internalArea" placeholder="请输入套内面积" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="11">
<el-form-item label="公摊面积(㎡)" prop="shareArea">
<el-input maxlength="10" v-model.trim="form.shareArea" placeholder="请输入公摊面积" />
</el-form-item>
</el-col>
<el-col :span="2"></el-col>
<el-col :span="11"> </el-col>
</el-row>
<el-row>
<el-col :span="11">
<el-form-item label="房东姓名" prop="landlordName">
<el-input maxlength="10" show-word-limit v-model.trim="form.landlordName" placeholder="请输入房东姓名" />
</el-form-item>
</el-col>
<el-col :span="2"></el-col>
<el-col :span="11">
<el-form-item label="房东电话" prop="landlordPhone">
<el-input maxlength="11" v-model.number="form.landlordPhone" placeholder="请输入房东电话" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="11">
<el-form-item label="承租方姓名" prop="lesseeName">
<el-input maxlength="10" show-word-limit v-model.trim="form.lesseeName" placeholder="请输入承租方姓名" />
</el-form-item>
</el-col>
<el-col :span="2"></el-col>
<el-col :span="11">
<el-form-item label="承租方电话" prop="lesseePhone">
<el-input maxlength="11" v-model.number="form.lesseePhone" placeholder="请输入承租方电话" />
</el-form-item>
</el-col>
</el-row>
<el-form-item label="备注" prop="remark">
<el-input type="textarea" maxlength="200" show-word-limit :row="5" v-model.trim="form.remark" placeholder="请输入备注" />
</el-form-item>
<el-form-item style="margin-top: 30px">
<el-button type="primary" @click="submitForm">确定</el-button>
<el-button @click="cancelForm">返回</el-button>
</el-form-item>
</el-form>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import PageHeader from '@/components/Pageheader/index.vue';
import { CascaderValue } from 'element-plus';
import { addHouseAPI, EditHouseApi, getHouseApi } from '@/api/system/house';
import { addHouseType } from '@/api/system/house/type';
import { validator } from '@/utils/Reg';
import { useHouseStore } from '@/store/modules/house';
interface HouseForm {
houseId?: string | null;
villageId?: string | null;
buildingId?: string | null;
unitNoId?: string | null;
floorNo?: number | null;
houseNo?: string;
houseType?: string;
houseArea?: string;
internalArea?: string;
shareArea?: string;
houseUseTypeId?: string;
houseStatus?: string;
residentId?: string | null;
landlordName?: string | null;
landlordPhone?: string | null;
lesseeName?: string | null;
lesseePhone?: string | null;
status?: string;
remark?: string | null;
}
const houseStore = useHouseStore();
const router = useRouter();
const route = useRoute();
const formRef = ref();
const form = ref<HouseForm>({
houseId: null,
buildingId: null,
unitNoId: null,
houseNo: '',
floorNo: null,
houseArea: '',
internalArea: '',
shareArea: '',
landlordName: '',
landlordPhone: '',
lesseeName: '',
lesseePhone: '',
remark: ''
});
const userHousePath = ref<CascaderValue>([]);
/** 选填手机号校验 */
const validatePhone = (_: any, value: string | number, callback: (error?: Error) => void) => {
if (value === '' || value === null || value === undefined) {
return callback();
}
return validator(value, 'phone') ? callback() : callback(new Error('请输入正确的手机号码'));
};
const rules = ref({
buildingId: [{ required: true, message: '请选择区号', trigger: 'change' }],
houseNo: [{ required: true, message: '请输入房号', trigger: 'blur' }],
landlordName: [{ required: true, message: '请输入房东姓名', trigger: 'blur' }],
landlordPhone: [
{ required: true, message: '请输入房东电话', trigger: 'blur' },
{ validator: validatePhone, trigger: 'blur' }
],
lesseePhone: [{ validator: validatePhone, trigger: 'blur' }]
});
// 区号(楼栋)选项,只展示一层
const treeData = ref<any[]>([]);
function getTree() {
houseStore.getCurrentVilageTreeHouse().then((res) => {
treeData.value = (res ?? []).map((node: any) => ({
label: node.label,
value: node.value,
type: node.type
}));
getTreeData();
});
}
getTree();
// !== 楼栋房屋 =============================================================================
const userid = ref(null);
function getTreeData() {
// !== 编辑 =============================================================================
if (route.query.id) {
userid.value = route.query.id;
getHouseApi(userid.value).then((res) => {
const house = res.data ?? {};
form.value = {
...house
};
// 只在区号(楼栋)一层回显,使用树中的原始 value 保证与 options 一致
const buildingNode = treeData.value.find((node: any) => String(node.value) === String(house.buildingId));
userHousePath.value = buildingNode ? [buildingNode.value] : [];
});
}
}
function handleChange(val: CascaderValue) {
userHousePath.value = val;
const path = Array.isArray(val) ? val : [];
// 只有区号(楼栋)一级
form.value.buildingId = (path[0] ?? null) as string | null;
}
// 提交
const submitForm = () => {
formRef.value?.validate(async (valid: boolean) => {
if (valid) {
const obj = {
...form.value
} as unknown as addHouseType;
if (userid.value) {
EditHouseApi(obj).then(() => {
ElMessage.success('修改成功');
cancelForm();
});
} else {
addHouseAPI(obj).then(() => {
ElMessage.success('添加成功');
cancelForm();
});
}
}
});
};
// 推出
const cancelForm = () => {
router.back();
};
</script>
<style scoped lang="scss">
.AddBuildingBox {
padding: 15px;
height: 100%;
width: 100%;
}
.AddBuildingBody {
margin-top: 20px;
display: flex;
flex-direction: column;
justify-content: center;
background-color: white;
padding: 15px;
.title {
height: 40px;
line-height: 40px;
padding-left: 20px;
background-color: rgba(255, 255, 255, 1);
color: rgba(16, 16, 16, 1);
border-bottom: 1px solid #bbbbbb;
margin-bottom: 60px;
}
.formBody {
width: 1050px;
margin: 0 auto;
&:deep(.el-form-item__content, .el-select, .el-input) {
width: 350px !important;
margin-right: 10px;
.el-cascader {
width: 100%;
}
}
.el-form-item {
margin-bottom: 20px;
align-items: center;
}
.unitBox {
.el-input {
width: 440px;
margin-right: 10px;
}
}
.el-button {
width: 80px;
height: 35px;
margin-right: 20px;
}
.houseTypebox {
display: flex;
align-items: center;
.el-input {
width: 100px;
margin-right: 0;
}
span {
margin: 0 20px;
}
}
}
}
</style>