Explorar el Código

会员转移保留选择框设置

wangxy hace 9 horas
padre
commit
85c39d7aeb
Se han modificado 2 ficheros con 108 adiciones y 11 borrados
  1. 55 6
      src/views/his/user/indexProject.vue
  2. 53 5
      src/views/user/transfer/index.vue

+ 55 - 6
src/views/his/user/indexProject.vue

@@ -177,7 +177,7 @@
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
 
-    <el-table  height="500" border v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
+    <el-table  ref="userTable" height="500" border v-loading="loading" :data="userList" @selection-change="handleSelectionChange" @select="handleSelect" @select-all="handleSelectAll">
       <el-table-column type="selection" width="55" align="center" />
       <el-table-column label="ID" align="center" prop="userId" />
       <el-table-column label="项目" align="center" prop="projectId">
@@ -555,6 +555,7 @@ export default {
       companyOptions: [],
       projectOptions: [],
       selectedUser: [],
+      restoring: false,
       // 转移导入
       transferUploadDialog: {
         visible: false,
@@ -643,9 +644,28 @@ export default {
     getList() {
       this.loading = true;
       listUserByProject(this.queryParams).then(response => {
-        this.userList = response.rows;
+        this.restoring = true;
+        this.userList = (response.rows || []).map(row => {
+          row._rowKey = row.userId + '_' + (row.projectId || 0);
+          return row;
+        });
         this.total = response.total;
         this.loading = false;
+        this.$nextTick(() => {
+          const table = this.$refs.userTable;
+          if (table) {
+            this.userList.forEach(row => {
+              if (this.ids.includes(row._rowKey)) {
+                table.toggleRowSelection(row, true);
+              }
+            });
+          }
+          this.$nextTick(() => {
+            this.restoring = false;
+          });
+        });
+      }).catch(() => {
+        this.loading = false;
       });
     },
     // 取消按钮
@@ -691,6 +711,8 @@ export default {
     /** 搜索按钮操作 */
     handleQuery() {
       this.queryParams.pageNum = 1;
+      this.ids = [];
+      this.selectedUser = [];
       this.getList();
     },
     /** 重置按钮操作 */
@@ -702,6 +724,8 @@ export default {
       this.companyQueryUserOptions = null;
       this.queryParams.startCreateTime = null
       this.queryParams.endCreateTime = null
+      this.ids = [];
+      this.selectedUser = [];
       this.handleQuery();
     },
     /** 处理日期范围变化 */
@@ -716,10 +740,35 @@ export default {
     },
     // 多选框选中数据
     handleSelectionChange(selection) {
-      this.ids = selection.map(item => item.userId)
-      this.selectedUser = selection.map(item => {return {userId: item.userId, projectId: item.projectId}})
-      this.single = selection.length!==1
-      this.multiple = !selection.length
+      this.single = selection.length !== 1;
+      this.multiple = !selection.length;
+    },
+    // 单行选中(跨页累积)
+    handleSelect(selection) {
+      if (this.restoring) return;
+      this.updateSelection(selection);
+    },
+    // 全选当前页(跨页累积)
+    handleSelectAll(selection) {
+      if (this.restoring) return;
+      this.updateSelection(selection);
+    },
+    // 更新跨页选中数据
+    updateSelection(selection) {
+      const pageKeys = this.userList.map(row => row._rowKey);
+      const otherIds = this.ids.filter(id => !pageKeys.includes(id));
+      const curIds = selection.map(item => item._rowKey);
+      this.ids = [...otherIds, ...curIds];
+
+      const curUsers = selection.map(item => ({userId: item.userId, projectId: item.projectId}));
+      const otherUsers = this.selectedUser.filter(u => {
+        const key = u.userId + '_' + (u.projectId || 0);
+        return !pageKeys.includes(key);
+      });
+      this.selectedUser = [...otherUsers, ...curUsers];
+
+      this.single = this.ids.length !== 1;
+      this.multiple = !this.ids.length;
     },
     /** 新增按钮操作 */
     handleAdd() {

+ 53 - 5
src/views/user/transfer/index.vue

@@ -97,7 +97,7 @@
 	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
 
-    <el-table v-loading="loading" :data="approvalList" @selection-change="handleSelectionChange">
+    <el-table ref="approvalTable" v-loading="loading" :data="approvalList" @selection-change="handleSelectionChange" @select="handleSelect" @select-all="handleSelectAll">
       <el-table-column type="selection" width="55" align="center" />
       <el-table-column label="ID" align="center" prop="id" />
       <el-table-column label="所属公司" align="center" prop="companyName" />
@@ -288,6 +288,8 @@ export default {
         ]
       },
       projectOptions: [],
+      selectedUser: [],
+      restoring: false,
     };
   },
   created() {
@@ -338,9 +340,28 @@ export default {
     getList() {
       this.loading = true;
       listApproval(this.queryParams).then(response => {
-        this.approvalList = response.rows;
+        this.restoring = true;
+        this.approvalList = (response.rows || []).map(row => {
+          row._rowKey = row.id;
+          return row;
+        });
         this.total = response.total;
         this.loading = false;
+        this.$nextTick(() => {
+          const table = this.$refs.approvalTable;
+          if (table) {
+            this.approvalList.forEach(row => {
+              if (this.ids.includes(row._rowKey)) {
+                table.toggleRowSelection(row, true);
+              }
+            });
+          }
+          this.$nextTick(() => {
+            this.restoring = false;
+          });
+        });
+      }).catch(() => {
+        this.loading = false;
       });
     },
     // 取消按钮
@@ -371,17 +392,44 @@ export default {
     /** 搜索按钮操作 */
     handleQuery() {
       this.queryParams.pageNum = 1;
+      this.ids = [];
+      this.selectedUser = [];
       this.getList();
     },
     /** 重置按钮操作 */
     resetQuery() {
       this.resetForm("queryForm");
+      this.ids = [];
+      this.selectedUser = [];
       this.handleQuery();
     },
     handleSelectionChange(selection) {
-      this.ids = selection.map(item => item.id)
-      this.single = selection.length!==1
-      this.multiple = !selection.length
+      this.single = selection.length !== 1;
+      this.multiple = !selection.length;
+    },
+    handleSelect(selection) {
+      if (this.restoring) return;
+      this.updateSelection(selection);
+    },
+    handleSelectAll(selection) {
+      if (this.restoring) return;
+      this.updateSelection(selection);
+    },
+    updateSelection(selection) {
+      const pageKeys = this.approvalList.map(row => row._rowKey);
+      const otherIds = this.ids.filter(id => !pageKeys.includes(id));
+      const curIds = selection.map(item => item._rowKey);
+      this.ids = [...otherIds, ...curIds];
+
+      const curUsers = selection.map(item => ({id: item.id}));
+      const otherUsers = this.selectedUser.filter(u => {
+        const key = u.id;
+        return !pageKeys.includes(key);
+      });
+      this.selectedUser = [...otherUsers, ...curUsers];
+
+      this.single = this.ids.length !== 1;
+      this.multiple = !this.ids.length;
     },
     /** 新增按钮操作 */
     handleAdd() {