Просмотр исходного кода

批量添加标签和批量移除标签

xw 3 недель назад
Родитель
Сommit
f091e08116
2 измененных файлов с 361 добавлено и 78 удалено
  1. 161 46
      src/views/qw/externalContact/index.vue
  2. 200 32
      src/views/qw/externalContact/myExternalContact.vue

+ 161 - 46
src/views/qw/externalContact/index.vue

@@ -337,6 +337,15 @@
           @click="delUserTag"
           v-hasPermi="['qw:externalContact:delTag']"
         >批量移除标签</el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="primary"
+          plain
+          size="mini"
+          @click="delUserTagFilter"
+          v-hasPermi="['qw:externalContact:delTag']"
+        >批量移除标签(筛选条件)</el-button>
       </el-col>
 	  <el-col :span="1.5">
 	    <el-button
@@ -368,6 +377,12 @@
     <el-table v-loading="loading" :data="externalContactList" @selection-change="handleSelectionChange" border>
       <el-table-column type="selection" width="55" align="center" />
       <el-table-column label="企微客户ID" align="center" prop="id" />
+      <el-table-column label="用户id" align="center" prop="fsUserId" width="100px">
+        <template slot-scope="scope">
+          <span v-if="scope.row.fsUserId">{{ scope.row.fsUserId }}</span>
+          <span v-else>未绑定</span>
+        </template>
+      </el-table-column>
       <el-table-column label="企微客户头像" align="center" prop="avatar" width="100px">
         <template slot-scope="scope">
           <el-popover
@@ -1687,7 +1702,28 @@ export default {
       }, 200);
 
       this.tagDelOpen = true;
+      this.tagFilter = false;
+
+    },
+
+    delUserTagFilter(){
+
+      if(this.externalContactList.length == 0){
+        return  this.$message('无可移除标签客户');
+      }
+
+      this.getPageListTagGroup();
+
+      setTimeout(() => {
+        for (let i = 0; i < this.tagGroupList.length; i++) {
+          for (let x = 0; x < this.tagGroupList[i].tag.length; x++) {
+            this.tagGroupList[i].tag[x].isSelected=false;
+          }
+        }
+      }, 200);
 
+      this.tagDelOpen = true;
+      this.tagFilter = true;
     },
 
 
