同步6/16
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<template>
|
||||
<slot name="default" />
|
||||
|
||||
<el-dialog append-to-body v-model="dialog.dialogVisible" :title="dialog.dialogTitle" width="1250">
|
||||
<nav class="flex flex-items-center mb-8">
|
||||
<el-dialog append-to-body v-model="dialog.dialogVisible" :title="dialog.dialogTitle" width="1400">
|
||||
<nav class="flex flex-items-center mb-8 justify-between">
|
||||
<!-- <div class="flex flex-items-center">
|
||||
<div style="width: 70px; text-align: right; padding-right: 10px">房屋类型</div>
|
||||
<div class="flex-1">
|
||||
@@ -12,32 +12,40 @@
|
||||
</div>
|
||||
</div> -->
|
||||
<div class="flex flex-items-center">
|
||||
<div style="width: 50px; text-align: right; padding-right: 10px">楼栋</div>
|
||||
<div class="flex-1"></div>
|
||||
<el-select @change="handleChangebuilding" clearable 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: 50px; text-align: right; padding-right: 10px">单元</div>
|
||||
<div class="flex-1">
|
||||
<el-select @change="handleChangeUnit" clearable style="width: 140px" v-model="queryParams.unitNoId">
|
||||
<el-option v-for="(item, index) in unitlist" :key="index" :label="item.unitNoName" :value="item.unitNoId"></el-option>
|
||||
<div class="flex flex-items-center">
|
||||
<div style="width: 50px; text-align: right; padding-right: 10px">楼栋</div>
|
||||
<div class="flex-1"></div>
|
||||
<el-select @change="handleChangebuilding" clearable style="width: 120px" 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>
|
||||
<div class="flex flex-items-center mr-20px">
|
||||
<div style="width: 80px; text-align: right; padding-right: 10px">房屋类型</div>
|
||||
<div class="flex-1">
|
||||
<el-select clearable @change="handleHouseUseChange" style="width: 140px" v-model="queryParams.houseUseTypeId">
|
||||
<el-option v-for="(item, index) in houseUseTypeList" :key="index" :label="item.name" :value="item.id"></el-option>
|
||||
</el-select>
|
||||
<div class="flex flex-items-center mr-20px">
|
||||
<div style="width: 50px; text-align: right; padding-right: 10px">单元</div>
|
||||
<div class="flex-1">
|
||||
<el-select @change="handleChangeUnit" clearable style="width: 120px" v-model="queryParams.unitNoId">
|
||||
<el-option v-for="(item, index) in unitlist" :key="index" :label="item.unitNoName" :value="item.unitNoId"></el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-items-center mr-20px">
|
||||
<div style="width: 80px; text-align: right; padding-right: 10px">业主名称</div>
|
||||
<div class="flex-1">
|
||||
<el-input clearable @clear="handleClear" v-model="queryParams.residentName" placeholder="查找业主"></el-input>
|
||||
<div class="flex flex-items-center mr-20px">
|
||||
<div style="width: 80px; text-align: right; padding-right: 10px">房屋类型</div>
|
||||
<div class="flex-1">
|
||||
<el-select clearable @change="handleHouseUseChange" style="width: 120px" v-model="queryParams.houseUseTypeId">
|
||||
<el-option v-for="(item, index) in houseUseTypeList" :key="index" :label="item.name" :value="item.id"></el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
</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-input clearable @clear="handleClear" style="width: 120px" v-model="queryParams.houseNo" placeholder="请输入房屋号"></el-input>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-items-center mr-20px">
|
||||
<div style="width: 80px; text-align: right; padding-right: 10px">业主名称</div>
|
||||
<div class="flex-1">
|
||||
<el-input clearable @clear="handleClear" style="width: 120px" v-model="queryParams.residentName" placeholder="请输入业主名称"></el-input>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
@@ -45,14 +53,7 @@
|
||||
<el-button @click="resetQuery">重置</el-button>
|
||||
</div>
|
||||
</nav>
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
@row-click="handleRowClick"
|
||||
ref="multipleTableRef"
|
||||
:data="tableData"
|
||||
border
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<el-table row-key="houseId" v-loading="loading" 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" />
|
||||
@@ -87,7 +88,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getBuildinglistAPI, getBuildingOnly, getHouselistAPI } from '@/api/system/house';
|
||||
import { listHouseUseType } from '@/api/system/houseUse';
|
||||
import { listHouseUseType, listHouseUseType_add_house } from '@/api/system/houseUse';
|
||||
import { BillHouse, listBillHouse } from '@/api/system/SdbBill';
|
||||
import { ref, watch, nextTick, getCurrentInstance, ComponentInternalInstance, toRefs } from 'vue';
|
||||
|
||||
@@ -128,7 +129,7 @@ const dialog = ref({
|
||||
const queryParams = ref({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
// houseUseTypeId: null,
|
||||
houseNo: '',
|
||||
buildingId: null,
|
||||
unitNoId: null,
|
||||
houseUseTypeId: null,
|
||||
@@ -147,29 +148,35 @@ const isMultiple = computed(() => props.isMultiple ?? false);
|
||||
|
||||
// 优化 handleUserSelection,避免重复查找
|
||||
const handleUserSelection = () => {
|
||||
if (!tableData.value.length) return;
|
||||
multipleSelection.value = [];
|
||||
if (showids.value.length > 0) {
|
||||
const arr = showids.value;
|
||||
arr.forEach((item) => {
|
||||
const target = tableData.value.find((row) => row.houseId == item);
|
||||
target && multipleSelection.value.push(target);
|
||||
});
|
||||
isFetching.value = true;
|
||||
if (!multipleTableRef.value || !tableData.value.length) {
|
||||
isFetching.value = false;
|
||||
return;
|
||||
}
|
||||
// 1. 获取当前页所有行的 houseId 集合,用于快速判断
|
||||
// const currentPageIds = new Set(tableData.value.map((item) => item.houseId));
|
||||
const rowsToSelect = tableData.value.filter((row) => {
|
||||
return multipleSelection.value.some((selected) => selected.houseId === row.houseId);
|
||||
});
|
||||
multipleTableRef.value.clearSelection();
|
||||
if (rowsToSelect.length > 0) {
|
||||
nextTick(() => {
|
||||
if (multipleTableRef.value) {
|
||||
multipleTableRef.value.clearSelection();
|
||||
multipleSelection.value.forEach((item) => {
|
||||
multipleTableRef.value.toggleRowSelection(item, true);
|
||||
});
|
||||
}
|
||||
rowsToSelect.forEach((row) => {
|
||||
multipleTableRef.value?.toggleRowSelection(row, true);
|
||||
});
|
||||
isFetching.value = false;
|
||||
});
|
||||
} else {
|
||||
isFetching.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// ====================== 方法 ======================
|
||||
const houseUseTypeList = ref([]);
|
||||
const isFetching = ref(false);
|
||||
// 获取列表
|
||||
function getlist() {
|
||||
isFetching.value = true; // 🔒 加锁:禁止 selection-change 更新数据
|
||||
loading.value = true;
|
||||
listBillHouse(queryParams.value)
|
||||
.then((res) => {
|
||||
@@ -182,6 +189,7 @@ function getlist() {
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
isFetching.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -225,34 +233,44 @@ function handleChangeUnit() {
|
||||
// ✅ 新增:处理 selection-change(多选专用)
|
||||
// ==============================================
|
||||
function handleSelectionChange(selection: BillHouse[]) {
|
||||
// 🛑 如果正在获取数据/恢复状态,直接返回,不要更新 multipleSelection
|
||||
if (isFetching.value) return;
|
||||
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);
|
||||
}
|
||||
// 1. 获取当前表格中所有选中行的 ID
|
||||
const currentSelectedIds = new Set(selection.map((item) => item.houseId));
|
||||
const otherPageSelections = multipleSelection.value.filter((item) => {
|
||||
// 判断 item 是否属于当前页
|
||||
const isCurrentPageItem = tableData.value.some((row) => row.houseId === item.houseId);
|
||||
if (isCurrentPageItem) {
|
||||
// 如果是当前页的数据,检查是否在当前 selection 中
|
||||
return currentSelectedIds.has(item.houseId);
|
||||
} else {
|
||||
// 如果不是当前页的数据,保留(假设是之前页选的)
|
||||
return true;
|
||||
}
|
||||
});
|
||||
// 去重合并
|
||||
const finalSelection = [...otherPageSelections, ...selection];
|
||||
// 再次去重以防万一
|
||||
const uniqueMap = new Map();
|
||||
finalSelection.forEach((item) => uniqueMap.set(item.houseId, item));
|
||||
multipleSelection.value = Array.from(uniqueMap.values());
|
||||
console.log(multipleSelection.value.map((item) => item.houseId));
|
||||
} else {
|
||||
// 【单选模式】先清空,再选中当前行
|
||||
multipleSelection.value = [];
|
||||
multipleTableRef.value.clearSelection();
|
||||
multipleSelection.value = [row];
|
||||
multipleTableRef.value.toggleRowSelection(row, true);
|
||||
// ✅ 补充:单选模式下,selection-change 触发时,直接取最新的一项
|
||||
// 这样配合 handleRowClick 的 clearSelection + toggle 就能实现完美单选
|
||||
if (selection.length > 0) {
|
||||
const lastSelected = selection[selection.length - 1];
|
||||
multipleSelection.value = [lastSelected];
|
||||
nextTick(() => {
|
||||
if (selection.length > 1) {
|
||||
multipleTableRef.value?.clearSelection();
|
||||
multipleTableRef.value?.toggleRowSelection(lastSelected, true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
multipleSelection.value = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
// 重置查询
|
||||
@@ -263,6 +281,7 @@ function resetQuery() {
|
||||
houseUseTypeId: null,
|
||||
buildingId: null,
|
||||
unitNoId: null,
|
||||
houseNo: '',
|
||||
residentName: ''
|
||||
};
|
||||
getlist();
|
||||
@@ -308,15 +327,20 @@ function confirm() {
|
||||
|
||||
defineExpose({
|
||||
open: (showidArray: string[] = []) => {
|
||||
multipleSelection.value = [];
|
||||
showids.value = showidArray;
|
||||
if (showidArray && showidArray.length > 0) {
|
||||
multipleSelection.value = showidArray.map(
|
||||
(id) =>
|
||||
({
|
||||
houseId: id
|
||||
}) as BillHouse
|
||||
);
|
||||
}
|
||||
getlist();
|
||||
dialog.value.dialogVisible = true;
|
||||
|
||||
listHouseUseType({
|
||||
pageNum: 1,
|
||||
pageSize: 99999
|
||||
}).then((res) => {
|
||||
houseUseTypeList.value = res.rows;
|
||||
listHouseUseType_add_house().then((res) => {
|
||||
houseUseTypeList.value = res.data;
|
||||
});
|
||||
handleChangeHouse();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user