createGroupCode.vue
10.9 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<template>
<d2-container v-loading="loading">
<!-- 基础信息 -->
<div class="edit-page edit-tmpl" style="margin-bottom: 20px">
<div class="title">基础信息</div>
<div class="content-box">
<glsx-combi-form
class="edit-form-container"
ref="baseFormRef"
label-width="150px"
default-width="470px"
:isBlock="isBlock"
:form-ref="'baseChildRef'"
:form-obj="editData"
:form-data="baseFormData"
:form-rules="formRules"
>
</glsx-combi-form>
</div>
</div>
<!-- 群池配置 -->
<div class="edit-page edit-tmpl">
<div class="title">
群池配置
<span class="sub-title"
>已关联{{ editData.groupChatIds.length }}个群</span
>
</div>
<div class="content-box">
<glsx-combi-form
class="edit-form-container"
ref="poolFormRef"
label-width="150px"
default-width="470px"
:isBlock="isBlock"
:form-ref="'poolChildRef'"
:form-obj="editData"
:form-data="poolFormData"
:form-rules="formRules"
>
<!-- 锁定时长插槽 -->
<template slot="lockTimeSlot">
<div style="display: flex; align-items: center">
<el-input-number
v-model="editData.lockTime"
:min="1"
:max="120"
:step="1"
:precision="0"
style="width: 150px"
@change="handleLockTimeChange"
>
</el-input-number>
<span style="margin-left: 10px; color: #666">分钟 (1-120)</span>
</div>
<div class="tip-text">
客户扫码但未进入所分配的群聊时,该群锁定的时间条件,锁定生效内对应群不会进入群池配置。
</div>
</template>
<!-- 选择群聊插槽 -->
<template slot="groupChatIdsSlot">
<el-button plain icon="el-icon-plus" @click="handleAddGroupChat"
>从企微后台添加群聊</el-button
>
<div class="tip-text">
支持最多选择1000个群聊,系统将按列表顺序自动分配状态为“空闲”的群。
</div>
</template>
<!-- 已选群聊列表展示插槽 -->
<template slot="groupListSlot">
<div v-if="editData.groupChatIds.length > 0" class="group-list">
<el-tag
v-for="(group, index) in editData.groupChatIds"
:key="index"
:closable="!group.disabled"
@close="handleRemoveGroup(index)"
style="margin-right: 10px; margin-bottom: 10px"
>
{{ group.groupChatName }}
</el-tag>
</div>
</template>
</glsx-combi-form>
</div>
</div>
<div class="footer">
<el-button @click="handleConfirm" type="primary" :loading="loading"
>提交</el-button
>
<el-button @click="handleCancel">取消</el-button>
</div>
<!-- 群聊选择弹窗组件 -->
<GroupChatDialog
v-if="dialogVisible"
:selected-data="editData.groupChatIds"
:edit-data="editData"
@close="dialogVisible = false"
@confirm="handleGroupConfirm"
/>
</d2-container>
</template>
<script>
import { deepClone } from "@/common/util";
import {
getCarDealerList,
addLiveCode,
updateLiveCode,
getLiveCodeDetail
} from "@/api/usedCarManagement";
import GroupChatDialog from "./components/GroupChatDialog.vue";
export default {
name: "CreateGroupCode",
components: {
GroupChatDialog,
},
data() {
// 自定义群聊数组校验
const validateGroupChats = (rule, value, callback) => {
if (!value || value.length === 0) {
callback(new Error("请选择群聊"));
} else {
callback();
}
};
return {
loading: false,
isBlock: true,
editData: {
liveName: "",
storeId: "",
remark: "",
lockTime: "",
groupChatIds: [],
},
formRules: {
liveName: [
{ required: true, message: "请输入活码名称", trigger: "change" },
],
storeId: [{ required: true, message: "请选择4S店", trigger: "change" }],
lockTime: [
{ required: true, message: "请输入锁定时长", trigger: "change" },
],
groupChatIds: [
{ required: true, validator: validateGroupChats, trigger: "change" },
],
},
baseFormData: [
{
label: "活码名称",
name: "liveName",
type: "input",
maxlength: 20,
showLimit: true,
},
{
label: "4S店选择",
name: "storeId",
type: "select",
optionList: [],
optionId: "mainMerchantId",
optionLabel: "mainMerchantName",
optionsName: "storeList",
changeAttr: (value, targetItem) => {
this.editData.storeName =
targetItem?.optionList?.find(
(item) => item.mainMerchantId === value
)?.mainMerchantName || "";
},
},
{
label: "备注信息",
name: "remark",
type: "input",
inputType: "textarea",
maxlength: 200,
rows: 4,
showLimit: true,
placeholder: "请输入",
},
],
poolFormData: [
{
label: "锁定时长",
name: "lockTime",
type: "slot",
addHtml: "lockTimeSlot",
},
{
label: "选择群聊",
name: "groupChatIds",
type: "slot",
addHtml: "groupChatIdsSlot",
},
{
label: "",
name: "groupList",
type: "slot",
addHtml: "groupListSlot",
},
],
dialogVisible: false,
baseData: {
storeList: [],
},
};
},
beforeRouteEnter(to, from, next) {
console.log(to.query.optType)
to.meta.title = to.query.optType == 'update' ? '修改群活码' : '创建群活码'
next()
},
mounted() {
const { optType, id } = this.$route.query;
const promises = [this.getStoreList()];
if (optType === "update") {
promises.push(this.getDetail(id));
}
Promise.all(promises).then(() => {
if (optType === "update" && this.editData.storeId) {
const storeExists = this.baseData.storeList.some(
(item) => item.mainMerchantId == this.editData.storeId
);
if (!storeExists) {
this.editData.storeId = "";
this.editData.storeName = "";
}
}
});
},
methods: {
getDetail(id) {
return getLiveCodeDetail({ id }).then((res) => {
const data = res || {};
const groupChatIds = deepClone(data.groupList || []);
const deteleAttrList = ["groupList", "groupCount", "idleGroupCount"];
deteleAttrList.forEach((item) => {
delete data[item];
});
this.editData = Object.assign({}, this.editData, data, {
groupChatIds,
});
this.editData.storeId = this.editData.storeId + "";
});
},
getOptionsList(formName, hasAll = true, refreshSigle) {
if (refreshSigle) {
var item = this[formName].find((k) => k.name == refreshSigle);
var index = this[formName].findIndex((k) => k.name == refreshSigle);
this.$set(
this[formName][index],
"optionList",
deepClone(this.baseData[item.optionsName])
);
if (
hasAll &&
this.baseData[item.optionsName].length &&
this.baseData[item.optionsName][0][
this[formName][index].optionLabel
] !== "全部"
) {
const temp = {};
temp[this[formName][index].optionId] = "";
temp[this[formName][index].optionLabel] = "全部";
this[formName][index].optionList.unshift(temp);
}
} else {
this[formName].forEach((item, index) => {
if (
item.type === "select" &&
this.baseData[item.optionsName].length
) {
this.$set(
this[formName][index],
"optionList",
deepClone(this.baseData[item.optionsName])
);
if (
hasAll &&
this.baseData[item.optionsName].length &&
this.baseData[item.optionsName][0][
this[formName][index].optionLabel
] !== "全部"
) {
const temp = {};
temp[this[formName][index].optionId] = "";
temp[this[formName][index].optionLabel] = "全部";
this[formName][index].optionList.unshift(temp);
}
}
});
}
console.log(this.baseFormData, "----");
},
getStoreList() {
return getCarDealerList().then((res) => {
this.baseData.storeList = res || [];
console.log(this.baseData.storeList);
this.getOptionsList("baseFormData", false, "storeId");
});
},
handleLockTimeChange() {
// 触发锁定时长校验
if (this.$refs.poolFormRef && this.$refs.poolFormRef.$refs.poolChildRef) {
this.$refs.poolFormRef.$refs.poolChildRef.validateField("lockTime");
}
},
handleAddGroupChat() {
this.dialogVisible = true;
},
handleGroupConfirm(selectedGroups) {
this.editData.groupChatIds = selectedGroups;
if (this.$refs.poolFormRef && this.$refs.poolFormRef.$refs.poolChildRef) {
this.$refs.poolFormRef.$refs.poolChildRef.clearValidate("groupChatIds");
}
},
handleRemoveGroup(index) {
console.log(this.editData.groupChatIds, index);
this.editData.groupChatIds.splice(index, 1);
if (this.editData.groupChatIds.length === 0) {
this.$refs.poolFormRef.$refs.poolChildRef.validateField("groupChatIds");
}
},
handleConfirm() {
if (this.loading) return;
const p1 = new Promise((resolve) => {
this.$refs.baseFormRef.$refs.baseChildRef.validate((valid) => {
resolve(valid);
});
});
const p2 = new Promise((resolve) => {
this.$refs.poolFormRef.$refs.poolChildRef.validate((valid) => {
resolve(valid);
});
});
// 并发校验基础信息和群池配置
Promise.all([p1, p2]).then((results) => {
if (results.every((res) => res)) {
this.loading = true;
const params = deepClone(this.editData);
// 组装提交数据
const groupChatIds = params.groupChatIds.map((item) => {
return {
groupChatId: item.groupChatId,
groupChatName: item.groupChatName,
};
});
const payload = {
...params,
groupChatIds,
};
const requestApi =
this.$route.query.optType === "update"
? updateLiveCode
: addLiveCode;
requestApi(payload)
.then((res) => {
let { code, data, msg } = res.data;
code == 0 ? this.$message.success("操作成功") : this.$message.error(msg || "操作失败");
if (code == 0) {
this.handleCancel();
}
})
.finally(() => {
this.loading = false;
});
}
});
},
handleCancel() {
this.$router.push({
name: "oneCustomerOneGroup"
})
},
},
};
</script>
<style lang="scss" scoped>
::v-deep .d2-container-full {
bottom: 60px !important;
}
.edit-page.edit-tmpl {
background: #ffffff;
padding-bottom: 20px;
.title {
height: 50px;
line-height: 50px;
padding: 0 20px;
border-bottom: 1px solid #e5e5e5;
font-size: 16px;
font-weight: 600;
color: #333333;
.sub-title {
font-size: 14px;
color: #999999;
font-weight: 400;
margin-left: 10px;
}
}
}
.content-box {
padding: 20px 20px 0;
background: #ffffff;
}
.tip-text {
font-size: 12px;
color: #999999;
margin-top: 8px;
line-height: 1.5;
}
.group-list {
margin-left: 150px;
border-radius: 4px;
border: 1px solid #e5e5e5;
padding: 8px;
}
/* 底部提交/取消按钮固定样式 */
.footer {
position: fixed;
bottom: 0px;
left: 50%;
text-align: center;
padding: 10px;
z-index: 100;
}
</style>