5.1日 暂定 水电表管理
This commit is contained in:
@@ -16,11 +16,14 @@ import { usePermissionStore } from '@/store/modules/permission';
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const permissionStore = usePermissionStore();
|
||||
const levelList = ref<RouteLocationMatched[]>([]);
|
||||
|
||||
const levelList = ref<LooseRouteMatched[]>([]);
|
||||
type LooseRouteMatched = Partial<RouteLocationMatched> & {
|
||||
path: string; // 确保必要字段存在
|
||||
meta?: any;
|
||||
};
|
||||
const getBreadcrumb = () => {
|
||||
// 1. 先获取原生的 matched
|
||||
let matched = route.matched.filter((item) => item.meta && item.meta.title);
|
||||
let matched = route.matched.filter((item) => item.meta && item.meta.title) as LooseRouteMatched[];
|
||||
|
||||
// 🔥 关键:如果当前路由有 parentTitle,手动插入虚拟父级
|
||||
if (route.meta?.parentTitle) {
|
||||
@@ -30,7 +33,7 @@ const getBreadcrumb = () => {
|
||||
// 创建虚拟父级路由对象
|
||||
const virtualParent = {
|
||||
path: matched[lastIndex].path,
|
||||
meta: { title: route.meta.parentTitle }
|
||||
meta: { title: route.meta.parentTitle as string }
|
||||
};
|
||||
|
||||
// 插入到倒数第二个位置
|
||||
@@ -40,8 +43,6 @@ const getBreadcrumb = () => {
|
||||
|
||||
// 2. 过滤掉设置了 breadcrumb: false 的路由
|
||||
levelList.value = matched.filter((item) => item.meta && item.meta.title && item.meta.breadcrumb !== false);
|
||||
|
||||
console.log('最终面包屑:', levelList.value);
|
||||
};
|
||||
|
||||
const handleLink = (item) => {
|
||||
|
||||
@@ -59,7 +59,7 @@ const props = defineProps({
|
||||
// 大小限制(MB)
|
||||
fileSize: propTypes.number.def(5),
|
||||
// 文件类型, 例如['png', 'jpg', 'jpeg']
|
||||
fileType: propTypes.array.def(['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'pdf']),
|
||||
fileType: propTypes.array.def(['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'pdf', 'bin']),
|
||||
// 是否显示提示
|
||||
isShowTip: propTypes.bool.def(true),
|
||||
// 禁用组件(仅查看文件)
|
||||
|
||||
295
src/components/Holder/house.vue
Normal file
295
src/components/Holder/house.vue
Normal file
@@ -0,0 +1,295 @@
|
||||
<template>
|
||||
<slot name="default" />
|
||||
|
||||
<el-dialog append-to-body v-model="dialog.dialogVisible" :title="dialog.dialogTitle" width="1050">
|
||||
<nav class="flex flex-items-center mb-8">
|
||||
<div class="flex flex-items-center">
|
||||
<div style="width: 70px; text-align: right; padding-right: 10px">房屋类型</div>
|
||||
<div class="flex-1">
|
||||
<el-select @change="handleChangeHouse" style="width: 140px" v-model="queryParams.buildingUse">
|
||||
<el-option v-for="(item, index) in com_build_use" :key="index" :label="item.label" :value="item.value"></el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-items-center">
|
||||
<div style="width: 60px; text-align: right; padding-right: 10px">楼栋</div>
|
||||
<div class="flex-1"></div>
|
||||
<el-select @change="handleChangebuilding" style="width: 140px" v-model="queryParams.buildingId">
|
||||
<el-option v-for="(item, index) in buildinglist" :key="index" :label="item.buildingName" :value="item.id"></el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="flex flex-items-center mr-20px">
|
||||
<div style="width: 60px; text-align: right; padding-right: 10px">单元</div>
|
||||
<div class="flex-1">
|
||||
<el-select style="width: 140px" v-model="queryParams.unitNo">
|
||||
<el-option v-for="(item, index) in unitlist" :key="index" :label="`${item.unitNo}单元`" :value="item.unitNo"></el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<el-button type="primary" @click="getlist">查询</el-button>
|
||||
<el-button @click="resetQuery">重置</el-button>
|
||||
</div>
|
||||
</nav>
|
||||
<el-table @row-click="handleRowClick" ref="multipleTableRef" :data="tableData" border @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="序号" align="center" width="55" type="index" />
|
||||
<el-table-column label="小区" align="center" prop="villageName" />
|
||||
<el-table-column label="楼栋" align="center" prop="buildingName" />
|
||||
<el-table-column label="单元" align="center" prop="unitNo" />
|
||||
<el-table-column label="房间" align="center" prop="houseNo" />
|
||||
<el-table-column label="业主" align="center">
|
||||
<template #default="scope">
|
||||
<span>{{ scope.row.userName ? scope.row.userName : '---' }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<template #footer>
|
||||
<div class="dialog-footer flex flex-items-center flex-justify-between">
|
||||
<pagination
|
||||
style="margin-top: 0"
|
||||
layout="total, prev, pager, next, jumper"
|
||||
v-show="total > 0"
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNum"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getlist"
|
||||
/>
|
||||
<div>
|
||||
<el-button @click="conback">退出</el-button>
|
||||
<el-button type="primary" @click="confirm"> 确定 </el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getBuildinglistAPI, getBuildingOnly, getHouselistAPI } from '@/api/system/house';
|
||||
import { BillHouse, listBillHouse } from '@/api/system/SdbBill';
|
||||
import { ref, watch, nextTick, getCurrentInstance, ComponentInternalInstance, toRefs } from 'vue';
|
||||
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
const { sys_user_sex } = toRefs<any>(proxy?.useDict('sys_user_sex'));
|
||||
const { com_build_use } = toRefs<any>(proxy?.useDict('com_build_use'));
|
||||
|
||||
const props = defineProps({
|
||||
userid: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
returnvalue: {
|
||||
type: String,
|
||||
default: 'houseId'
|
||||
},
|
||||
titleName: {
|
||||
type: String,
|
||||
default: '选择房屋'
|
||||
},
|
||||
/** 是否多选 false 单选 */
|
||||
isMultiple: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
});
|
||||
|
||||
const { userid, titleName, returnvalue } = toRefs(props);
|
||||
|
||||
// ✅ 手动设置默认值(替代 withDefaults)
|
||||
const emit = defineEmits<{
|
||||
change: [value: string | number | (string | number)[] | BillHouse | BillHouse[]]; // 支持返回数组
|
||||
}>();
|
||||
|
||||
const dialog = ref({
|
||||
dialogVisible: false,
|
||||
dialogTitle: titleName.value
|
||||
});
|
||||
|
||||
const queryParams = ref({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
buildingUse: null,
|
||||
buildingId: null,
|
||||
unitNo: null
|
||||
});
|
||||
|
||||
const multipleTableRef = ref();
|
||||
const tableData = ref<BillHouse[]>([]);
|
||||
const total = ref(0);
|
||||
const loading = ref(false);
|
||||
|
||||
// 存储选中项
|
||||
const multipleSelection = ref<BillHouse[]>([]);
|
||||
|
||||
const isMultiple = computed(() => props.isMultiple ?? false);
|
||||
|
||||
// 优化 handleUserSelection,避免重复查找
|
||||
const handleUserSelection = () => {
|
||||
if (!userid.value || !tableData.value.length) return;
|
||||
|
||||
multipleSelection.value = [];
|
||||
if (userid.value.trim() !== '') {
|
||||
const arr = userid.value.split(',');
|
||||
arr.forEach((item) => {
|
||||
const target = tableData.value.find((row) => row.userId == item);
|
||||
target && multipleSelection.value.push(target);
|
||||
});
|
||||
nextTick(() => {
|
||||
if (multipleTableRef.value) {
|
||||
multipleTableRef.value.clearSelection();
|
||||
multipleSelection.value.forEach((item) => {
|
||||
multipleTableRef.value.toggleRowSelection(item, true);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// ====================== 方法 ======================
|
||||
|
||||
// 获取列表
|
||||
function getlist() {
|
||||
loading.value = true;
|
||||
listBillHouse(queryParams.value)
|
||||
.then((res) => {
|
||||
tableData.value = res.rows;
|
||||
total.value = res.total;
|
||||
handleUserSelection();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('获取用户列表失败:', error);
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
/** 楼栋列表 */
|
||||
const buildinglist = ref([]);
|
||||
/** 房屋列表 */
|
||||
const unitlist = ref([]);
|
||||
|
||||
/** 筛选房屋类型 */
|
||||
function handleChangeHouse(val: string) {
|
||||
getBuildinglistAPI(val).then((res) => {
|
||||
buildinglist.value = res.data;
|
||||
});
|
||||
}
|
||||
/** 单元列表 */
|
||||
function handleChangebuilding(val: string) {
|
||||
getHouselistAPI(val).then((res) => {
|
||||
unitlist.value = res.data.units;
|
||||
});
|
||||
}
|
||||
|
||||
// ==============================================
|
||||
// ✅ 新增:处理 selection-change(多选专用)
|
||||
// ==============================================
|
||||
function handleSelectionChange(selection: BillHouse[]) {
|
||||
if (isMultiple.value) {
|
||||
multipleSelection.value = selection;
|
||||
}
|
||||
}
|
||||
// ==============================================
|
||||
// 最佳单选方案:点击行选中,无报错、无循环、最稳定
|
||||
// ==============================================
|
||||
// 优化 handleRowClick,避免重复
|
||||
function handleRowClick(row: BillHouse) {
|
||||
if (!multipleTableRef.value) return;
|
||||
|
||||
if (isMultiple.value) {
|
||||
const index = multipleSelection.value.findIndex((item) => item.houseId === row.houseId);
|
||||
if (index > -1) {
|
||||
// 取消选中
|
||||
multipleSelection.value.splice(index, 1);
|
||||
multipleTableRef.value?.toggleRowSelection(row, false);
|
||||
} else {
|
||||
// 选中
|
||||
multipleSelection.value.push(row);
|
||||
multipleTableRef.value?.toggleRowSelection(row, true);
|
||||
}
|
||||
} else {
|
||||
// 【单选模式】先清空,再选中当前行
|
||||
multipleSelection.value = [];
|
||||
multipleTableRef.value.clearSelection();
|
||||
multipleSelection.value = [row];
|
||||
multipleTableRef.value.toggleRowSelection(row, true);
|
||||
}
|
||||
}
|
||||
// 重置查询
|
||||
function resetQuery() {
|
||||
queryParams.value = {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
houseuse: null,
|
||||
buildingId: null,
|
||||
unitNo: null
|
||||
};
|
||||
getlist();
|
||||
}
|
||||
|
||||
// 退出
|
||||
function conback() {
|
||||
dialog.value.dialogVisible = false;
|
||||
resetQuery();
|
||||
}
|
||||
|
||||
// ==============================================
|
||||
// ✅ 核心修改:根据 returnvalue 返回对应的值
|
||||
// ==============================================
|
||||
function confirm() {
|
||||
dialog.value.dialogVisible = false;
|
||||
if (isMultiple.value) {
|
||||
// 多选
|
||||
if (returnvalue.value === '*') {
|
||||
// ✅ 返回整个对象数组
|
||||
emit('change', multipleSelection.value);
|
||||
} else {
|
||||
// 返回指定字段数组
|
||||
emit(
|
||||
'change',
|
||||
multipleSelection.value.map((item) => item[returnvalue.value as keyof BillHouse])
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// 单选
|
||||
if (returnvalue.value === '*') {
|
||||
// ✅ 返回整个对象
|
||||
emit('change', multipleSelection.value[0]);
|
||||
} else {
|
||||
// 返回指定字段
|
||||
emit('change', multipleSelection.value[0][returnvalue.value as keyof BillHouse]);
|
||||
}
|
||||
}
|
||||
|
||||
multipleSelection.value = [];
|
||||
multipleTableRef.value.clearSelection();
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
open: () => {
|
||||
getlist();
|
||||
dialog.value.dialogVisible = true;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.residentBox {
|
||||
width: 385px;
|
||||
height: 35px;
|
||||
line-height: 35px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 5px;
|
||||
padding: 0 10px;
|
||||
.defaultbox {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
background-color: #f4f8ff;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -83,7 +83,6 @@ const houseStore = useHouseStore();
|
||||
const treedata = ref([]);
|
||||
function init() {
|
||||
houseStore.getCurrentVilageTreeHouse().then((res) => {
|
||||
console.log(res);
|
||||
treedata.value = res;
|
||||
});
|
||||
}
|
||||
@@ -273,7 +272,6 @@ function confirm() {
|
||||
// ✅ 返回整个对象
|
||||
emit('change', multipleSelection.value[0]);
|
||||
} else {
|
||||
console.log(multipleSelection.value[0], returnvalue.value);
|
||||
// 返回指定字段
|
||||
emit('change', multipleSelection.value[0][returnvalue.value as keyof tableType]);
|
||||
}
|
||||
|
||||
@@ -157,7 +157,6 @@ function getlist() {
|
||||
// ✅ 新增:处理 selection-change(多选专用)
|
||||
// ==============================================
|
||||
function handleSelectionChange(selection: MaterialVO[]) {
|
||||
console.log(selection);
|
||||
if (isMultiple.value) {
|
||||
multipleSelection.value = selection;
|
||||
}
|
||||
@@ -228,7 +227,6 @@ function confirm() {
|
||||
// ✅ 返回整个对象
|
||||
emit('change', multipleSelection.value[0]);
|
||||
} else {
|
||||
console.log(multipleSelection.value[0], returnvalue.value);
|
||||
// 返回指定字段
|
||||
emit('change', multipleSelection.value[0][returnvalue.value as keyof MaterialVO]);
|
||||
}
|
||||
|
||||
@@ -252,7 +252,6 @@ function confirm() {
|
||||
// ✅ 返回整个对象
|
||||
emit('change', multipleSelection.value[0]);
|
||||
} else {
|
||||
console.log(multipleSelection.value[0], returnvalue.value);
|
||||
// 返回指定字段
|
||||
emit('change', multipleSelection.value[0][returnvalue.value as keyof tableType]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user