(function ($) {
var obj = obj || {};
var currentPage = 1;//默认第一页
var pageSize = 10;//每页显示条数
var pageNum='';//总页数
obj.search=function(){
var _this=this;
$("#search").click(function(){
currentPage=1;
_this.selectH5Order(true);
obj.fillHtml('pageHtml',{"currPage":currentPage,"pageNum":pageNum,"state":obj.state()});
})
}
obj.init=function(pageHtml,args){
return (function(){
obj.bindEvent();
obj.search();
})();
};
//var currentPage=1;var totalPage;
obj.fillHtml=function(pageHtml,args){
return (function(){
pageHtml="";
if(currentPage > 1){
pageHtml += "<a href='javascript:void(0);' class='geraltTb_pager' data-go='' >上一页</a>";
}else{
pageHtml += "";
}
// 判断出现...情况
if(currentPage!=1 && currentPage>=4 && args.pageNum!=4) {
pageHtml += "<a href='javascript:void(0);' class='geraltTb_pager' data-go='' >首页</a>";
}
if(currentPage-2>2 && currentPage<=args.pageNum && args.pageNum>5) {
pageHtml += "<a href='javascript:void(0);' class='geraltTb_' data-go='' >...</a>";
}
var start = currentPage-2;//通过当前页面跟总页数关系来判断
var end = currentPage+2;
if((start>1 && currentPage<4) || currentPage==1) {
end++;
}
if(currentPage>args.pageNum-4 && currentPage>=args.pageNum) {
start--;
}
for(; start<=end; start++) {
if(start<=args.pageNum && start>=1) {
// if(start != currentPage) {
// pageHtml += "<li class='ali'><a href='javascript:void(0);' class='geraltTb_pager' data-go='' >"+start+"</a>";
// }else{
pageHtml += "<a href='javascript:void(0);' class='geraltTb_pager' data-go='' >"+start+"</a>";
// }
}
}
if(currentPage+2<args.pageNum-1 && currentPage>=1 && args.pageNum>5) {
pageHtml += "<a href='javascript:void(0);' class='geraltTb_' data-go='' >...</a>";
}
if(currentPage!=args.pageNum && currentPage<args.pageNum-2 && args.pageNum!=4) {
pageHtml += "<a href='javascript:void(0);' class='geraltTb_pager' data-go='' >末页</a>";
}
if(currentPage < args.pageNum){
pageHtml += "<a href='javascript:void(0);' class='geraltTb_pager' data-go='' >下一页</a>";
}else{
pageHtml += "";
}
$(".pagination").html(pageHtml);
})();
};
obj.bindEvent=function(){
return (function(){
$(".page").on("click","a.geraltTb_pager",function(event){
$(this).addClass("cur").siblings().removeClass("cur");
if($(this).text()=="上一页"){
currentPage=(currentPage>1)?currentPage-1:1;
}
else if($(this).text()=="下一页"){
currentPage=(currentPage<pageNum)?currentPage+1:pageNum;
}else if($(this).text()=="首页"){
currentPage=1;
}else if($(this).text()=="末页"){
currentPage=pageNum;
}else{
currentPage = parseInt($(this).text());
}
// obj.fillHtml(pageHtml,{"starTime":"","endTime":"","currPage":currentPage,"pageNum":args.pageNum,"turndown":args.turndown,"state":obj.state()});
// if(typeof(args.backFn)=="function"){
// args.backFn(args.currentPage);
// }
obj.selectH5Order();
});
})();
}
obj.selectH5Order=function(first){
var _this=this;
var trHtml='';//列表
//获取数据
$.ajax({
url:'xxxx',
type:'post',
dataType:'json',
cache:true,
contentType: "application/x-www-form-urlencoded; charset=utf-8",
data:XXX,
success: function (data) {
if(data.code="0000"){
pageNum=Math.ceil(data.listSize/pageSize);//通过接口反的数据,算出总页数
var ORDERSTATUS;
// if(first&&pageNum>0){_this.getData()}
// _this.fillHtml();
// if(first){trHtml=''};
trHtml+='<tr>XX<td>XX</td></tr>'
}
$("table").eq(0).html(trHtml);
}else{
pageNum=0;
$("table").html(trHtml);
}
obj.fillHtml('pageHtml',{"starTime":"","endTime":"","currPage":currentPage,"pageNum":pageNum,"state":obj.state()});
}else{
alert(data.message)
}
}
},
error:function(){
}
})
}
return {
selectH5Order:obj.selectH5Order(true),
bindEvent:obj.init()
}
})(jQuery);
pc端表格分页的简单实现
最新推荐文章于 2023-11-22 17:46:02 发布