|
|
@@ -149,7 +149,7 @@ import {
|
|
|
} from '@/api/xg/xgss/sslxx/dormBuilding';
|
|
|
import { DormBuildingVO, DormBuildingQuery, DormBuildingForm } from '@/api/xg/xgss/sslxx/dormBuilding/types';
|
|
|
import { DormCampusVO } from '@/api/xg/xgss/xqxx/dormCampus/types';
|
|
|
-import { getCurrentInstance, ComponentInternalInstance, ref, reactive, toRefs, onMounted } from 'vue';
|
|
|
+import { getCurrentInstance, ComponentInternalInstance, ref, reactive, toRefs, onMounted, watch } from 'vue';
|
|
|
import { ElForm, ElMessageBox, ElMessage } from 'element-plus';
|
|
|
|
|
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
|
|
@@ -178,8 +178,10 @@ const initFormData: DormBuildingForm = {
|
|
|
buildingCode: undefined,
|
|
|
buildingName: undefined,
|
|
|
campusId: undefined,
|
|
|
+ areaId: '2015638219126755329',
|
|
|
buildingType: undefined,
|
|
|
buildingDescription: undefined,
|
|
|
+ remark: undefined,
|
|
|
sortOrder: undefined,
|
|
|
floors: 6 // 添加默认值为6
|
|
|
};
|
|
|
@@ -220,6 +222,30 @@ const loadCampusOptions = async () => {
|
|
|
campusList.value = res.rows || [];
|
|
|
};
|
|
|
|
|
|
+// 默认宿舍区映射(按校区名称判断)
|
|
|
+const AREA_DEFAULTS: Record<string, string> = {
|
|
|
+ '临安校区': '2015638219126755329',
|
|
|
+ '西溪校区': '2015639946668298241'
|
|
|
+};
|
|
|
+
|
|
|
+const deriveAreaIdFromCampusId = (campusId?: string | number) => {
|
|
|
+ const defaultArea = AREA_DEFAULTS['临安校区'];
|
|
|
+ if (!campusId) return defaultArea;
|
|
|
+ const campus = campusList.value.find((c: any) => String(c.id) === String(campusId));
|
|
|
+ if (!campus || !campus.campusName) return defaultArea;
|
|
|
+ if (campus.campusName.includes('临安')) return AREA_DEFAULTS['临安校区'];
|
|
|
+ if (campus.campusName.includes('西溪')) return AREA_DEFAULTS['西溪校区'];
|
|
|
+ return defaultArea;
|
|
|
+};
|
|
|
+
|
|
|
+// 当选择校区变化时,自动设置 areaId
|
|
|
+watch(
|
|
|
+ () => form.value.campusId,
|
|
|
+ (newCampusId) => {
|
|
|
+ (form.value as any).areaId = deriveAreaIdFromCampusId(newCampusId);
|
|
|
+ }
|
|
|
+);
|
|
|
+
|
|
|
/** 搜索按钮操作 */
|
|
|
const handleQuery = () => {
|
|
|
queryParams.value.pageNum = 1;
|
|
|
@@ -252,6 +278,10 @@ const handleUpdate = async (row?: DormBuildingVO) => {
|
|
|
const _id = row?.id || ids.value[0];
|
|
|
const res = await getDormBuilding(_id);
|
|
|
Object.assign(form.value, res.data);
|
|
|
+ // If areaId is missing from returned data, default it based on campus
|
|
|
+ if (!(form.value as any).areaId) {
|
|
|
+ (form.value as any).areaId = deriveAreaIdFromCampusId(form.value.campusId);
|
|
|
+ }
|
|
|
dialog.visible = true;
|
|
|
dialog.title = '修改宿舍楼信息';
|
|
|
};
|
|
|
@@ -261,6 +291,10 @@ const submitForm = () => {
|
|
|
dormBuildingFormRef.value?.validate(async (valid: boolean) => {
|
|
|
if (valid) {
|
|
|
buttonLoading.value = true;
|
|
|
+ // Ensure areaId defaults based on selected campus before submitting
|
|
|
+ if (!(form.value as any).areaId) {
|
|
|
+ (form.value as any).areaId = deriveAreaIdFromCampusId(form.value.campusId);
|
|
|
+ }
|
|
|
if (form.value.id) {
|
|
|
await updateDormBuilding(form.value)
|
|
|
.then(() => {
|
|
|
@@ -303,6 +337,8 @@ const handleDelete = async (row?: DormBuildingVO) => {
|
|
|
/** 重置操作表单 */
|
|
|
const reset = () => {
|
|
|
form.value = { ...initFormData };
|
|
|
+ // default areaId for new forms/reset based on current campus selection (or 临安)
|
|
|
+ (form.value as any).areaId = deriveAreaIdFromCampusId(form.value.campusId);
|
|
|
dormBuildingFormRef.value?.resetFields();
|
|
|
};
|
|
|
|