保誠-保戶業務員媒合平台
wayne
2022-02-17 a3716f72066d25d745f4d5103ff23a553c3e102b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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, PropSync } from 'nuxt-property-decorator';
import { Consultant } from '~/shared/models/consultant.model';
 
@Component
export default class UiPagination extends Vue {
    @Prop()
    totalList!: Consultant[];
 
    @Prop({default: 5}) pageSize!: number;
    @PropSync('currentPage', {default: 1}) syncCurrentPage!: number;
 
    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) {
 
        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>