瀏覽代碼

新增下一个按钮

duy 1 月之前
父節點
當前提交
2262bbbd1d
共有 1 個文件被更改,包括 92 次插入24 次删除
  1. 92 24
      src/views/certificate/list.vue

+ 92 - 24
src/views/certificate/list.vue

@@ -102,7 +102,7 @@
       :total="total"
       @size-change="handleSizeChange"
       @current-change="handleCurrentChange"
-      :current-page.sync="pageindex"
+      :current-page="pageindex"
       :page-size="pagesize"
     >
     </el-pagination>
@@ -128,8 +128,38 @@ export default {
       pageindex: 1,
       pagesize: 20,
       certificateTypeValue: null, //证书类型
+      nextId: null,
+
     };
   },
+  watch: {
+    // 监听路由变化,当从其他页面返回时更新状态
+    '$route.query': {
+      immediate: true,
+      handler(newQuery) {
+        if (newQuery.pageindex) {
+          this.pageindex = Number(newQuery.pageindex);
+        }
+        if (newQuery.value) {
+          this.value = newQuery.value;
+        }
+    
+        if (newQuery.pagesize) {
+          this.pagesize = Number(newQuery.pagesize);
+        }
+      }
+    },
+    searchinput: {
+      immediate: true,
+      handler(newQuery) {
+        if (newQuery) {
+          this.pageindex = 1;
+          this.pagesize=20
+
+        }
+      }
+    }
+  },
   methods: {
     //#region 页码
     handleSizeChange(val) {
@@ -141,25 +171,53 @@ export default {
       this.listpage();
     },
     typeChange() {
+      this.pageindex = 1;
+      this.pagesize = 20;
       this.listpage();
     },
     //#endregion
 
     //#region 头接口
-    pushRouter(id) {
-      this.$router.push({
-        path: "/certificate/list/addList",
-        query: {
-          id,
-          value: this.value,
-        },
-      });
-      console.log(this.value, "value");
-    },
+   // 修改pushRouter方法,传递完整的查询状态
+  // 在列表页的pushRouter方法中修改下一条ID的计算方式
+pushRouter(id) {
+  // 找到当前行在表格数据中的索引
+  const currentIndex = this.tableData.findIndex(row => row.id === id);
+  // 获取下一行数据的id(如果存在)
+  let nextId = null;
+  
+  // 如果是最后一条记录,查询下一页的第一条
+  if (currentIndex === this.tableData.length - 1) {
+    // 检查是否有下一页
+    if (this.pageindex * this.pagesize < this.total) {
+      // 这里只是标记需要加载下一页,实际数据在编辑页处理
+      nextId = 'nextPage';
+    }
+  } else {
+    // 正常获取下一条
+    const nextRow = this.tableData[currentIndex + 1];
+    nextId = nextRow ? nextRow.id : null;
+  }
+  
+  this.$router.push({
+    path: "/certificate/list/addList",
+    query: {
+      id,
+      value: this.value,
+      certificateTypeValue: this.certificateTypeValue,
+      searchinput: this.searchinput,
+      pageindex: this.pageindex,
+      pagesize: this.pagesize,
+      nextId: nextId
+    }
+  });
+},
     //#endregion
 
     //#region 列表接口
     projectChange() {
+           this.pageindex = 1;
+      this.pagesize = 20;
       //下拉框change事件
       this.listpage();
     },
@@ -196,19 +254,29 @@ export default {
         this.listpage();
       }
     },
-    async queryProjectList() {
-      //获取所有项目
-      const { data: res } = await queryProjectList();
-      if (res.code == 200) {
-        this.options = res.data;
-        if (this.$route.query.value) {
-          this.value = this.$route.query.value;
-        } else {
-          this.value = this.value = this.options[0].id;
-        }
-        this.listpage();
-      }
-    },
+   async queryProjectList() {
+  const { data: res } = await queryProjectList();
+  if (res.code == 200) {
+    this.options = res.data;
+    // 处理路由参数
+    if (this.$route.query.value) {
+      this.value = this.$route.query.value;
+      // 确保页码是数字类型
+      this.pageindex = Number(this.$route.query.pageindex) || 1;
+      this.pagesize = Number(this.$route.query.pagesize) || 20;
+      this.certificateTypeValue = this.$route.query.certificateTypeValue 
+        ? Number(this.$route.query.certificateTypeValue) 
+        : null;
+      this.searchinput = this.$route.query.searchinput || '';
+    } else {
+      this.value = this.options[0].id || '';
+    }
+    this.$nextTick(() => {
+      this.listpage();
+    });
+  }
+},
+
     async listpage() {
       //分页获取证书列表数据
       const { data: res } = await listpage({