Forráskód Böngészése

进销商筛选逻辑修改

suxinf 4 éve%!(EXTRA string=óta)
szülő
commit
148789fbf7

+ 91 - 73
src/views/data/UploadInfor.vue

@@ -95,25 +95,28 @@
         </div>
       </div>
     </form>
-    <div class="count" v-show="scope === '0'">
-      <Count :sum="sum" />
-    </div>
-    <div class="table" v-show="scope === '0'">
-      <UpLoadTable
-        :tableData="tableData"
-        @change_icon="changeIcon"
-        :pageSize="pageSize"
-        :currentPage="currentPage"
-      />
-    </div>
-    <div class="page" v-show="scope === '0'">
-      <Tablepage
-        :totalPage="totalPage"
-        :currentPage="currentPage"
-        @change_page="changePage"
-        @jump_page="jumpPage "
-      />
+    <div v-show="scope === '0'">
+      <div class="count">
+        <Count :sum="sum" />
+      </div>
+      <div class="table">
+        <UpLoadTable
+          :tableData="tableData"
+          @change_icon="changeIcon"
+          :pageSize="pageSize"
+          :currentPage="currentPage"
+        />
+      </div>
+      <div class="page" v-show="sum > 0">
+        <Tablepage
+          :totalPage="totalPage"
+          :currentPage="currentPage"
+          @change_page="changePage"
+          @jump_page="jumpPage"
+        />
+      </div>
     </div>
+
     <div class="uploadFile">
       <p>附件</p>
       <div class="fileDes">
