房屋详情,单元变更
This commit is contained in:
@@ -39,26 +39,21 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getBuildinglistAPI, getBuildingOnly, getHouselistAPI } from '@/api/system/house';
|
||||
import { BillHouse, listBillHouse, queryResidentList_holder } from '@/api/system/SdbBill';
|
||||
import { ref, watch, nextTick, getCurrentInstance, ComponentInternalInstance, toRefs } from 'vue';
|
||||
import { getBuildinglistAPI, getHouselistAPI } from '@/api/system/house';
|
||||
import { BillUserlist, queryResidentList_holder } from '@/api/system/SdbBill';
|
||||
import { ref, 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 || Array<string>,
|
||||
default: ''
|
||||
},
|
||||
returnvalue: {
|
||||
type: String,
|
||||
default: 'houseId'
|
||||
},
|
||||
titleName: {
|
||||
type: String,
|
||||
default: '选择房屋'
|
||||
default: '选择业主'
|
||||
},
|
||||
/** 是否多选 false 单选 */
|
||||
isMultiple: {
|
||||
@@ -67,11 +62,12 @@ const props = defineProps({
|
||||
}
|
||||
});
|
||||
|
||||
const { userid, titleName, returnvalue } = toRefs(props);
|
||||
const { titleName, returnvalue } = toRefs(props);
|
||||
|
||||
const userid = ref([]);
|
||||
// ✅ 手动设置默认值(替代 withDefaults)
|
||||
const emit = defineEmits<{
|
||||
change: [value: string | number | (string | number)[] | BillHouse | BillHouse[]]; // 支持返回数组
|
||||
change: [value: string | number | (string | number)[] | BillUserlist | BillUserlist[]]; // 支持返回数组
|
||||
}>();
|
||||
|
||||
const dialog = ref({
|
||||
@@ -85,29 +81,24 @@ const queryParams = ref({
|
||||
});
|
||||
|
||||
const multipleTableRef = ref();
|
||||
const tableData = ref<BillHouse[]>([]);
|
||||
const tableData = ref<BillUserlist[]>([]);
|
||||
const total = ref(0);
|
||||
const loading = ref(false);
|
||||
|
||||
// 存储选中项
|
||||
const multipleSelection = ref<BillHouse[]>([]);
|
||||
const multipleSelection = ref<BillUserlist[]>([]);
|
||||
|
||||
const isMultiple = computed(() => props.isMultiple ?? false);
|
||||
|
||||
// 优化 handleUserSelection,避免重复查找
|
||||
const handleUserSelection = () => {
|
||||
if (!userid.value || !tableData.value.length) return;
|
||||
if (!tableData.value.length) return;
|
||||
|
||||
multipleSelection.value = [];
|
||||
let arr = [];
|
||||
if (userid.value && typeof userid.value === 'string' && userid.value.trim() !== '') {
|
||||
arr = userid.value.split(',');
|
||||
} else if (Array.isArray(userid.value)) {
|
||||
arr = [...userid.value];
|
||||
}
|
||||
const arr = userid.value;
|
||||
if (!arr.length) return;
|
||||
arr.forEach((item) => {
|
||||
const target = tableData.value.find((row) => row.userId == item);
|
||||
const target = tableData.value.find((row) => row.residentId == item);
|
||||
target && multipleSelection.value.push(target);
|
||||
});
|
||||
nextTick(() => {
|
||||
@@ -146,7 +137,7 @@ const unitlist = ref([]);
|
||||
|
||||
/** 筛选房屋类型 */
|
||||
function handleChangeHouse(val: string) {
|
||||
getBuildinglistAPI(val).then((res) => {
|
||||
getBuildinglistAPI().then((res) => {
|
||||
buildinglist.value = res.data;
|
||||
});
|
||||
}
|
||||
@@ -160,7 +151,7 @@ function handleChangebuilding(val: string) {
|
||||
// ==============================================
|
||||
// ✅ 新增:处理 selection-change(多选专用)
|
||||
// ==============================================
|
||||
function handleSelectionChange(selection: BillHouse[]) {
|
||||
function handleSelectionChange(selection: BillUserlist[]) {
|
||||
if (isMultiple.value) {
|
||||
multipleSelection.value = selection;
|
||||
}
|
||||
@@ -169,11 +160,11 @@ function handleSelectionChange(selection: BillHouse[]) {
|
||||
// 最佳单选方案:点击行选中,无报错、无循环、最稳定
|
||||
// ==============================================
|
||||
// 优化 handleRowClick,避免重复
|
||||
function handleRowClick(row: BillHouse) {
|
||||
function handleRowClick(row: BillUserlist) {
|
||||
if (!multipleTableRef.value) return;
|
||||
|
||||
if (isMultiple.value) {
|
||||
const index = multipleSelection.value.findIndex((item) => item.houseId === row.houseId);
|
||||
const index = multipleSelection.value.findIndex((item) => item.residentId === row.residentId);
|
||||
if (index > -1) {
|
||||
// 取消选中
|
||||
multipleSelection.value.splice(index, 1);
|
||||
@@ -220,7 +211,7 @@ function confirm() {
|
||||
// 返回指定字段数组
|
||||
emit(
|
||||
'change',
|
||||
multipleSelection.value.map((item) => item[returnvalue.value as keyof BillHouse])
|
||||
multipleSelection.value.map((item) => item[returnvalue.value as keyof BillUserlist])
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@@ -230,7 +221,7 @@ function confirm() {
|
||||
emit('change', multipleSelection.value[0]);
|
||||
} else {
|
||||
// 返回指定字段
|
||||
emit('change', multipleSelection.value[0][returnvalue.value as keyof BillHouse]);
|
||||
emit('change', multipleSelection.value[0][returnvalue.value as keyof BillUserlist]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +230,8 @@ function confirm() {
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
open: () => {
|
||||
open: (arr: string[] = []) => {
|
||||
userid.value = arr;
|
||||
getlist();
|
||||
dialog.value.dialogVisible = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user