buildOwner.vue
5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<script setup lang="ts">
import {
reactive,
onMounted,
ref,
getCurrentInstance,
defineProps,
defineEmits,
watchEffect,
} from "vue";
import {
availableResidentList,
addHouseResident,
membersByHouseId,
} from "@/api/community/houses.ts";
import { addOrUpBuildingHouseKeeper } from "@/api/community/housekeeper.ts";
import Pagination from "@/components/Pagination/index.vue";
let instance: ComponentInternalInstance | null = getCurrentInstance(); //获取app实例
const multipleTableRef = ref<InstanceType<typeof ElTable>>();
// 声明props
const props = defineProps({
houseId: {
type: Number,
default: null,
},
});
// 数据筛选
const searchData = reactive({
condition: "",
page: 1,
pageSize: 10,
});
// 展示
const data = reactive({
total: 0,
tableList: [],
loading: false,
livingList: [
{ label: "不在住", value: 0 },
{ label: "在住", value: 1 },
],
ownerList: [
{ label: "非业主", value: 0 },
{ label: "业主", value: 1 }
],
selectList: [],
});
/**
* 列表查询
*/
const search = (): void => {
data.loading = true;
searchData.houseId = props.houseId;
availableResidentList(searchData)
.then((res) => {
data.tableList = res.data.data.list;
data.tableList.map((item) => {
item.houseId = props.houseId;
item.residentId = item.id;
});
data.total = res.data.data.total;
data.loading = false;
data.selectList = [];
})
.catch((err) => {
data.loading = false;
});
};
const emit = defineEmits<{
(e: "success"): void;
}>();
/**
* 表格选择回调
*/
const setCurrentRow = (selection, row) => {
if (
[null, undefined].includes(row.isOwner) ||
[null, undefined].includes(row.isLiving)
) {
instance?.proxy?.$message.error("请完当前业主信息");
multipleTableRef.value.toggleRowSelection(row);
}
};
/**
* 全选回调
*/
const selectAll = (selection) => {
const status = selection.every((item) => {
return (
![null, undefined].includes(item.isOwner) &&
![null, undefined].includes(item.isLiving)
);
});
if (!status) {
instance?.proxy?.$message.error("请完当前业主信息");
}
};
const handleSelectionChange = (val) => {
data.selectList = val;
};
/**
* 数据提交
*/
const submit = () => {
if (data.selectList.length == 0) {
instance?.proxy?.$message.error("请选择业主");
} else {
instance?.proxy?.$messageBox
.confirm("确认要进行此操作?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
})
.then(() => {
let params = [];
data.selectList.map((item) => {
let obj = {};
obj.houseId = item.houseId;
obj.isLiving = item.isLiving;
obj.isOwner = item.isOwner;
obj.residentId = item.residentId;
params.push(obj);
});
addHouseResident(params).then((res) => {
multipleTableRef.value!.clearSelection();
data.selectList = [];
emit("success");
});
})
.catch((err) => {});
}
};
watchEffect(() => {
if (props.houseId) {
search();
}
});
</script>
<template>
<div>
<!-- 搜索 -->
<el-form :inline="true" :model="searchData" >
<el-form-item>
<el-input
style="width: 280px"
placeholder="请输入姓名/手机号/身份证号"
v-model="searchData.condition"
clearable
></el-input>
</el-form-item>
<el-form-item
><el-button type="primary" @click="search"
>查询</el-button
></el-form-item
>
<el-form-item
><el-button type="primary" @click="submit"
>确认选择</el-button
></el-form-item
>
</el-form>
<!-- 表格 -->
<el-table
border
:data="data.tableList"
@select="setCurrentRow"
@select-all="selectAll"
@selection-change="handleSelectionChange"
ref="multipleTableRef"
v-loading="data.loading"
>
<el-table-column type="selection" width="55" />
<el-table-column label="姓名" prop="name"></el-table-column>
<el-table-column label="是否居住" prop="isLiving">
<template #default="scope">
<el-select v-model="scope.row.isLiving" placeholder="请选择">
<el-option
v-for="item in data.livingList"
:key="item.value"
:label="item.label"
:value="item.value"
>
</el-option>
</el-select>
</template>
</el-table-column>
<el-table-column label="是否是业主" prop="isOwner">
<template #default="scope">
<el-select v-model="scope.row.isOwner" placeholder="请选择">
<el-option
v-for="item in data.ownerList"
:key="item.value"
:label="item.label"
:value="item.value"
>
</el-option>
</el-select> </template
></el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
v-if="data.total > 0"
:total="data.total"
v-model:currentPage="searchData.page"
v-model:pageSize="searchData.pageSize"
@pageChange="search"
></Pagination>
</div>
</template>
<style></style>