aev.vue
5.33 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
<template>
<div class="flex" v-loading="loading">
<el-form :model="form" ref="form" :rules="rules" label-width="100px" class="g-card fxauto mr20">
<el-form-item label="活码名称" prop="taskName">
<el-input v-model="form.taskName" maxlength="30" show-word-limit placeholder="请输入名称" clearable />
</el-form-item>
<el-form-item label="关键词" prop="keywords">
<el-input
v-model="form.keywords"
placeholder="请输入关键词,多个词用英文逗号分隔,每个词不超过10个字"
clearable></el-input>
</el-form-item>
<el-form-item label="加群引导语" prop="welcomeMsg">
<TextareaExtend
v-model="form.welcomeMsg"
maxlength="220"
show-word-limit
:autosize="{ minRows: 5, maxRows: 20 }"
placeholder="请输入加群引导语"
clearable />
</el-form-item>
<el-form-item label="选择群活码" prop="groupCodeId">
<el-image
style="width: 160px; height: 160px"
v-if="groupQrCode && groupQrCode.codeUrl"
:src="groupQrCode.codeUrl"
class="code-image"></el-image>
<el-button
type="primary"
plain
class="ml10"
icon="el-icon-plus"
size="mini"
@click="dialogVisibleSelectQrCode = true">
{{ groupQrCode && groupQrCode.codeUrl ? '修改' : '添加' }}
</el-button>
</el-form-item>
<el-form-item label=" ">
<el-button type="primary" @click="submit">保存</el-button>
<el-button @click="$router.back()">取消</el-button>
</el-form-item>
</el-form>
<div class="preview-wrap g-card mt0">
<!-- 预览 -->
<PhoneDialog
:message="form.welcomeMsg || '请输入加群引导语'"
:isOther="groupQrCode && groupQrCode.codeUrl ? true : false">
<el-image style="border-radius: 6px; width: 100px" :src="groupQrCode.codeUrl"></el-image>
</PhoneDialog>
</div>
<SelectQrCode
:visible.sync="dialogVisibleSelectQrCode"
@success="submitSelectQrCode"
:selected="codes"></SelectQrCode>
</div>
</template>
<script>
import { getDetail, add, update } from '@/api/communityOperating/keywords'
import PhoneDialog from '@/components/PhoneDialog'
import SelectQrCode from '@/components/SelectQrCode'
export default {
components: { PhoneDialog, SelectQrCode },
data() {
return {
taskId: '',
dialogVisibleSelectQrCode: false,
loading: false, // 遮罩层
// 表单参数
form: {
taskName: '', // 任务名称
groupCodeId: '', // 群活码ID
welcomeMsg: '', // 欢迎语
keywords: '', // 关键词
},
codes: [],
groupQrCode: {},
rules: Object.freeze({
taskName: [{ required: true, message: '该项为必填项', trigger: 'blur' }],
welcomeMsg: [{ required: true, message: '该项为必填项', trigger: 'blur' }],
keywords: [{ required: true, message: '该项为必填项', trigger: 'blur' }],
groupCodeId: [{ required: true, message: '该项为必填项', trigger: 'change' }],
}),
}
},
created() {
this.taskId = this.$route.query.id
// this.$route.meta.title = (this.taskId ? '编辑' : '新建') + '关键词拉群'
this.taskId && this.getDetail(this.taskId)
},
methods: {
/** 获取详情 */
getDetail(id) {
this.loading = true
getDetail(id).then(({ data }) => {
this.form.taskName = data.taskName
this.form.welcomeMsg = data.welcomeMsg
// const keywordList = data.keywordList || []
// const keywords = keywordList.map((k) => k.keyword)
// this.form.keywords = keywords.join(',')
this.form.keywords = data.keywords
if (data.groupCodeInfo && data.groupCodeInfo.id) {
this.form.groupCodeId = data.groupCodeInfo.id
this.codes = [data.groupCodeInfo]
this.groupQrCode = data.groupCodeInfo
} else {
this.form.groupCodeId = ''
this.codes = []
this.groupQrCode = {}
}
this.loading = false
})
},
submit() {
this.$refs.form.validate((valid) => {
if (valid) {
this.loading = true
if (this.taskId) {
update(this.taskId, this.form)
.then(() => {
this.msgSuccess('更新成功')
this.loading = false
this.$router.back()
})
.catch(() => {
this.loading = false
})
} else {
add(this.form)
.then(() => {
this.msgSuccess('添加成功')
this.loading = false
this.$router.back()
})
.catch(() => {
this.loading = false
})
}
}
})
},
// 选择二维码确认按钮
submitSelectQrCode(data) {
this.groupQrCode = data
this.form.groupCodeId = data.id
this.$refs.form.validateField('groupCodeId')
},
},
}
</script>
<style lang="scss" scoped>
.el-form-item {
width: 500px;
}
.preview-wrap {
line-height: 26px;
}
.tip {
color: #999;
}
.welcome-input {
display: table;
width: 80%;
margin: 0 auto 20px;
}
.phone-dialog-image {
border-radius: 6px;
width: 100px;
}
</style>