|
@@ -0,0 +1,259 @@
|
|
1
|
+<template>
|
|
2
|
+ <el-dialog
|
|
3
|
+ :visible.sync="dialogVisible"
|
|
4
|
+ :before-close="handleCancel"
|
|
5
|
+ class="bindAccount-dialog"
|
|
6
|
+ :title="title"
|
|
7
|
+ width="550px"
|
|
8
|
+ :close-on-click-modal="false"
|
|
9
|
+ >
|
|
10
|
+ <div class="form-wrap" v-loading="loading">
|
|
11
|
+ <div class="form-item flex-start">
|
|
12
|
+ <span class="lable required">账号</span>
|
|
13
|
+ <div class="account-wrap">
|
|
14
|
+ <el-select
|
|
15
|
+ v-model="form.user_id_list"
|
|
16
|
+ size="small" placeholder="请选择账号"
|
|
17
|
+ clearable filterable multiple collapse-tags
|
|
18
|
+ @change="onChangeUserIdList"
|
|
19
|
+ >
|
|
20
|
+ <el-option v-for="item in accountOptions" :key="item.id" :label="item.name" :value="item.id" />
|
|
21
|
+ </el-select>
|
|
22
|
+ <div class="user-wrap" v-if="form.user_info_list && form.user_info_list.length">
|
|
23
|
+ <el-tag
|
|
24
|
+ class="user-item-wrap"
|
|
25
|
+ v-for="(user, userIdx) in form.user_info_list"
|
|
26
|
+ :key="user.id"
|
|
27
|
+ closable
|
|
28
|
+ disable-transitions
|
|
29
|
+ @close="onCloseUserTag(userIdx)"
|
|
30
|
+ >
|
|
31
|
+ {{ user.name }}
|
|
32
|
+ </el-tag>
|
|
33
|
+ </div>
|
|
34
|
+ </div>
|
|
35
|
+ </div>
|
|
36
|
+ </div>
|
|
37
|
+ <div slot="footer" class="dialog-footer">
|
|
38
|
+ <el-button size="mini" @click="handleCancel">取 消</el-button>
|
|
39
|
+ <el-button size="mini" type="primary" @click="handleConfirm" :disabled="loading">确 定</el-button>
|
|
40
|
+ </div>
|
|
41
|
+ </el-dialog>
|
|
42
|
+</template>
|
|
43
|
+
|
|
44
|
+<script>
|
|
45
|
+export default {
|
|
46
|
+ name: "bindAccountDialog",
|
|
47
|
+ props: {
|
|
48
|
+ // 控制弹框是否显示
|
|
49
|
+ dialogVisible: {
|
|
50
|
+ type: Boolean,
|
|
51
|
+ default: () => false
|
|
52
|
+ },
|
|
53
|
+ id: {
|
|
54
|
+ type: Number | String,
|
|
55
|
+ default: () => '',
|
|
56
|
+ },
|
|
57
|
+ },
|
|
58
|
+ data() {
|
|
59
|
+ return {
|
|
60
|
+ loading: false,
|
|
61
|
+ accountOptions: [], // ADQ投放账号选项
|
|
62
|
+ allAccountInfo: [],
|
|
63
|
+ form: {
|
|
64
|
+ user_id_list: [],
|
|
65
|
+ user_info_list: [],
|
|
66
|
+ }
|
|
67
|
+
|
|
68
|
+ }
|
|
69
|
+ },
|
|
70
|
+ computed: {
|
|
71
|
+ title() {
|
|
72
|
+ return `分配账号`
|
|
73
|
+ },
|
|
74
|
+ },
|
|
75
|
+ watch: {
|
|
76
|
+ dialogVisible(isShow) {
|
|
77
|
+ if (isShow) {
|
|
78
|
+ // 获取账号选项列表
|
|
79
|
+ this.handleGetOptions()
|
|
80
|
+ // 获取表单数据
|
|
81
|
+ this.handleGetFormData()
|
|
82
|
+ }
|
|
83
|
+ },
|
|
84
|
+ },
|
|
85
|
+ methods: {
|
|
86
|
+ // 获取账号选项列表
|
|
87
|
+ async handleGetOptions() {
|
|
88
|
+ const { data: res = {} } = await this.$axios.get(this.URL.BASEURL + this.URL.manager_list, {
|
|
89
|
+ params: {
|
|
90
|
+ page: 1,
|
|
91
|
+ page_size: 500
|
|
92
|
+ }
|
|
93
|
+ })
|
|
94
|
+ if (res && res.errno == 0) {
|
|
95
|
+ this.accountOptions = res.rst.data
|
|
96
|
+ } else if (res.errno != 4002) {
|
|
97
|
+ this.$message.warning(res.err)
|
|
98
|
+ }
|
|
99
|
+ },
|
|
100
|
+ async handleConfirm() {
|
|
101
|
+ try {
|
|
102
|
+ // 表单校验
|
|
103
|
+ await this.handleFormValidate()
|
|
104
|
+ const url = `${this.URL.BASEURL}${this.URL.authority_bindUser}`
|
|
105
|
+ const params = {
|
|
106
|
+ id: this.id,
|
|
107
|
+ user_id_list: JSON.stringify(this.form.user_id_list),
|
|
108
|
+ }
|
|
109
|
+ this.loading = true
|
|
110
|
+ const { data: res = {} } = await this.$axios.post(url, params)
|
|
111
|
+ if (res && res.errno == 0) {
|
|
112
|
+ this.$message.success('操作成功')
|
|
113
|
+ this.handleClearFormData()
|
|
114
|
+ this.$emit('confirm')
|
|
115
|
+ } else if (res.errno != 4002) {
|
|
116
|
+ this.$message.warning(res.err || '操作失败')
|
|
117
|
+ }
|
|
118
|
+ } catch (error) {
|
|
119
|
+ console.log('error => ', error)
|
|
120
|
+ } finally {
|
|
121
|
+ this.loading = false
|
|
122
|
+ }
|
|
123
|
+ },
|
|
124
|
+ handleCancel() {
|
|
125
|
+ this.handleClearFormData()
|
|
126
|
+ this.$emit('cancel')
|
|
127
|
+ },
|
|
128
|
+ // 执行表单校验
|
|
129
|
+ handleFormValidate() {
|
|
130
|
+ return new Promise((resolve, reject) => {
|
|
131
|
+ if (!this.form.user_id_list || !this.form.user_id_list.length) {
|
|
132
|
+ this.$message.warning('请选择账号')
|
|
133
|
+ reject('表单校验未通过')
|
|
134
|
+ } else {
|
|
135
|
+ resolve('表单校验通过')
|
|
136
|
+ }
|
|
137
|
+ })
|
|
138
|
+ },
|
|
139
|
+ // 获取表单数据
|
|
140
|
+ async handleGetFormData() {
|
|
141
|
+ try {
|
|
142
|
+ // 表单校验
|
|
143
|
+ const url = `${this.URL.BASEURL}${this.URL.authority_getBindUser}`
|
|
144
|
+ const params = { id: this.id }
|
|
145
|
+ this.loading = true
|
|
146
|
+ const { data: res = {} } = await this.$axios.get(url, { params })
|
|
147
|
+ if (res && res.errno == 0) {
|
|
148
|
+ this.form.user_id_list = res.rst.map(user => user.user_id)
|
|
149
|
+ this.form.user_info_list = res.rst.map(user => ({
|
|
150
|
+ id: user.user_id,
|
|
151
|
+ name: user.user_name,
|
|
152
|
+ }))
|
|
153
|
+ } else if (res.errno != 4002) {
|
|
154
|
+ this.$message.warning(res.err || '操作失败')
|
|
155
|
+ }
|
|
156
|
+ } catch (error) {
|
|
157
|
+ console.log('error => ', error)
|
|
158
|
+ } finally {
|
|
159
|
+ this.loading = false
|
|
160
|
+ }
|
|
161
|
+ },
|
|
162
|
+ // 清空弹框表单数据
|
|
163
|
+ handleClearFormData() {
|
|
164
|
+ this.form.user_id_list = []
|
|
165
|
+ this.handleGetUserInfoList([])
|
|
166
|
+ },
|
|
167
|
+ onCloseUserTag(idx) {
|
|
168
|
+ const currentId = this.form.user_info_list[idx].id
|
|
169
|
+ const userIdIdx = this.form.user_id_list.findIndex(id => id === currentId)
|
|
170
|
+ this.form.user_id_list.splice(userIdIdx, 1)
|
|
171
|
+ this.form.user_info_list.splice(idx, 1)
|
|
172
|
+ },
|
|
173
|
+ onChangeUserIdList(val) {
|
|
174
|
+ this.form.user_id_list = [...val]
|
|
175
|
+ this.handleGetUserInfoList(val)
|
|
176
|
+ },
|
|
177
|
+ handleGetUserInfoList(user_id_list) {
|
|
178
|
+ if (!user_id_list || !user_id_list.length) {
|
|
179
|
+ this.form.user_info_list = []
|
|
180
|
+ return false
|
|
181
|
+ }
|
|
182
|
+ this.allAccountInfo = [...this.form.user_info_list, ...this.accountOptions]
|
|
183
|
+ const user_info_list = []
|
|
184
|
+ user_id_list.forEach(userId => {
|
|
185
|
+ const accountInfo = this.allAccountInfo.find(account => account.id === userId)
|
|
186
|
+ if (accountInfo) user_info_list.push(accountInfo)
|
|
187
|
+ })
|
|
188
|
+ this.form.user_info_list = [...user_info_list]
|
|
189
|
+ },
|
|
190
|
+ },
|
|
191
|
+};
|
|
192
|
+</script>
|
|
193
|
+
|
|
194
|
+<style lang="scss" scoped>
|
|
195
|
+.bindAccount-dialog {
|
|
196
|
+ .form-wrap {
|
|
197
|
+ padding: 0 20px 0 10px;
|
|
198
|
+ min-height: 100px;
|
|
199
|
+ .form-item {
|
|
200
|
+ display: flex;
|
|
201
|
+ align-items: center;
|
|
202
|
+ margin-top: 16px;
|
|
203
|
+ &.flex-start {
|
|
204
|
+ align-items: flex-start;
|
|
205
|
+ .lable {
|
|
206
|
+ margin-top: 6px;
|
|
207
|
+ }
|
|
208
|
+ }
|
|
209
|
+ &:first-child {
|
|
210
|
+ margin-top: 0;
|
|
211
|
+ }
|
|
212
|
+ .lable {
|
|
213
|
+ width: 60px;
|
|
214
|
+ font-weight: 500;
|
|
215
|
+ flex-shrink: 0;
|
|
216
|
+
|
|
217
|
+ &.required {
|
|
218
|
+ position: relative;
|
|
219
|
+ &::before {
|
|
220
|
+ position: absolute;
|
|
221
|
+ left: -8px;
|
|
222
|
+ top: 0;
|
|
223
|
+ content: "*";
|
|
224
|
+ color: #f56c6c;
|
|
225
|
+ }
|
|
226
|
+ }
|
|
227
|
+ }
|
|
228
|
+ /deep/ .el-select {
|
|
229
|
+ width: 100%;
|
|
230
|
+ }
|
|
231
|
+
|
|
232
|
+ .account-wrap {
|
|
233
|
+ flex: 1;
|
|
234
|
+ .user-wrap {
|
|
235
|
+ box-sizing: border-box;
|
|
236
|
+ width: 100%;
|
|
237
|
+ background-color: rgb(247, 247, 247);
|
|
238
|
+ margin-top: 10px;
|
|
239
|
+ padding: 10px 10px 0 10px;
|
|
240
|
+ display: flex;
|
|
241
|
+ align-items: center;
|
|
242
|
+ flex-wrap: wrap;
|
|
243
|
+ .user-item-wrap {
|
|
244
|
+ margin: 0 14px 10px 0;
|
|
245
|
+ }
|
|
246
|
+ }
|
|
247
|
+ }
|
|
248
|
+ }
|
|
249
|
+ .form-tips {
|
|
250
|
+ margin: 5px 0 0 80px;
|
|
251
|
+ font-size: 13px;
|
|
252
|
+ color: #999;
|
|
253
|
+ }
|
|
254
|
+ }
|
|
255
|
+ .dialog-footer {
|
|
256
|
+ text-align: center;
|
|
257
|
+ }
|
|
258
|
+}
|
|
259
|
+</style>
|