@@ -215,10 +218,10 @@ export default {
     showOption() {
       this.optionFlag = !this.optionFlag;
     },
-    // 保证多选框区和其他的多选框互斥
+    // 保证多选框区和其他的多选框互斥
     clickCheckbox(i) {
       let list = this.checkedBoxList;
-      let include = list.indexOf("all");
+      let include = list.indexOf("东区");
       console.log(i, include);
       // if (i === 0) {
       //   this.checkedBoxList = [];
@@ -230,20 +233,22 @@ export default {
     },
     // 点击按区域添加button
     addByArea: function () {
-      let strReq = this.checkedBoxList.join(",");
-      let req = {
-        localArea: strReq
-      };
-      console.log(req,'按区域添加');
-      this.getAllDlr(req);
+      if (this.checkedBoxList.length !== 0) {
+        let strReq = this.checkedBoxList.join(",");
+        let req = {
+          localArea: strReq,
+        };
+        this.getAllDlr(req);
+      }
     },
     // 自定义添加
     addBySelf: function () {
-      let dataObj = {
-        queryParams: this.addByCustomize,
-      };
-      console.log(dataObj, '自定义添加入参');
-      this.getAllDlr(dataObj);
+      if (this.addByCustomize) {
+        let dataObj = {
+          queryParams: this.addByCustomize,
+        };
+        this.getAllDlr(dataObj, false, true);
+      }
     },
     // 按小组添加,增加小组
     addGroup: function (index) {
@@ -256,18 +261,21 @@ export default {
     // 点击按小组添加  添加按钮
     addByGroup: function () {
       this.addGroupList = [];
-      this.groupList.forEach(element => {
-        if(!element.flag){
+      this.groupList.forEach((element) => {
+        if (!element.flag) {
           this.addGroupList.push(element.id);
         }
       });
-      let strReq = this.addGroupList.join(",");
-      let req = {
-        groupId: strReq
+      if (this.addGroupList.length !== 0) {
+        let strReq = this.addGroupList.join(",");
+        let req = {
+          groupId: strReq,
+        };
+        this.getAllDlr(req);
+        this.optionFlag = false;
+      } else {
+        alert("没有选择一个或多个小组");
       }
-      console.log('点击按小组添加入参', req)
-      this.getAllDlr(req);
-      this.optionFlag = false;
     },
     // 筛选
     changeIcon: function (i) {
@@ -340,7 +348,7 @@ export default {
     // 获取文件名
     getFileInfo: function (event) {
       this.file = event.target.files;
-      console.log(this.file)
+      console.log(this.file);
       this.fileDes = [];
       this.file.forEach((item) => {
         this.fileDes.push(item.name);
@@ -361,10 +369,10 @@ export default {
     // 提交接口
     submitRequest: function () {
       let paramData = new FormData();
-      this.file.forEach((item)=>{
-          paramData.append("file", item);
-      })
-     
+      this.file.forEach((item) => {
+        paramData.append("file", item);
+      });
+
       paramData.append("dataName", this.inforName);
       paramData.append("dataDesc", this.inforDes);
       paramData.append("sourceTime", this.materialTime);
@@ -412,7 +420,7 @@ export default {
         });
     },
     // 获取所有经销商信息接口
-    getAllDlr: function (data = {}, flag) {
+    getAllDlr: function (data = {}, flag, addBySelfFlag) {
       this.$http({
         method: "post",
         url: "/sys/agent/selectAgentInfoPage",
@@ -421,27 +429,43 @@ export default {
         .then((res) => {
           console.log(res);
           this.tableData = [];
-          this.allDlr = [];
+          let nowSum = this.sum;
           if (res.data && res.data.code === 200) {
-            // 整合数据, 主要目的是加一个 flag,在用户点击筛选的时候,好判断
-            res.data.data.forEach((item) => {
-              this.allDlr.push({
-                id: item.id,
-                dlrCode: item.dlrCode,
-                dlrName: item.dlrName,
-                localArea: item.localArea,
-                flag: true,
-              });
-            });
-            this.sum = res.data.count;
-            this.tableData = this.allDlr.slice(0, this.pageSize);
-            // 获取自定义添加datalist下拉框的值
-            if (!flag) {
+            // created时,获取自定义添加datalist下拉框的值
+            if (flag) {
               this.dlrList = [];
-              this.allDlr.forEach((item) => {
+              let allDlrList = res.data.data;
+              allDlrList.forEach((item) => {
                 this.dlrList.push(item.dlrName);
                 this.dlrList.push(item.dlrCode);
               });
+            } else {
+              // 整合数据, 主要目的是加一个 flag,在用户点击筛选的时候,好判断
+              res.data.data.forEach((item) => {
+                this.allDlr.push({
+                  id: item.id,
+                  dlrCode: item.dlrCode,
+                  dlrName: item.dlrName,
+                  localArea: item.localArea,
+                  flag: true,
+                });
+              });
+              // 去重
+              let hash = {};
+              this.allDlr = this.allDlr.reduce(function (item, next) {
+                hash[next.id] ? "" : (hash[next.id] = true && item.push(next));
+                return item;
+              }, []);
+              this.sum = this.allDlr.length;
+              // 添加以后跳到最后一页
+              this.currentPage = this.totalPage;
+              let startData = (this.currentPage - 1) * this.pageSize;
+              let endData = this.currentPage * this.pageSize;
+              this.tableData = this.allDlr.slice(startData, endData);
+              // 自定义添加  提示
+              if (this.sum === nowSum && addBySelfFlag) {
+                alert("该小组已在列表中,不用重复添加");
+              }
             }
           } else {
             console.log(res);
@@ -462,14 +486,12 @@ export default {
           if (res.data && res.data.code === 200) {
             this.groupList = [];
             res.data.data.forEach((item) => {
-            this.groupList.push(
-              {
+              this.groupList.push({
                 id: item.id,
                 groupName: item.groupName,
-                flag: true
-              }
-            )
-            })
+                flag: true,
+              });
+            });
           } else {
             console.log(res);
           }
@@ -485,10 +507,8 @@ export default {
         url: "/sys/agent/selectAgentAreaInfoList",
       })
         .then((res) => {
-          console.log(res, 1111111);
           if (res.data && res.data.code === 200) {
             this.areaList = res.data.data;
-            console.log(this.areaList)
           } else {
             console.log(res);
           }
@@ -502,12 +522,10 @@ export default {
     this.getLocalMonth();
   },
   created() {
-    // 获取所有经销商信息
-    this.getAllDlr();
-    this.getAreaList();
-    // 获取所有的资料名称
+    this.getAllDlr({}, true);
     this.getAllDataName();
     this.selectGroupList();
+    this.getAreaList();
   },
 };
 </script>

+ 56 - 35
src/views/parameter/components/Grouping/GroupMemberModal.vue

@@ -42,7 +42,7 @@
           >
           </Table>
         </div>
-        <div class="page">
+        <div class="page" v-if="sum > 0">
           <Tablepage
             :totalPage="totalPage"
             :currentPage="currentPage"
@@ -103,7 +103,7 @@ export default {
       addByCustomize: "",
       tableData: [],
       dlrList: [],
-      AllDlr: [],
+      allDlr: [],
       idList: [],
     };
   },
@@ -130,28 +130,32 @@ export default {
     },
     // 点击按区域添加button
     addByArea: function () {
-      let strReq = this.checkedBoxList.join(",");
-      let req = {
-        localArea: strReq,
-      };
-      this.getDlrData(req);
+      if (this.checkedBoxList.length !== 0) {
+        let strReq = this.checkedBoxList.join(",");
+        let req = {
+          localArea: strReq,
+        };
+        this.getDlrData(req);
+      }
     },
     // 自定义添加
     addBySelf: function () {
-      let req = {
-        queryParams: this.addByCustomize,
-      };
-      this.getDlrData(req, true);
+      if (this.addByCustomize) {
+        let req = {
+          queryParams: this.addByCustomize,
+        };
+        this.getDlrData(req, false, true);
+      }
     },
     // 筛选
     changeIcon: function (i) {
       let index = (this.currentPage - 1) * this.pageSize + i;
-      this.AllDlr[index].flag = !this.AllDlr[index].flag;
+      this.allDlr[index].flag = !this.allDlr[index].flag;
     },
     // 获取某一页面的数据,展示在表格
     changePage: function (page) {
       this.currentPage = page;
-      this.tableData = this.AllDlr.slice(
+      this.tableData = this.allDlr.slice(
         (this.currentPage - 1) * this.pageSize,
         this.currentPage * this.pageSize
       );
@@ -172,7 +176,7 @@ export default {
           this.currentPage = this.totalPage;
           break;
       }
-      this.tableData = this.AllDlr.slice(
+      this.tableData = this.allDlr.slice(
         (this.currentPage - 1) * this.pageSize,
         this.currentPage * this.pageSize
       );
@@ -183,42 +187,59 @@ export default {
     // 选中经销商的id 组成列表
     dlrIdList: function () {
       this.idList = [];
-      this.AllDlr.forEach((element) => {
+      this.allDlr.forEach((element) => {
         if (element.flag) {
           this.idList.push(element.id);
         }
       });
     },
-    // 获取进销商信息 接口
-    getDlrData: function (data = {}, flag) {
+    // 获取经销商信息接口
+    getDlrData: function (data = {}, flag, addBySelfFlag) {
       this.$http({
         method: "post",
         url: "/sys/agent/selectAgentInfoPage",
         data: data,
       })
         .then((res) => {
+          console.log(res);
           this.tableData = [];
-          this.AllDlr = [];
+          let nowSum = this.sum;
           if (res.data && res.data.code === 200) {
-            // 整合数据, 主要目的是加一个 flag,在用户点击筛选的时候,好判断
-            res.data.data.forEach((item) => {
-              this.AllDlr.push({
-                id: item.id,
-                dlrCode: item.dlrCode,
-                dlrName: item.dlrName,
-                localArea: item.localArea,
-                flag: true,
-              });
-            });
-            this.sum = res.data.count;
-            this.tableData = this.AllDlr.slice(0, this.pageSize);
-            // 获取自定义添加datalist下拉框的值
-            if (!flag) {
+            // created时,获取自定义添加datalist下拉框的值
+            if (flag) {
               this.dlrList = [];
-              this.AllDlr.forEach((item) => {
+              let allDlrList = res.data.data;
+              allDlrList.forEach((item) => {
                 this.dlrList.push(item.dlrName);
                 this.dlrList.push(item.dlrCode);
               });
+            } else {
+              // 整合数据, 主要目的是加一个 flag,在用户点击筛选的时候,好判断
+              res.data.data.forEach((item) => {
+                this.allDlr.push({
+                  id: item.id,
+                  dlrCode: item.dlrCode,
+                  dlrName: item.dlrName,
+                  localArea: item.localArea,
+                  flag: true,
+                });
+              });
+              // 去重
+              let hash = {};
+              this.allDlr = this.allDlr.reduce(function (item, next) {
+                hash[next.id] ? "" : (hash[next.id] = true && item.push(next));
+                return item;
+              }, []);
+              this.sum = this.allDlr.length;
+              // 添加以后跳到最后一页
+              this.currentPage = this.totalPage;
+              let startData = (this.currentPage - 1) * this.pageSize;
+              let endData = this.currentPage * this.pageSize;
+              this.tableData = this.allDlr.slice(startData, endData);
+              // 自定义添加  提示
+              if (this.sum === nowSum && addBySelfFlag) {
+                alert("该小组已在列表中,不用重复添加");
+              }
             }
           } else {
             console.log(res);
@@ -236,7 +257,7 @@ export default {
         data: data,
       })
         .then((res) => {
-          console.log(res);
+          console.log(res, 11);
           if (res.data && res.data.code === 200) {
             this.areaList = res.data.data;
             console.log(this.areaList);
@@ -250,7 +271,7 @@ export default {
     },
   },
   created() {
-    this.getDlrData();
+    this.getDlrData({}, true);
     this.getAreaList();
   },
 };