Browse Source

feat: 智能推送 - v3

zhengxy 1 year ago
parent
commit
d4ab6bbe7c
2 changed files with 126 additions and 63 deletions
  1. 19 0
      project/src/assets/js/common.js
  2. 107 63
      project/src/components/smartPushV3/createMassMsg.vue

+ 19 - 0
project/src/assets/js/common.js

279
   }
279
   }
280
   return total <= 0 ? "0%" : (`${Math.round(num / total * 10000) / 100.00}%`); // 小数点后两位百分比
280
   return total <= 0 ? "0%" : (`${Math.round(num / total * 10000) / 100.00}%`); // 小数点后两位百分比
281
 }
281
 }
282
+
283
+// 判断的是否是JSON字符串
284
+export const isJSON=(str)=>{
285
+	if (typeof str == 'string') {
286
+	      try {
287
+	        var obj = JSON.parse(str);
288
+			// 等于这个条件说明就是JSON字符串 会返回true
289
+	        if (typeof obj == 'object' && obj) {
290
+	          return true;
291
+	        } else {
292
+				//不是就返回false
293
+	          return false;
294
+	        }
295
+	      } catch (e) {
296
+	        return false;
297
+	      }
298
+	    }
299
+	    return false;
300
+}

+ 107 - 63
project/src/components/smartPushV3/createMassMsg.vue

175
 import screenPay from '@/components/assembly/screen/pay.vue'
175
 import screenPay from '@/components/assembly/screen/pay.vue'
176
 import pushGroupDialog from './pushGroupDialog.vue'
176
 import pushGroupDialog from './pushGroupDialog.vue'
177
 import _lodash from 'lodash'
177
 import _lodash from 'lodash'
178
-import { getIntegerNumber } from '@/assets/js/common'
178
+import { getIntegerNumber, isJSON } from '@/assets/js/common'
179
 
179
 
