2019-10-18 15:05:56 +00:00
|
|
|
import { Vue, Component, Prop } from 'vue-property-decorator';
|
|
|
|
// import Vue from "vue";
|
|
|
|
|
|
|
|
@Component
|
|
|
|
export default class VsPagination extends Vue {
|
|
|
|
|
|
|
|
pageNumber: number = 0; // default to page 0
|
|
|
|
|
|
|
|
@Prop()
|
|
|
|
data;
|
|
|
|
|
|
|
|
@Prop({ default: 4 }) readonly offset: number;
|
|
|
|
|
|
|
|
changePage(page) {
|
|
|
|
if (page == this.data.current_page) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.data.current_page = page;
|
|
|
|
let from = (page * this.data.per_page) - this.data.per_page;
|
|
|
|
this.$emit('paginate', from);
|
|
|
|
}
|
2019-10-18 15:49:02 +00:00
|
|
|
|
2019-10-18 15:05:56 +00:00
|
|
|
get numberOfPages() {
|
|
|
|
return Math.ceil(this.data.total / this.data.per_page);
|
|
|
|
}
|
|
|
|
|
|
|
|
get pages() {
|
|
|
|
let numberOfPages = Math.ceil(this.data.total / this.data.per_page);
|
|
|
|
|
|
|
|
// if (!this.data.to) {
|
|
|
|
// return [];
|
|
|
|
// }
|
|
|
|
let from = this.data.current_page - this.data.per_page;
|
|
|
|
if (from < 1) {
|
|
|
|
from = 1;
|
|
|
|
}
|
|
|
|
let to = from + (this.data.per_page * 2);
|
|
|
|
if (to >= numberOfPages) {
|
|
|
|
to = numberOfPages;
|
|
|
|
}
|
|
|
|
let pagesArray = [];
|
|
|
|
for (let page = from; page <= to; page++) {
|
|
|
|
pagesArray.push(page);
|
|
|
|
}
|
|
|
|
return pagesArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
}
|
|
|
|
}
|