From 8f60f9800584d6918d7bcda66ed18f8773a25f25 Mon Sep 17 00:00:00 2001
From: Tomas <tomasysh@gmail.com>
Date: 星期四, 07 九月 2023 13:46:31 +0800
Subject: [PATCH] Update: 0907-P6: Bad use of null-like value

---
 PAMapp/components/Ui/UiPagination.vue |   54 ++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/PAMapp/components/Ui/UiPagination.vue b/PAMapp/components/Ui/UiPagination.vue
index b2128a7..2e13b2b 100644
--- a/PAMapp/components/Ui/UiPagination.vue
+++ b/PAMapp/components/Ui/UiPagination.vue
@@ -1,43 +1,61 @@
 <template>
     <el-pagination
+        :current-page.sync="syncCurrentPage"
         layout="prev, pager, next"
         :total="totalList.length"
         :page-size="pageSize"
         @current-change="handleCurrentChange"
+        class="mt-10"
     >
     </el-pagination>
 </template>
 
 <script lang="ts">
-import { Vue, Component, Prop, Emit, Watch } from 'nuxt-property-decorator';
-import { Agents } from '~/plugins/api/home';
+import { Vue, Component, Prop, Emit, Watch, PropSync } from 'nuxt-property-decorator';
+import { Consultant } from '~/shared/models/consultant.model';
 
 @Component
 export default class UiPagination extends Vue {
-    @Prop() totalList!: Agents[];
-    pageSize = 5;
-    currentPage = 1;
-    pageList: Agents[] = [];
+    @Prop()
+    totalList!: Consultant[];
 
-    mounted() {
-        this.handleCurrentChange(this.currentPage);
-    }
+    @Prop({default: 5}) pageSize!: number;
+    @PropSync('currentPage', {default: 1}) syncCurrentPage!: number;
 
-    @Emit('changePage') chagnePage(): Agents[] {
+    pageList: Consultant[] = [];
+
+    //////////////////////////////////////////////////////////////////
+
+    @Emit('changePage')
+    changePage(): Consultant[] {
         return this.pageList
     }
 
-    handleCurrentChange(currentPage: number) {
-        if (this.totalList) {
-            this.pageList = this.totalList.slice(this.pageSize * currentPage - this.pageSize, this.pageSize * currentPage)
-            this.chagnePage();
+    @Watch('totalList')
+    watchTotalList(newValue: Consultant[]) {
+        if (newValue) {
+            this.handleCurrentChange(this.syncCurrentPage);
         }
     }
 
-    @Watch('totalList') watchtotalList(newValue: Agents[]) {
-        if (newValue) {
-            this.handleCurrentChange(this.currentPage);
+    //////////////////////////////////////////////////////////////////
+
+    mounted() {
+        this.handleCurrentChange(this.syncCurrentPage);
+    }
+
+    //////////////////////////////////////////////////////////////////
+
+    handleCurrentChange(currentPage: number) {
+
+        if (this.totalList.length <= this.pageSize && currentPage !== 1) {
+            currentPage -= 1;
+        }
+
+        if (this.totalList) {
+            this.pageList = this.totalList.slice(this.pageSize * currentPage - this.pageSize, this.pageSize * currentPage)
+            this.changePage();
         }
     }
 }
-</script>
\ No newline at end of file
+</script>

--
Gitblit v1.8.0