Browse Source

feat: 企微助手 - 群活码 - 详情&复制交互逻辑&接口联调

zhengxy 2 years ago
parent
commit
0a1e95b0e4

+ 10 - 0
project/src/components/assembly/screen/customerService.vue

@@ -157,6 +157,16 @@ export default {
157 157
 
158 158
   },
159 159
   methods: {
160
+    // 执行一遍组件的created方法(拓展组件 群活码详情用)
161
+    handleCreatedFn() {
162
+      if (this.userList.length == 0) {
163
+        this.init()
164
+      } else {
165
+        this.selectUser = JSON.parse(JSON.stringify(this.final_result));
166
+        this.changeSelect()
167
+        this.afferent_init()
168
+      }
169
+    },
160 170
     afferent_init () {//从外面传入
161 171
       let selectUser = [];
162 172
       if (this.afferent_users && this.afferent_users.length > 0) {

+ 76 - 2
project/src/components/groupCode/createGroupCode.vue

@@ -153,6 +153,7 @@ import dialogGroup from './components/dialogGroup.vue'
153 153
 import chatGroupOptions from './components/chatGroupOptions.vue'
154 154
 import selfCustomerservice from '@/components/assembly/screen/customerService.vue'
155 155
 import Sortable from 'sortablejs'
156
+import _lodash from 'lodash'
156 157
 
157 158
 export default {
158 159
   name: "createGroupCode",
@@ -173,14 +174,18 @@ export default {
173 174
         is_limit: 0, // 渠道群管理(是否设置群上限)
174 175
         user_list: [], // 客服(生效成员) 数组回显 'a,b' => ['a', 'b']
175 176
         leading_words: '', // 引导话术
176
-      }
177
+      },
178
+      rule_id: this.$route.query.id || '', // 群活码id
179
+      detailFromApi: Object.freeze({}), // 后端返回的详情完整数据
177 180
     }
178 181
   },
179 182
   computed: {
183
+    // 当前操作是否为"编辑"
180 184
     isEdit() {
181 185
       const { id = '', type = '' } = this.$route.query
182 186
       return id && type === 'edit'
183 187
     },
188
+    // 当前操作是否为"复制"
184 189
     isCopy() {
185 190
       const { id = '', type = '' } = this.$route.query
186 191
       return id && type === 'copy'
@@ -189,12 +194,74 @@ export default {
189 194
   created() {
190 195
     // 获取分组列表
191 196
     this.handleGetGroupOptions()
197
+    console.log('isEdit => ', this.isEdit)
198
+    console.log('isCopy => ', this.isCopy)
199
+    // 编辑、复制 => 获取群活码详情
200
+    if (this.isEdit || this.isCopy) {
201
+      this.handleGetDetail()
202
+    }
192 203
   },
193 204
   mounted() {
194 205
     // 表格行拖拽
195 206
 	  this.handleRowDrop()
196 207
   },
197 208
   methods: {
209
+    // 获取群活码详情数据
210
+    async handleGetDetail() {
211
+      console.log('handleGetDetail => ')
212
+      try {
213
+        this.loading = true
214
+        const { data: res = {} } = await this.$axios.get(this.URL.BASEURL + this.URL.groupCode_ruleDetail, {
215
+          params: { rule_id: this.rule_id }
216
+        })
217
+        if (res && res.errno == 0) {
218
+          const { rst = {} } = res
219
+          // 备份接口数据
220
+          this.detailFromApi = Object.freeze(_lodash.cloneDeep(rst))
221
+          // 回显数据
222
+          this.setGroupFormData(rst)
223
+        } else if (res.errno != 4002) {
224
+          this.$message.warning(res.err)
225
+          this.$router.go(-1)
226
+        }
227
+      } catch (error) {
228
+        console.log('error => ', error)
229
+        this.loading = false
230
+      } finally {
231
+        // this.loading = false
232
+      }
233
+    },
234
+    // 回显详情数据
235
+    async setGroupFormData(detail) {
236
+      try {
237
+        // 基础属性回显
238
+        const keys = ['name', 'group_id', 'chat_id_list', 'join_type', 'is_limit', 'leading_words']
239
+        keys.forEach(k => {
240
+          this.groupForm[k] = detail[k]
241
+        })
242
+
243
+        // 回显生效成员
244
+        this.groupForm.user_list = detail.user_list.split(',')
245
+        await this.$nextTick()
246
+        this.$refs.selfKefu && this.$refs.selfKefu.handleCreatedFn()
247
+
248
+        // 回显群聊列表"群名称"
249
+        const { data: res = {} } = await this.$axios.get(this.URL.BASEURL + this.URL.groupCode_chatGroupList, {
250
+          params: { keyword: '' }
251
+        })
252
+        if (res && res.errno == 0 && Array.isArray(res.rst)) {
253
+          detail.chat_id_list.forEach((item, idx) => {
254
+            const isFound = res.rst.find(chat => chat.chat_id === item.chat_id)
255
+            if (isFound) detail.chat_id_list[idx].name = isFound.name
256
+          })
257
+          this.groupForm.chat_id_list = [...detail.chat_id_list]
258
+        }
259
+      } catch (error) {
260
+        console.log('error => ', error)
261
+      } finally {
262
+        this.loading = false
263
+      }
264
+    },
198 265
     // 注册表格行拖拽事件
199 266
     handleRowDrop() {
200 267
       const tbody = document.querySelector('.el-table__body-wrapper tbody')
@@ -272,6 +339,13 @@ export default {
272 339
     handleGetParams() {
273 340
       const url = `${this.URL.BASEURL}${this.URL[this.isEdit ? 'groupCode_editRule' : 'groupCode_setRule']}`
274 341
       const { name, group_id, join_type, is_limit, user_list, leading_words, chat_id_list } = this.groupForm
342
+
343
+      // 删除后端返回的 sort 属性
344
+      const chatIdList = chat_id_list.map(c => {
345
+        delete c.sort
346
+        return {...c}
347
+      })
348
+
275 349
       const params = {
276 350
         name,
277 351
         group_id,
@@ -279,7 +353,7 @@ export default {
279 353
         is_limit,
280 354
         user_list: user_list.join(','),
281 355
         leading_words,
282
-        chat_id_list: JSON.stringify(chat_id_list),
356
+        chat_id_list: JSON.stringify(chatIdList),
283 357
       }
284 358
 
285 359
       return { url, params }

+ 8 - 2
project/src/components/groupCode/index.vue

@@ -192,11 +192,17 @@ export default {
192 192
     },
193 193
     // 编辑
194 194
     editCode(id){
195
-      this.$router.push({path:'/createChannelCode',query: {id:id}})
195
+      this.$router.push({
196
+        path: '/createGroupCode',
197
+        query: { id, type: 'edit' }
198
+      })
196 199
     },
197 200
     // 复制
198 201
     copyCode(id){
199
-      this.$router.push({path:'/createChannelCode',query: {id:id,type:'copy'}})
202
+      this.$router.push({
203
+        path: '/createGroupCode',
204
+        query: { id, type: 'copy' }
205
+      })
200 206
     },
201 207
     // 下载
202 208
     downloadIamge(imgsrc, imgname){