import { Vue, Prop, Component } from "vue-property-decorator"; import Button from "@/components/Button/index.vue"; import Popover from "@/components/Popover/index.vue"; import { ListsObject, Translation } from "@/types"; import Dropdown from "@/components/Dropdown/index.vue"; import Loading from "./Loading/index.vue"; @Component({ components: { Button, Popover, Loading, Dropdown, }, }) export default class Pagination extends Vue { @Prop({ type: Number }) initPage!: number; @Prop({ type: Number }) initLimit!: number; @Prop({ type: Number, default: 1 }) lastPage!: number; @Prop({ type: Boolean, default: false }) readonly loading?: boolean; @Prop({ type: Boolean, default: true }) readonly showNavigate?: boolean; @Prop({ type: Boolean, default: true }) readonly showLimit?: boolean; @Prop({ type: Number }) readonly total?: number; limit = 15; page = 1; limitBox = false; pageBox = false; limitList: string[] = []; open = ""; innerStyle = false; height = document.documentElement.clientHeight; openOnTop = false; mounted() { window.addEventListener("resize", this.getDimensions); document.documentElement.addEventListener("click", this.outsideClick, true); } unmounted() { window.removeEventListener("resize", this.getDimensions); this.openOnTop = false; } getDimensions() { this.height = document.documentElement.clientHeight; } outsideClick() { if (this.open === "limit" || this.open === "page") { this.open = ""; } } get initial() { if (this.initLimit && this.initPage) { this.page = this.initPage; return { lim: this.initLimit, pg: this.initPage }; } this.page = this.initPage; return { lim: 15, pg: 1 }; } get limitsList(): ListsObject[] { const list: ListsObject[] = []; for (let limit = 5; limit <= 25; ) { list.push({ title: limit.toString(), }); limit += 5; } this.page = +this.initPage; return list; } get pagesList(): ListsObject[] { const list: ListsObject[] = []; for (let page = 1; page <= this.lastPage; page += 1) { list.push({ title: page.toString(), }); } return list; } get period(): Translation { const all = this.total; // const to = this.page * this.limit; // const from = to - (this.limit - 1); return this.$i18n.t("pagination.result", { all }); } toggle(value) { this.open = value; if (this.height < 284) { this.innerStyle = true; } else { this.innerStyle = false; const element = document.querySelector("#drop"); const dom = element?.getBoundingClientRect(); if (typeof dom !== "undefined" && window.innerHeight - dom.bottom < 230) { this.openOnTop = true; } } } limitBtnHandler(e) { this.limit = e; this.open = ""; this.$emit("changeLimit", e); } pageBtnHandler(e) { this.page = e; this.open = ""; this.$emit("changePage", e); } }