Browse Source

feat: 客户群发 - 多主体成员选择弹框组件

zhengxy 1 year ago
parent
commit
e8ef2941cd
1 changed files with 23 additions and 13 deletions
  1. 23 13
      project/src/components/assembly/screen/customerServiceCorpV2.vue

+ 23 - 13
project/src/components/assembly/screen/customerServiceCorpV2.vue

@@ -56,7 +56,7 @@
56 56
           <div class="title">已选择的成员</div>
57 57
           <div class="choice_result_top">
58 58
             <div class="clear" @click="closeUser(-1)">全部清空</div>
59
-            <div class="result_num">已选择<span>{{selectUser&&selectUser.length}}</span>人</div>
59
+            <div class="result_num">已选择<span>{{selectedCorpList&&selectedCorpList.length}}</span>个主体<span>{{selectUser&&selectUser.length}}</span>名成员</div>
60 60
           </div>
61 61
           <div class="member_result self-scrollbar-3">
62 62
 
@@ -93,6 +93,8 @@
93 93
 <script>
94 94
 // 此组件是按照企业
95 95
 import selfInput from '@/components/assembly/screen/input.vue'
96
+import _lodash from 'lodash'
97
+
96 98
 export default {
97 99
   components: { selfInput },
98 100
   props: {
@@ -257,13 +259,16 @@ export default {
257 259
         return
258 260
       }
259 261
       this.visible = false
260
-      this.$emit('customerDefine', this.selectUser)
262
+      this.$emit('customerDefine', { // 2种数据格式都传给父组件 不同场景选择使用
263
+        res_format_1: this.selectUser,
264
+        res_format_2: this.selectedCorpList,
265
+      })
261 266
     },
262 267
     userSearch () {//模糊搜索
263 268
       let search_user_list = []
264 269
       this.old_user_list.forEach((item) => {
265 270
         let arr = item.user_list.filter((v) => {
266
-          return v.name && v.name.indexOf(this.input_keyword) != -1
271
+          return (v.name && v.name.indexOf(this.input_keyword) != -1) || (v.corp_name && v.corp_name.indexOf(this.input_keyword) != -1)
267 272
         })
268 273
         if (arr && arr.length > 0) {
269 274
           let self_item = JSON.parse(JSON.stringify(item))
@@ -274,7 +279,11 @@ export default {
274 279
       this.userList = search_user_list;
275 280
       let userTotal = 0;
276 281
       this.userList.forEach((item) => {
277
-        item.is_open = false//是否折叠
282
+        if (this.input_keyword === '') {
283
+          item.is_open = true//是否折叠
284
+        } else {
285
+          item.is_open = false//是否折叠
286
+        }
278 287
         item.is_select = false//是否选中
279 288
         item.user_list.forEach((item1) => {
280 289
           item1.is_select = false
@@ -305,7 +314,7 @@ export default {
305 314
           let userTotal = 0;
306 315
           this.userList.forEach((item) => {
307 316
             userTotal += item.user_list.length;
308
-            item.is_open = false//是否折叠
317
+            item.is_open = true//是否折叠   默认收起
309 318
             item.is_select = false//是否选中
310 319
             item.user_list.forEach((item1) => {
311 320
               item1.is_select = false
@@ -350,7 +359,7 @@ export default {
350 359
         let brr = user_arr.user_list[user_index]
351 360
         if (brr.is_select) {
352 361
           selectUser = selectUser.filter((v) => {
353
-            return v.user_id != brr.user_id
362
+            return `${v.corpid}&&&${v.user_id}` != `${brr.corpid}&&&${brr.user_id}`
354 363
           })
355 364
         } else {
356 365
           selectUser.push(brr)
@@ -360,9 +369,11 @@ export default {
360 369
       // 去重
361 370
       let tmp = {};
362 371
       selectUser = selectUser.reduce((list, item) => {
363
-        tmp[item.user_id] ? '' : (tmp[item.user_id] = list.push(item));
372
+        // 根据corpid和user_id去重(之前版本只判断user_id去重)
373
+        tmp[`${item.corpid}&&&${item.user_id}`] ? '' : (tmp[`${item.corpid}&&&${item.user_id}`] = list.push(item));
364 374
         return list
365 375
       }, []);
376
+
366 377
       this.selectUser = selectUser
367 378
       this.changeSelect()
368 379
     },
@@ -377,7 +388,7 @@ export default {
377 388
         })
378 389
         this.userList.forEach((main) => {
379 390
           if (main.corpid == item.corpid) {
380
-            if (item.user_list.length == main.user_list.length) {
391
+            if ((item.user_list.length == main.user_list.length) && (item.user_list.length !== 0)) {
381 392
               main.is_select = true
382 393
             } else {
383 394
               main.is_select = false
@@ -398,7 +409,6 @@ export default {
398 409
       })
399 410
     },
400 411
     closeUser (item) {
401
-      console.log('item => ', item)
402 412
       if (item == -1) {
403 413
         this.selectUser = []
404 414
       } else {
@@ -410,11 +420,11 @@ export default {
410 420
       this.changeSelect()
411 421
     },
412 422
     onClickDelSelectedCorp(currentCorp) {
413
-      this.selectUser.forEach((s, idx) => {
414
-        if (s.corpid === currentCorp.corpid) {
415
-          this.selectUser.splice(idx, 1)
416
-        }
423
+      const res = []
424
+      this.selectUser.forEach(s => {
425
+        if (s.corpid !== currentCorp.corpid) res.push(s)
417 426
       })
427
+      this.selectUser = [...res]
418 428
       this.changeSelect()
419 429
     },
420 430
   }