function paging(options,idname) {
let defaultvalue = {
total: totalcount,
current: 1,
firsttext: '首页',
prevtext: '上一页',
nexttext: '下一页',
lasttext: '尾页',
pagesize:2,
pagenum: 5,
container: document.getelementbyid(idname)
}
this.options = object.assign({}, defaultvalue, options);
this.show();
this.pageclick()
}
paging.prototype.show = function() {
let disable = "";
let pagetotalnum = this.getpagetotalnum();
this.options.container.innerhtml = "";
if (this.options.current === 1) {
disable = 'disable'
}
this.createelement('first cursora ' + disable, this.options.firsttext);
this.createelement('prev cursora ' + disable, this.options.prevtext);
// this.createnumelement();
// disable = ""
// if (this.options.current === pagetotalnum) {
// disable = 'disable'
// }
this.createelement('next cursora ' + disable, this.options.nexttext);
this.createelement('last cursora ' + disable, this.options.lasttext);
this.createelement('total cursora ' + disable, "总"+this.options.total+"条记录");
let span = document.createelement('span');
let i = `第${this.options.current}/${pagetotalnum}页`;
span.innerhtml = i;
this.options.container.appendchild(span)
}
paging.prototype.createnumelement = function() {
let min = this.options.current - math.floor(this.options.pagenum / 2);
if (min < 1) {
min = 1;
}
let max = min + this.options.pagenum - 1;
let pagetotalnum = this.getpagetotalnum();
if (max > pagetotalnum) {
max = pagetotalnum;
}
let active = "";
for (let i = min; i <= max; i++) {
if (this.options.current === i) {
active = 'active';
} else {
active = '';
}
this.createelement('pagingnormal ' + active, i);
//this.onclick(function(){$(this).show()})
}
}
paging.prototype.createelement = function(specialstyle, content) {
let odiv = document.createelement('a');
odiv.classname = specialstyle;
odiv.innertext = content;
this.options.container.appendchild(odiv);
}
paging.prototype.getpagetotalnum = function() {
return math.ceil(this.options.total / this.options.pagesize)
}
paging.prototype.pageclick = function() {
let _this = this;
let pagetotalnum = this.getpagetotalnum();
this.options.container.addeventlistener('click', function(e) {
if (e.target.classlist.contains('first')) {
_this.topage(1);
showlist(1);
} else if (e.target.classlist.contains('prev')) {
_this.topage(_this.options.current - 1);
showlist(_this.options.current);
} else if (e.target.classlist.contains('next')) {
_this.topage(_this.options.current + 1);
showlist(_this.options.current);
} else if (e.target.classlist.contains('last')) {
_this.topage(pagetotalnum);
showlist(pagetotalnum);
} else if (e.target.classlist.contains('pagingnormal')) {
_this.topage(+e.target.innertext);
showlist(+e.target.innertext);
}
})
}
paging.prototype.topage = function(page) {
let pagetotalnum = this.getpagetotalnum();
if (page < 1) {
page = 1;
}
if (page > pagetotalnum) {
page = pagetotalnum;
}
this.options.current = page;
this.show()
}