//请求数据加载绑定页面
function DindAjax(pageIndex) {
//获取参数
var colors = $("#colorsVal").val();
$.ajax({
url: '/Ajax/muban/AjaxHandler.ashx',
type: 'POST',
data: 'ajaxType=pagelist&pageSize=40&pageIndex=' + pageIndex+ '&colors=' + colors,
dataType: 'json',
async: false,
timeout: 6000,
error: function () { },
success: function (obj) {
result1 = eval(obj)[0];
result2 = eval(obj).splice(1, obj.length);
//有数据
if (result1.pagenum > 0) {
$(".content-nolist").hide();
$(".nolist-tj").hide();
$(".back-top").hide();
$(".fy-auto").html(pagesizelist(result1.pageIndex, result1.pagenum));
} else {
$(".nolist-tj").show();
$(".content-nolist").html(result1.result).show();
$(".fy-auto").html("");
$(".back-top").show();
}
}
});
if (result2 != null) {
firstLists = [];
newLists = [];
getJson(result2);
index = 0;
setBox(firstLists);
$('.content-lists').hide();
$('.loading').show();
imagesLoaded(document.querySelector('#masonry'), function (instance) {
imgLoad($('#masonry'));
$('.content-lists').show();
$('.loading').hide();
});
}
}
//列表绑定分页
function pagesizelist(pageIndex, pagenum) {
var i = 0;
//当前页码
var pageIndex = parseInt(pageIndex);
//查询的数据总记录
var pagenum = parseInt(pagenum);
var pagehtml = '<a class="prev ' + (pageIndex == 1 ? 'no-check' : '') + '" href="javascript:void(0);" ' + (pageIndex == 1 ? '' : 'onclick="DindAjax(' + (pageIndex - 1) + ')"') + '><i class="iconfont"></i></a>';
//默认显示分页按钮数量
var indexsize = 5;
//分页中间值偏右
var indexleft = Math.ceil(indexsize / 2);
//分页按钮起始值
var smor = 0;
//分页按钮结束值
var big = 0;
//判断分页数量和总数据量
if (pagenum > indexsize) {
smor = pageIndex < indexleft ? 0 : ((pageIndex - indexleft) >= (pagenum - indexsize) ? (pagenum - indexsize) : (pageIndex - indexleft));
big = pageIndex < indexleft ? indexsize : (pageIndex == pagenum ? pageIndex : (pageIndex + ((pagenum - pageIndex) >= (indexsize - indexleft) ? (indexsize - indexleft) : (pagenum - pageIndex))));
} else {
smor = 0;
big = pagenum;
}
for (i = smor; i < big; i++) {
if (pageIndex == (i + 1)) {
pagehtml += " <span>" + pageIndex + "</span>";
} else {
pagehtml += "<a href="javascript:void(0)" onclick="DindAjax('" + (i + 1) + "')">" + (i + 1) + "</a>";
}
}
pagehtml += '<a class="prev ' + ((pageIndex + 1) > pagenum ? 'no-check' : '') + '" href="javascript:void(0);" ' + ((pageIndex + 1) > pagenum ? '' : 'onclick="DindAjax(' + (pageIndex + 1) + ')"') + '><i class="iconfont"></i></a>';
pagehtml += ' <div class="fl"><b>共' + pagenum + '页</b> <b>到第</b><input onkeypress="if(event.keyCode==13){ pageValue(' + pagenum + ')};" onkeyup="javascript:value=value.replace(/[^0-9]/g,"");" id="text_default" value="' + pageIndex + '" /><b>页</b></div><button class="logobutton" onclick="pageValue(' + pagenum + ')">确定</button>';
return pagehtml;
}
function pageValue(pagenum) {
var num = $("#text_default").eq(0).val() >= pagenum ? pagenum : $("#text_default").eq(0).val();
DindAjax(num);
}