@@ -1856,7 +1892,7 @@ export default {
       };
     },
     addTagSubmitForm(){
-
+      this.addTagForm.tagIds = [];
       for (let i = 0; i < this.tagGroupList.length; i++) {
         for (let x = 0; x < this.tagGroupList[i].tag.length; x++) {
           if(this.tagGroupList[i].tag[x].isSelected==true){
@@ -1868,23 +1904,6 @@ export default {
         return  this.$message('请选择标签');
       }
 
-      this.addTagForm.corpId=this.queryParams.corpId
-      this.addTagForm.userIds=this.ids;
-      this.addTagForm.filter = this.tagFilter;
-
-      // 修改这里:正确处理参数对象
-      let obj = JSON.parse(JSON.stringify(this.queryParams));
-
-      // 将逗号分隔的字符串转换为数组
-      if(obj.tagIds && typeof obj.tagIds === 'string') {
-        obj.tagIds = obj.tagIds.split(",");
-      }
-      if(obj.outTagIds && typeof obj.outTagIds === 'string') {
-        obj.outTagIds = obj.outTagIds.split(",");
-      }
-
-      this.addTagForm.param = obj;
-
       let loadingRock = this.$loading({
         lock: true,
         text: '正在执行中请稍后~~请不要刷新页面!!',
@@ -1892,24 +1911,87 @@ export default {
         background: 'rgba(0, 0, 0, 0.7)'
       });
 
+      const runAdd = (userIds) => {
+        this.addTagForm.corpId=this.queryParams.corpId
+        this.addTagForm.filter = this.tagFilter;
+        this.addTagForm.userIds = userIds;
 
-      addTag(this.addTagForm).then(response => {
-       this.msgSuccess(response.msg);
-       this.tagOpen = false;
-        loadingRock.close();
-       this.addTagForm={
-        filter: false,
-        addType: 0,
-        userIds:[],
-        tagIds:[]
-       };
-       this.getList()
-     }).finally(res=>{
-        loadingRock.close();
-      });
+        let obj = JSON.parse(JSON.stringify(this.queryParams));
+        if(obj.tagIds && typeof obj.tagIds === 'string') {
+          obj.tagIds = obj.tagIds.split(",");
+        }
+        if(obj.outTagIds && typeof obj.outTagIds === 'string') {
+          obj.outTagIds = obj.outTagIds.split(",");
+        }
+        this.addTagForm.param = obj;
+
+        addTag(this.addTagForm).then(response => {
+         this.msgSuccess(response.msg);
+         this.tagOpen = false;
+         this.addTagForm={
+          filter: false,
+          addType: 0,
+          userIds:[],
+          tagIds:[]
+         };
+         this.getList()
+       }).finally(()=>{
+          loadingRock.close();
+        });
+      };
 
+      if (this.tagFilter) {
+        this.fetchAllContactIdsByCurrentFilter().then(ids => {
+          if (!ids || !ids.length) {
+            this.$message.warning('当前筛选条件下没有可处理的客户');
+            loadingRock.close();
+            return;
+          }
+          runAdd(ids);
+        }).catch(() => {
+          loadingRock.close();
+        });
+      } else {
+        if (this.ids == null || this.ids === '' || (Array.isArray(this.ids) && this.ids.length === 0)) {
+          this.$message('请选择需要添加标签的客户');
+          loadingRock.close();
+          return;
+        }
+        runAdd(this.ids);
+      }
+
+    },
+    /** 按当前筛选条件分页拉取全部企微客户主键 id,供批量添加、移除标签传入 userIds */
+    fetchAllContactIdsByCurrentFilter() {
+      const { qwUserName, ...queryParams } = this.queryParams;
+      const obj = JSON.parse(JSON.stringify(queryParams));
+      if (obj.tagIds && typeof obj.tagIds === 'string') {
+        obj.tagIds = obj.tagIds.split(',');
+      }
+      if (obj.outTagIds && typeof obj.outTagIds === 'string') {
+        obj.outTagIds = obj.outTagIds.split(',');
+      }
+      const pageSize = 500;
+      const allIds = [];
+      const fetchNext = (pageNum) => {
+        return listExternalContact({ ...obj, pageNum, pageSize }).then(res => {
+          const rows = res.rows || [];
+          const total = res.total != null ? res.total : 0;
+          rows.forEach(r => {
+            if (r.id != null) {
+              allIds.push(r.id);
+            }
+          });
+          if (allIds.length >= total || rows.length < pageSize) {
+            return allIds;
+          }
+          return fetchNext(pageNum + 1);
+        });
+      };
+      return fetchNext(1);
     },
     tagDelSubmitForm(){
+      this.addTagForm.tagIds = [];
       for (let i = 0; i < this.tagGroupList.length; i++) {
         for (let x = 0; x < this.tagGroupList[i].tag.length; x++) {
           if(this.tagGroupList[i].tag[x].isSelected==true){
@@ -1921,8 +2003,6 @@ export default {
       if(this.addTagForm.tagIds==[]||this.addTagForm.tagIds==null||this.addTagForm.tagIds==""){
         return  this.$message('请选择标签');
       }
-       this.addTagForm.corpId=this.queryParams.corpId
-      this.addTagForm.userIds=this.ids;
 
       let loadingRock = this.$loading({
         lock: true,
@@ -1931,19 +2011,54 @@ export default {
         background: 'rgba(0, 0, 0, 0.7)'
       });
 
+      const runDel = (userIds) => {
+        this.addTagForm.corpId=this.queryParams.corpId
+        this.addTagForm.filter = this.tagFilter;
+        this.addTagForm.userIds = userIds;
 
-      delTag(this.addTagForm).then(response => {
-       this.msgSuccess(response.msg);
-       this.tagDelOpen = false;
-        loadingRock.close();
-       this.addTagForm={
-         userIds:[],
-         tagIds:[]
-       };
-       this.getList()
-     }).finally(res=>{
-        loadingRock.close();
-      });
+        let obj = JSON.parse(JSON.stringify(this.queryParams));
+        if(obj.tagIds && typeof obj.tagIds === 'string') {
+          obj.tagIds = obj.tagIds.split(",");
+        }
+        if(obj.outTagIds && typeof obj.outTagIds === 'string') {
+          obj.outTagIds = obj.outTagIds.split(",");
+        }
+        this.addTagForm.param = obj;
+
+        delTag(this.addTagForm).then(response => {
+         this.msgSuccess(response.msg);
+         this.tagDelOpen = false;
+         this.addTagForm={
+           filter: false,
+           addType: 0,
+           userIds:[],
+           tagIds:[]
+         };
+         this.getList()
+       }).finally(()=>{
+          loadingRock.close();
+        });
+      };
+
+      if (this.tagFilter) {
+        this.fetchAllContactIdsByCurrentFilter().then(ids => {
+          if (!ids || !ids.length) {
+            this.$message.warning('当前筛选条件下没有可处理的客户');
+            loadingRock.close();
+            return;
+          }
+          runDel(ids);
+        }).catch(() => {
+          loadingRock.close();
+        });
+      } else {
+        if (this.ids == null || this.ids === '' || (Array.isArray(this.ids) && this.ids.length === 0)) {
+          this.$message('请选择需要移除标签的客户');
+          loadingRock.close();
+          return;
+        }
+        runDel(this.ids);
+      }
     },
 
     // 表单重置

+ 200 - 32
src/views/qw/externalContact/myExternalContact.vue

@@ -293,6 +293,15 @@
           v-hasPermi="['qw:externalContact:myAddTag']"
         >批量添加标签</el-button>
       </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="primary"
+          plain
+          size="mini"
+          @click="addUserTagFilter"
+          v-hasPermi="['qw:externalContact:myAddTag']"
+        >批量添加标签(筛选条件)</el-button>
+      </el-col>
       <el-col :span="1.5">
         <el-button
           type="primary"
@@ -301,6 +310,15 @@
           @click="delUserTag"
           v-hasPermi="['qw:externalContact:myDelTag']"
         >批量移除标签</el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="primary"
+          plain
+          size="mini"
+          @click="delUserTagFilter"
+          v-hasPermi="['qw:externalContact:myDelTag']"
+        >批量移除标签(筛选条件)</el-button>
       </el-col>
 	  <el-col :span="1.5">
 	    <el-button
@@ -341,6 +359,12 @@
     <el-table v-loading="loading" :data="externalContactList" @selection-change="handleSelectionChange" border>
       <el-table-column type="selection" width="55" align="center" />
       <el-table-column label="企微客户ID" align="center" prop="id"/>
+      <el-table-column label="用户id" align="center" prop="fsUserId" width="100px">
+        <template slot-scope="scope">
+          <span v-if="scope.row.fsUserId">{{ scope.row.fsUserId }}</span>
+          <span v-else>未绑定</span>
+        </template>
+      </el-table-column>
       <el-table-column label="企微客户头像" align="center" prop="avatar" width="100px">
         <template slot-scope="scope">
           <el-popover
@@ -1241,7 +1265,9 @@ export default {
 
       addTagForm:{
         userIds:[],
-        tagIds:[]
+        tagIds:[],
+        filter: false,
+        addType: 0,
       },
 
       myQwCompanyList:[],
@@ -1338,6 +1364,7 @@ export default {
       },
 
       tagTotal:0,
+      tagFilter:false,
 
       //标签
       changeTagDialog:{
@@ -1894,9 +1921,32 @@ export default {
       }, 200);
 
       this.tagOpen = true;
+      this.tagFilter = false;
 
     },
 
+    addUserTagFilter(){
+
+      if(this.externalContactList.length == 0){
+        return  this.$message('无可添加标签客户');
+      }
+
+      this.getPageListTagGroup();
+
+      setTimeout(() => {
+
+        for (let i = 0; i < this.tagGroupList.length; i++) {
+          for (let x = 0; x < this.tagGroupList[i].tag.length; x++) {
+            this.tagGroupList[i].tag[x].isSelected=false;
+          }
+        }
+      }, 200);
+
+
+      this.tagOpen = true;
+      this.tagFilter = true;
+    },
+
     delUserTag(){
 
       if(this.ids==null||this.ids==""){
@@ -1914,7 +1964,28 @@ export default {
       }, 200);
 
       this.tagDelOpen = true;
+      this.tagFilter = false;
+
+    },
+
+    delUserTagFilter(){
+
+      if(this.externalContactList.length == 0){
+        return  this.$message('无可移除标签客户');
+      }
+
+      this.getPageListTagGroup();
+
+      setTimeout(() => {
+        for (let i = 0; i < this.tagGroupList.length; i++) {
+          for (let x = 0; x < this.tagGroupList[i].tag.length; x++) {
+            this.tagGroupList[i].tag[x].isSelected=false;
+          }
+        }
+      }, 200);
 
+      this.tagDelOpen = true;
+      this.tagFilter = true;
     },
 
     //重新获取页面数据
@@ -1958,6 +2029,8 @@ export default {
       this.tagOpen = false;
 
       this.addTagForm={
+        filter: false,
+        addType: 0,
         userIds:[],
         tagIds:[]
       };
@@ -1967,12 +2040,14 @@ export default {
       this.tagDelOpen = false;
 
       this.addTagForm={
+        filter: false,
+        addType: 0,
         userIds:[],
         tagIds:[]
       };
     },
     addTagSubmitForm(){
-
+      this.addTagForm.tagIds = [];
       for (let i = 0; i < this.tagGroupList.length; i++) {
         for (let x = 0; x < this.tagGroupList[i].tag.length; x++) {
           if(this.tagGroupList[i].tag[x].isSelected==true){
@@ -1985,10 +2060,6 @@ export default {
         return  this.$message('请选择标签');
       }
 
-      this.addTagForm.corpId=this.queryParams.corpId
-      this.addTagForm.userIds=this.ids;
-
-
       let loadingRock = this.$loading({
         lock: true,
         text: '正在执行中请稍后~~请不要刷新页面!!',
@@ -1996,22 +2067,86 @@ export default {
         background: 'rgba(0, 0, 0, 0.7)'
       });
 
+      const runAdd = (userIds) => {
+        this.addTagForm.corpId=this.queryParams.corpId
+        this.addTagForm.filter = this.tagFilter;
+        this.addTagForm.userIds = userIds;
 
-      addTag(this.addTagForm).then(response => {
-       this.msgSuccess(response.msg);
-       this.tagOpen = false;
-        loadingRock.close();
-       this.addTagForm={
-         userIds:[],
-         tagIds:[]
-       };
-       this.getList()
-     }).finally(res=>{
-        loadingRock.close();
-      });
+        let obj = JSON.parse(JSON.stringify(this.queryParams));
+        if(obj.tagIds && typeof obj.tagIds === 'string') {
+          obj.tagIds = obj.tagIds.split(",");
+        }
+        if(obj.outTagIds && typeof obj.outTagIds === 'string') {
+          obj.outTagIds = obj.outTagIds.split(",");
+        }
+        this.addTagForm.param = obj;
+
+        addTag(this.addTagForm).then(response => {
+         this.msgSuccess(response.msg);
+         this.tagOpen = false;
+         this.addTagForm={
+          filter: false,
+          addType: 0,
+          userIds:[],
+          tagIds:[]
+         };
+         this.getList()
+       }).finally(()=>{
+          loadingRock.close();
+        });
+      };
 
+      if (this.tagFilter) {
+        this.fetchAllContactIdsByCurrentFilter().then(ids => {
+          if (!ids || !ids.length) {
+            this.$message.warning('当前筛选条件下没有可处理的客户');
+            loadingRock.close();
+            return;
+          }
+          runAdd(ids);
+        }).catch(() => {
+          loadingRock.close();
+        });
+      } else {
+        if (this.ids == null || this.ids === '' || (Array.isArray(this.ids) && this.ids.length === 0)) {
+          this.$message('请选择需要添加标签的客户');
+          loadingRock.close();
+          return;
+        }
+        runAdd(this.ids);
+      }
+
+    },
+    /** 按当前筛选条件分页拉取全部企微客户主键 id,供批量添加、移除标签传入 userIds */
+    fetchAllContactIdsByCurrentFilter() {
+      const obj = JSON.parse(JSON.stringify(this.queryParams));
+      if (obj.tagIds && typeof obj.tagIds === 'string') {
+        obj.tagIds = obj.tagIds.split(',');
+      }
+      if (obj.outTagIds && typeof obj.outTagIds === 'string') {
+        obj.outTagIds = obj.outTagIds.split(',');
+      }
+      const pageSize = 500;
+      const allIds = [];
+      const fetchNext = (pageNum) => {
+        return myList({ ...obj, pageNum, pageSize }).then(res => {
+          const rows = res.rows || [];
+          const total = res.total != null ? res.total : 0;
+          rows.forEach(r => {
+            if (r.id != null) {
+              allIds.push(r.id);
+            }
+          });
+          if (allIds.length >= total || rows.length < pageSize) {
+            return allIds;
+          }
+          return fetchNext(pageNum + 1);
+        });
+      };
+      return fetchNext(1);
     },
     tagDelSubmitForm(){
+      this.addTagForm.tagIds = [];
       for (let i = 0; i < this.tagGroupList.length; i++) {
         for (let x = 0; x < this.tagGroupList[i].tag.length; x++) {
           if(this.tagGroupList[i].tag[x].isSelected==true){
@@ -2023,8 +2158,6 @@ export default {
       if(this.addTagForm.tagIds==[]||this.addTagForm.tagIds==null||this.addTagForm.tagIds==""){
         return  this.$message('请选择标签');
       }
-       this.addTagForm.corpId=this.queryParams.corpId
-      this.addTagForm.userIds=this.ids;
 
       let loadingRock = this.$loading({
         lock: true,
@@ -2033,19 +2166,54 @@ export default {
         background: 'rgba(0, 0, 0, 0.7)'
       });
 
+      const runDel = (userIds) => {
+        this.addTagForm.corpId=this.queryParams.corpId
+        this.addTagForm.filter = this.tagFilter;
+        this.addTagForm.userIds = userIds;
 
-      delTag(this.addTagForm).then(response => {
-       this.msgSuccess(response.msg);
-       this.tagDelOpen = false;
-        loadingRock.close();
-       this.addTagForm={
-         userIds:[],
-         tagIds:[]
-       };
-       this.getList()
-     }).finally(res=>{
-        loadingRock.close();
-      });
+        let obj = JSON.parse(JSON.stringify(this.queryParams));
+        if(obj.tagIds && typeof obj.tagIds === 'string') {
+          obj.tagIds = obj.tagIds.split(",");
+        }
+        if(obj.outTagIds && typeof obj.outTagIds === 'string') {
+          obj.outTagIds = obj.outTagIds.split(",");
+        }
+        this.addTagForm.param = obj;
+
+        delTag(this.addTagForm).then(response => {
+         this.msgSuccess(response.msg);
+         this.tagDelOpen = false;
+         this.addTagForm={
+          filter: false,
+          addType: 0,
+           userIds:[],
+           tagIds:[]
+         };
+         this.getList()
+       }).finally(()=>{
+          loadingRock.close();
+        });
+      };
+
+      if (this.tagFilter) {
+        this.fetchAllContactIdsByCurrentFilter().then(ids => {
+          if (!ids || !ids.length) {
+            this.$message.warning('当前筛选条件下没有可处理的客户');
+            loadingRock.close();
+            return;
+          }
+          runDel(ids);
+        }).catch(() => {
+          loadingRock.close();
+        });
+      } else {
+        if (this.ids == null || this.ids === '' || (Array.isArray(this.ids) && this.ids.length === 0)) {
+          this.$message('请选择需要移除标签的客户');
+          loadingRock.close();
+          return;
+        }
+        runDel(this.ids);
+      }
     },
 
     // 表单重置