oak-frontend-base/es/components/pagination/index.js

42 lines
1.2 KiB
JavaScript

export default OakComponent({
entity() {
return this.props.entity;
},
properties: {
entity: '',
},
isList: true,
lifetimes: {
ready() {
const { oakPagination } = this.state;
const { total } = oakPagination || {};
if (total) {
this.setState({ newTotal: total });
}
},
},
listeners: {
oakPagination(prev, next) {
if (!prev.oakPagination &&
prev.oakPagination !== next.oakPagination) {
const { total, pageSize, currentPage, more } = next.oakPagination || {};
if (total) {
this.setState({ newTotal: total });
}
}
},
},
methods: {
async setTotal() {
const { oakPagination, newTotal } = this.state;
const { pageSize, total, currentPage, more } = oakPagination || {};
if (total && pageSize) {
if (Math.ceil(newTotal / pageSize) === currentPage) {
console.log(newTotal + pageSize);
this.setState({ newTotal: newTotal + pageSize });
}
}
},
},
});