Browse Source

feat: 授权管理 - 分配账号

zhengxy 1 year ago
parent
commit
ec15103125

+ 3 - 0
project/src/assets/config/interface_api.js

@@ -476,6 +476,9 @@ var api = {
476 476
   orderPercent_list: '/api/order/getShareInProportionConf', // 分成比例配置 - 配置列表
477 477
   orderPercent_setConf: '/api/order/setShareInProportionConf', // 分成比例配置 - 编辑
478 478
 
479
+  authority_bindUser: '/api/admin/corpBindMultipleUser', // 授权管理 - 批量分配账号
480
+  authority_getBindUser: '/api/admin/getCorpBindUserList', // 授权管理 - 获取已分配结果
481
+
479 482
 };
480 483
 
481 484
 export { api };

+ 35 - 2
project/src/components/manage/authorityManage.vue

@@ -28,6 +28,7 @@
28 28
               <div class="corpName">{{item.corp_name?item.corp_name:item.corp_full_name?item.corp_full_name:item.corp_full_name}}</div>
29 29
               <div class="created_at">{{item.created_at}}</div>
30 30
               <button class="refresh_button" @click="resetCorp(item)">同步</button>
31
+              <button class="refresh_button w-75" @click="onClickBindAccount(item)">分配账号</button>
31 32
             </div>
32 33
           </div>
33 34
         </div>
@@ -45,13 +46,26 @@
45 46
     <el-dialog title="企微授权" :visible.sync="authorizeFalg" width="400px" center>
46 47
       <authorize></authorize>
47 48
     </el-dialog>
49
+
50
+    <!-- 分配账号 -->
51
+    <bindAccountDialog
52
+      :dialogVisible="bindAccountVisible"
53
+      :id="currentId"
54
+      @confirm="onConfirmBindAccount"
55
+      @cancel="onCancelBindAccount"
56
+    />
48 57
   </div>
49 58
 </template>
50 59
 <script>
51 60
 import authorize from './authorize.vue'
52 61
 import selfInput from '@/components/assembly/screen/input.vue'
62
+import bindAccountDialog from './bindAccountDialog.vue'
53 63
 export default {
54
-  components: { selfInput, authorize },
64
+  components: {
65
+    selfInput,
66
+    authorize,
67
+    bindAccountDialog,
68
+  },
55 69
   data () {
56 70
     return {
57 71
       type: 1,
@@ -66,7 +80,10 @@ export default {
66 80
       gzhData: [],
67 81
       bindTsFlag: false,
68 82
       tsFalg: false,
69
-      tsData: {}
83
+      tsData: {},
84
+
85
+      bindAccountVisible: false,
86
+      currentId: '',
70 87
     }
71 88
   },
72 89
   created () {
@@ -201,6 +218,19 @@ export default {
201 218
         this.init(val)
202 219
       }
203 220
     },
221
+
222
+    // 监听点击“分配账号”
223
+    onClickBindAccount(corp) {
224
+      this.currentId = corp.id
225
+      this.bindAccountVisible = true
226
+    },
227
+    onConfirmBindAccount() {
228
+      this.init()
229
+      this.bindAccountVisible = false
230
+    },
231
+    onCancelBindAccount() {
232
+      this.bindAccountVisible = false
233
+    },
204 234
   }
205 235
 }
206 236
 </script>
@@ -270,6 +300,9 @@ export default {
270 300
       font-size: 15px;
271 301
       border: none;
272 302
       margin-top: 10px;
303
+      &.w-75 {
304
+        width: 75px;
305
+      }
273 306
     }
274 307
     .corpName {
275 308
       color: #44546b;

+ 259 - 0
project/src/components/manage/bindAccountDialog.vue

@@ -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>