保誠-保戶業務員媒合平台
Tomas
2024-04-30 b4d6944076f1df6eedaae35c4c2a7072fe988e8a
PAMapp/components/Ui/UiPagination.vue
@@ -1,6 +1,6 @@
<template>
    <el-pagination
        :current-page.sync="currentPage"
        :current-page.sync="syncCurrentPage"
        layout="prev, pager, next"
        :total="totalList.length"
        :page-size="pageSize"
@@ -11,23 +11,40 @@
</template>
<script lang="ts">
import { Vue, Component, Prop, Emit, Watch } from 'nuxt-property-decorator';
import { Consultants } from '~/assets/ts/api/consultant';
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!: Consultants[];
    pageSize = 5;
    currentPage = 1;
    pageList: Consultants[] = [];
    @Prop()
    totalList!: Consultant[];
    mounted() {
        this.handleCurrentChange(this.currentPage);
    }
    @Prop({default: 5}) pageSize!: number;
    @PropSync('currentPage', {default: 1}) syncCurrentPage!: number;
    @Emit('changePage') chagnePage(): Consultants[] {
    pageList: Consultant[] = [];
    //////////////////////////////////////////////////////////////////
    @Emit('changePage')
    changePage(): Consultant[] {
        return this.pageList
    }
    @Watch('totalList')
    watchTotalList(newValue: Consultant[]) {
        if (newValue) {
            this.handleCurrentChange(this.syncCurrentPage);
        }
    }
    //////////////////////////////////////////////////////////////////
    mounted() {
        this.handleCurrentChange(this.syncCurrentPage);
    }
    //////////////////////////////////////////////////////////////////
    handleCurrentChange(currentPage: number) {
@@ -37,14 +54,8 @@
        if (this.totalList) {
            this.pageList = this.totalList.slice(this.pageSize * currentPage - this.pageSize, this.pageSize * currentPage)
            this.chagnePage();
        }
    }
    @Watch('totalList') watchtotalList(newValue: Consultants[]) {
        if (newValue) {
            this.handleCurrentChange(this.currentPage);
            this.changePage();
        }
    }
}
</script>
</script>