GroupChatDialog.vue
4.04 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
<template>
<d2-dialog
title="选择企微群聊"
:is-visible.sync="visible"
width="1080px"
@closeDialog="handleDialogClose"
@confirmDialog="confirmGroupSelection"
>
<div>
<d2-search
ref="showSearch"
class="show-search"
:search-form="searchForm"
:label-width="'80px'"
:form-data="showFormData"
/>
<div>
<el-button size="small" type="primary" @click="handleSearch">
查询
</el-button>
</div>
</div>
<d2-table
ref="groupTable"
v-loading="loading"
:table-data="groupChatList"
:table-params="tableParams"
:has-page="false"
:has-num="false"
:selectable-fn="checkSelectable"
max-height="400px"
@selectionTable="handleSelectionChange"
/>
</d2-dialog>
</template>
<script>
import { getGroupChatList } from "@/api/usedCarManagement";
export default {
name: "GroupChatDialog",
props: {
selectedData: {
type: Array,
default: () => [],
},
editData: {
type: Object,
default: () => {},
},
},
data() {
return {
visible: true,
loading: false,
groupChatList: [],
selectedGroups: [],
searchForm: {
groupChatName: "",
},
searchFormSearch: {},
showFormData: [
{
label: "群名称",
name: "groupChatName",
type: "input",
maxlength: 100,
placeholder: "请输入群名称",
},
],
tableParams: {
mutiSelectUniqueKey: "groupChatId",
mutiSelectName: "groupChat",
tableOption: false,
tableColumns: [
{ label: "群名称", prop: "groupChatName", align: "center" },
{
label: "群状态",
prop: "free",
align: "center",
formatter: (cellValue) => {
return cellValue.free ? "空闲" : "占用";
},
className: (cellValue) => {
return cellValue.free ? "greenSpot" : "redSpot";
},
},
],
},
};
},
created() {
this.searchFormSearch = { ...this.searchForm };
this.selectedGroups = [...this.selectedData];
this.fetchGroupList();
},
methods: {
handleSearch() {
this.searchFormSearch = { ...this.searchForm };
this.selectedGroups = this.getMutiDate();
this.fetchGroupList();
},
fetchGroupList() {
this.loading = true;
const params = { ...this.searchFormSearch };
if (this.editData?.id) {
params.id = this.editData.id;
}
getGroupChatList(params)
.then((res) => {
this.groupChatList = res;
this.recoverySelection(res);
})
.finally(() => {
this.loading = false;
});
},
recoverySelection(list) {
this.$nextTick(() => {
if (this.selectedGroups.length) {
this.selectedGroups.forEach((row) => {
const obj = this.groupChatList.find(
(item) => item.groupChatId == row.groupChatId
);
obj &&
this.$refs.groupTable.$refs[
this.tableParams.mutiSelectName + "MutiTable"
].toggleRowSelection(obj, true);
});
}
});
},
getMutiDate() {
let selectedData =
this.$refs.groupTable.mutiSelectArr[this.tableParams.mutiSelectName] ||
[];
let deleteIds = [];
this.selectedGroups.forEach((item) => {
if (
!this.groupChatList
.map((k) => k.groupChatId)
.includes(item.groupChatId) &&
!selectedData.map((k) => k.groupChatId).includes(item.groupChatId)
) {
selectedData.push(item);
}
if (
selectedData?.map((k) => k.groupChatId).includes(item.groupChatId) &&
!selectedData?.map((k) => k.groupChatId).includes(item.groupChatId)
) {
deleteIds.push(item.groupChatId);
}
});
deleteIds.forEach((item) => {
const idx = selectedData.findIndex((k) => k.groupChatId == item.groupChatId);
if (idx !== -1) {
selectedData.splice(idx, 1);
}
});
return selectedData;
},
handleSelectionChange(val) {},
confirmGroupSelection() {
this.selectedGroups = this.getMutiDate();
this.$emit("confirm", this.selectedGroups);
this.$emit("close");
},
handleDialogClose() {
this.$emit("close");
},
checkSelectable(row) {
return !row.disabled;
},
},
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
padding-top: 0 !important;
}
</style>