180
 export default {
180
 export default {
181
   components: { selfChannel, selfCustomerservice, customerServiceCorpV2, datePicker, enterpriseTag, editCon, screenPay, pushGroupDialog },
181
   components: { selfChannel, selfCustomerservice, customerServiceCorpV2, datePicker, enterpriseTag, editCon, screenPay, pushGroupDialog },
271
         this.loading = false
271
         this.loading = false
272
         this.isShowEditCon = true
272
         this.isShowEditCon = true
273
         if (res && res.errno == 0) {
273
         if (res && res.errno == 0) {
274
+          console.log('res.rst => ', res.rst)
274
           // 备份接口数据
275
           // 备份接口数据
275
           this.detailFromApi = Object.freeze(_lodash.cloneDeep(res.rst))
276
           this.detailFromApi = Object.freeze(_lodash.cloneDeep(res.rst))
276
 
277
 
277
           // 数据回显
278
           // 数据回显
278
-          this.user_id_list = res.rst.senders ? res.rst.senders.split(',') : [];
279
-          if (res.rst.senders && res.rst.senders.length > 0) {//有值代表部分员工
280
-            this.is_all = 0
279
+          if (this.operate_type == 1) {
280
+            this.user_id_list = (res.rst.senders && !isJSON(res.rst.senders)) ? res.rst.senders.split(',') : [];
281
+            if (res.rst.senders && res.rst.senders.length > 0) {//有值代表部分员工
282
+              this.is_all = 0
283
+            }
281
           }
284
           }
285
+
282
           this.gender = res.rst.gender ? res.rst.gender.split(',') : [];
286
           this.gender = res.rst.gender ? res.rst.gender.split(',') : [];
283
           this.payInfo = {
287
           this.payInfo = {
284
             pay_status: res.rst.pay_status,
288
             pay_status: res.rst.pay_status,
297
           this.operate_type = res.rst.operate_type ? res.rst.operate_type : 1
301
           this.operate_type = res.rst.operate_type ? res.rst.operate_type : 1
298
           this.is_operation = (res.rst.is_operation || res.rst.is_operation === 0) ? res.rst.is_operation : 1
302
           this.is_operation = (res.rst.is_operation || res.rst.is_operation === 0) ? res.rst.is_operation : 1
299
           this.operator_group_id = res.rst.operator_group_id ? res.rst.operator_group_id : ''
303
           this.operator_group_id = res.rst.operator_group_id ? res.rst.operator_group_id : ''
300
-          if (this.operate_type == 2 && this.is_operation == 0 && Array.isArray(res.rst.multiple_senders)) {
301
-            this.multiple_senders = [...res.rst.multiple_senders]
304
+          if (this.operate_type == 2 && this.is_operation == 0 && Array.isArray(JSON.parse(res.rst.multiple_senders))) {
305
+            const multiple_senders = JSON.parse(res.rst.multiple_senders)
306
+            this.multiple_senders = [...multiple_senders]
302
             const arr = []
307
             const arr = []
303
-            res.rst.multiple_senders.forEach(corp => {
308
+            multiple_senders.forEach(corp => {
304
               if (corp && corp.user_list && Array.isArray(corp.user_list)) {
309
               if (corp && corp.user_list && Array.isArray(corp.user_list)) {
305
                 corp.user_list.forEach(userId => {
310
                 corp.user_list.forEach(userId => {
306
                   arr.push({
311
                   arr.push({
348
           })
353
           })
349
         }
354
         }
350
       }).catch((err) => {
355
       }).catch((err) => {
356
+        console.log('err => ', err)
351
         this.loading = false
357
         this.loading = false
352
         this.isShowEditCon = true
358
         this.isShowEditCon = true
353
       });
359
       });
407
         return
413
         return
408
       }
414
       }
409
 
415
 
410
-      let params = {
411
-        name: this.name,
412
-        is_all: this.is_all,
413
-        // 单主体时传 senders
414
-        senders: (this.operate_type == 1 && this.is_all == 0) ? this.user_id_list.join(',') : '',
415
-        content: this.content,
416
-        attachments: this.attachments == '' || this.attachments.length == 0 ? '' : JSON.stringify(this.attachments),
417
-        gender: this.gender && this.gender.join(','),
418
-        send_conf: JSON.stringify(this.send_conf),
419
-        pay_status: this.payInfo.pay_status || this.payInfo.pay_status == 0 ? this.payInfo.pay_status : '',
420
-        pay_num_min: this.payInfo.pay_num_min || this.payInfo.pay_num_min == 0 ? Number(this.payInfo.pay_num_min) : '',
421
-        pay_num_max: this.payInfo.pay_num_max || this.payInfo.pay_num_max == 0 ? Number(this.payInfo.pay_num_max) : '',
422
-
423
-        operate_type: this.operate_type,
424
-        is_operation: this.operate_type == 1 ? 0 : this.is_operation, // 单主体模式 该字段传0
425
-        operator_group_id: (this.operate_type == 2 && this.is_operation == 1) ? this.operator_group_id : '',
426
-        multiple_senders: (this.operate_type == 2 && this.is_operation == 0 && this.multiple_senders.length) ? JSON.stringify(this.multiple_senders) : '',
427
-
428
-        group_id: this.group_id ? this.group_id : 0,
429
-      }
430
 
416
 
431
-      if (this.operate_type == 1) { // 单主体支持标签 多主体不支持
432
-        params.tag_screen_type = this.tag_info && this.tag_info.tag_type ? this.tag_info.tag_type : 0
433
-        params.tag_list = this.tag_info && this.tag_info.tag_id_list ? this.tag_info.tag_id_list.join(',') : ''
434
-        params.exclude_tag_list = this.exclude_tag_info && this.exclude_tag_info.tag_id_list ? this.exclude_tag_info.tag_id_list.join(',') : ''
435
-      }
417
+      let params = this.handleGetParams()
436
 
418
 
437
       if (this.isCopy) {
419
       if (this.isCopy) {
438
         const isSameParams = this.handleGetIsSameParams(params)
420
         const isSameParams = this.handleGetIsSameParams(params)
421
+        console.log('isSameParams => ', isSameParams)
439
         if (isSameParams) {
422
         if (isSameParams) {
440
           this.$message.warning('推送规则及内容重复!')
423
           this.$message.warning('推送规则及内容重复!')
441
           return
424
           return
492
       });
475
       });
493
     },
476
     },
494
 
477
 
495
-    // 复制操作 => 获取当前规则未修改时的参数
496
-    handleGetOldParams() {
497
-      let oldParams = {
478
+    // 根据当前页面视图 获取参数
479
+    handleGetParams() {
480
+      let params = {
498
         name: this.name,
481
         name: this.name,
499
         is_all: this.is_all,
482
         is_all: this.is_all,
500
-        senders: this.is_all == 0 ? this.user_id_list.join(',') : '',
483
+        // 单主体时传 senders
484
+        senders: (this.operate_type == 1 && this.is_all == 0) ? this.user_id_list.join(',') : '',
501
         content: this.content,
485
         content: this.content,
502
         attachments: this.attachments == '' || this.attachments.length == 0 ? '' : JSON.stringify(this.attachments),
486
         attachments: this.attachments == '' || this.attachments.length == 0 ? '' : JSON.stringify(this.attachments),
503
         gender: this.gender && this.gender.join(','),
487
         gender: this.gender && this.gender.join(','),
504
         send_conf: JSON.stringify(this.send_conf),
488
         send_conf: JSON.stringify(this.send_conf),
505
-        tag_screen_type: this.tag_info && this.tag_info.tag_type ? this.tag_info.tag_type : 0,
506
-        tag_list: this.tag_info && this.tag_info.tag_id_list ? this.tag_info.tag_id_list.join(',') : '',
507
-        exclude_tag_list: this.exclude_tag_info && this.exclude_tag_info.tag_id_list ? this.exclude_tag_info.tag_id_list.join(',') : '',
508
         pay_status: this.payInfo.pay_status || this.payInfo.pay_status == 0 ? this.payInfo.pay_status : '',
489
         pay_status: this.payInfo.pay_status || this.payInfo.pay_status == 0 ? this.payInfo.pay_status : '',
509
         pay_num_min: this.payInfo.pay_num_min || this.payInfo.pay_num_min == 0 ? Number(this.payInfo.pay_num_min) : '',
490
         pay_num_min: this.payInfo.pay_num_min || this.payInfo.pay_num_min == 0 ? Number(this.payInfo.pay_num_min) : '',
510
         pay_num_max: this.payInfo.pay_num_max || this.payInfo.pay_num_max == 0 ? Number(this.payInfo.pay_num_max) : '',
491
         pay_num_max: this.payInfo.pay_num_max || this.payInfo.pay_num_max == 0 ? Number(this.payInfo.pay_num_max) : '',
492
+
493
+        operate_type: this.operate_type,
494
+        is_operation: this.operate_type == 1 ? 0 : this.is_operation, // 单主体模式 该字段传0
495
+        operator_group_id: (this.operate_type == 2 && this.is_operation == 1) ? this.operator_group_id : '',
496
+        multiple_senders: (this.operate_type == 2 && this.is_operation == 0 && this.multiple_senders.length) ? JSON.stringify(this.multiple_senders) : '',
497
+
498
+        group_id: this.group_id ? this.group_id : 0,
511
       }
499
       }
500
+
501
+      if (this.operate_type == 1) { // 单主体支持标签 多主体不支持
502
+        params.tag_screen_type = this.tag_info && this.tag_info.tag_type ? this.tag_info.tag_type : 0
503
+        params.tag_list = this.tag_info && this.tag_info.tag_id_list ? this.tag_info.tag_id_list.join(',') : ''
504
+        params.exclude_tag_list = this.exclude_tag_info && this.exclude_tag_info.tag_id_list ? this.exclude_tag_info.tag_id_list.join(',') : ''
505
+      }
506
+
507
+      return JSON.parse(JSON.stringify(params))
508
+    },
509
+
510
+    // 复制操作 => 获取当前规则未修改时的参数
511
+    handleGetOldParams() {
512
+      let oldParams = this.handleGetParams()
512
       this.oldParams = JSON.parse(JSON.stringify(oldParams))
513
       this.oldParams = JSON.parse(JSON.stringify(oldParams))
513
     },
514
     },
514
     handleGetIsSameParams(newParams) {
515
     handleGetIsSameParams(newParams) {
516
+      console.log('newParams => ', JSON.parse(JSON.stringify(newParams)))
517
+      console.log('oldParams => ', JSON.parse(JSON.stringify(this.oldParams)))
518
+
515
       let isSameParams = true
519
       let isSameParams = true
516
       // 先比较“非多选”的属性
520
       // 先比较“非多选”的属性
517
       const _newParams = JSON.parse(JSON.stringify(newParams))
521
       const _newParams = JSON.parse(JSON.stringify(newParams))
519
       delete _newParams.gender
523
       delete _newParams.gender
520
       delete _newParams.tag_list
524
       delete _newParams.tag_list
521
       delete _newParams.exclude_tag_list
525
       delete _newParams.exclude_tag_list
526
+      delete _newParams.multiple_senders
527
+      console.log('_newParams => ', _newParams)
522
 
528
 
523
       const _oldParams = JSON.parse(JSON.stringify(this.oldParams))
529
       const _oldParams = JSON.parse(JSON.stringify(this.oldParams))
524
       delete _oldParams.senders
530
       delete _oldParams.senders
525
       delete _oldParams.gender
531
       delete _oldParams.gender
526
       delete _oldParams.tag_list
532
       delete _oldParams.tag_list
527
       delete _oldParams.exclude_tag_list
533
       delete _oldParams.exclude_tag_list
534
+      delete _oldParams.multiple_senders
535
+      console.log('_oldParams => ', _oldParams)
528
 
536
 
529
       const isEqual = _lodash.isEqual(_newParams, _oldParams)
537
       const isEqual = _lodash.isEqual(_newParams, _oldParams)
538
+      console.log('isEqual => ', isEqual)
530
       if (!isEqual) { // “非多选”的属性不相同 => 直接返回结果
539
       if (!isEqual) { // “非多选”的属性不相同 => 直接返回结果
531
         isSameParams = false
540
         isSameParams = false
532
       } else { // “非多选”的属性相同 => 比较"多选项"属性
541
       } else { // “非多选”的属性相同 => 比较"多选项"属性
533
-        const { senders, gender, tag_list, exclude_tag_list } = newParams
534
-        // 使用员工
535
-        if (senders.length !== this.oldParams.senders.length) {
536
-          isSameParams = false
537
-        } else {
538
-          const isNotSameS = senders.split(',').some(item => !this.oldParams.senders.includes(item))
539
-          if (isNotSameS) {
542
+        const { senders, gender, tag_list, exclude_tag_list, operate_type, is_operation, multiple_senders } = newParams
543
+
544
+        if (operate_type == 1) { // 单企微模式
545
+          // 使用员工
546
+          if (senders.length !== this.oldParams.senders.length) {
540
             isSameParams = false
547
             isSameParams = false
548
+          } else {
549
+            const isNotSameS = senders.split(',').some(item => !this.oldParams.senders.includes(item))
550
+            if (isNotSameS) {
551
+              isSameParams = false
552
+            }
541
           }
553
           }
542
-        }
543
 
554
 
544
-        // 规则配置 => 性别
545
-        if (gender.length !== this.oldParams.gender.length) {
546
-          isSameParams = false
547
-        } else {
548
-          const isNotSameG = gender.split(',').some(item => !this.oldParams.gender.includes(item))
549
-          if (isNotSameG) {
555
+          // 规则配置 => 标签
556
+          if (tag_list.length !== this.oldParams.tag_list.length) {
550
             isSameParams = false
557
             isSameParams = false
558
+          } else {
559
+            const isNotSameTG = tag_list.split(',').some(item => !this.oldParams.tag_list.includes(item))
560
+            if (isNotSameTG) {
561
+              isSameParams = false
562
+            }
563
+          }
564
+
565
+          // 规则配置 => 排除客户
566
+          if (exclude_tag_list.length !== this.oldParams.exclude_tag_list.length) {
567
+            isSameParams = false
568
+          } else {
569
+            const isNotSameETL = exclude_tag_list.split(',').some(item => !this.oldParams.exclude_tag_list.includes(item))
570
+            if (isNotSameETL) {
571
+              isSameParams = false
572
+            }
551
           }
573
           }
552
         }
574
         }
553
 
575
 
554
-        // 规则配置 => 标签
555
-        if (tag_list.length !== this.oldParams.tag_list.length) {
556
-          isSameParams = false
557
-        } else {
558
-          const isNotSameTG = tag_list.split(',').some(item => !this.oldParams.tag_list.includes(item))
559
-          if (isNotSameTG) {
576
+        if (operate_type == 2 && is_operation != 1) { // 多企微模式 - 使用员工
577
+          if (multiple_senders.length !== this.oldParams.multiple_senders.length) {
560
             isSameParams = false
578
             isSameParams = false
579
+          } else {
580
+            const multiple_senders = JSON.parse(newParams.multiple_senders)
581
+            const old_multiple_senders = JSON.parse(this.oldParams.multiple_senders)
582
+            console.log('multiple_senders => ', multiple_senders)
583
+            console.log('old_multiple_senders => ', old_multiple_senders)
584
+
585
+            // 判断企微主体是否相同
586
+            const corpids = multiple_senders.map(m => m.corpid)
587
+            const old_corpids = old_multiple_senders.map(m => m.corpid)
588
+            const isNotSameCorp = corpids.some(item => !old_corpids.includes(item))
589
+            if (isNotSameCorp) {
590
+              isSameParams = false
591
+            }
592
+
593
+            // 判断相同企微主体下的客服人员是否相同
594
+            multiple_senders.forEach(m => {
595
+              const new_user_list = m.user_list
596
+              const new_corpid = m.corpid
597
+              const old_corp = old_multiple_senders.find(o => o.corpid === new_corpid)
598
+              if (old_corp) {
599
+                const isNotSameUser = new_user_list.some(item => !old_corp.user_list.includes(item))
600
+                if (isNotSameUser) {
601
+                  isSameParams = false
602
+                }
603
+              }
604
+            })
561
           }
605
           }
562
         }
606
         }
563
 
607
 
564
-        // 规则配置 => 排除客户
565
-        if (exclude_tag_list.length !== this.oldParams.exclude_tag_list.length) {
608
+        // 规则配置 => 性别
609
+        if (gender.length !== this.oldParams.gender.length) {
566
           isSameParams = false
610
           isSameParams = false
567
         } else {
611
         } else {
568
-          const isNotSameETL = exclude_tag_list.split(',').some(item => !this.oldParams.exclude_tag_list.includes(item))
569
-          if (isNotSameETL) {
612
+          const isNotSameG = gender.split(',').some(item => !this.oldParams.gender.includes(item))
613
+          if (isNotSameG) {
570
             isSameParams = false
614
             isSameParams = false
571
           }
615
           }
572
         }
616
         }