//获取排行
var pagenumber = 1;
function pagination(pageNo, pageSize, array) {
var offset = (pageNo - 1) * pageSize;
return (offset + pageSize >= array.length) ? array.slice(offset, array.length) : array.slice(offset, offset + pageSize);
}
$.post("https://Best.tianjihr.com/H5/companyRank", function (data) {
pagesList = data.data;
var pageTrades = pagination(pagenumber, 10, data.data);
for(var i=0; i<pageTrades.length; i++){
var element = $('<li><div class="left"><strong>'+(i+1)+'.</strong>'+pageTrades[i].common_name+'</div><div class="right"><span></span>'+pageTrades[i].ticket_count+' 票</div></li>');
if(pageTrades[i].BestCompanyid==EnterpriseId){
$(element).find(".left").css('color','red');
$(element).find(".right").css('color','red');
}
$('.mingdan').append(element);
}
});
//点击下一页
$('.rank-down').click(function(){
if(pagenumber>=10){
alert('已经是最后一页了');
return;
}
$('.mingdan').html('');
pagenumber=pagenumber+1;
var pageTrades = pagination(pagenumber, 10, pagesList);
for(var i=0; i<pageTrades.length; i++){
var element = $('<li><div class="left"><strong>'+(pagenumber*10-10+i+1)+'.</strong>'+pageTrades[i].common_name+'</div><div class="right"><span></span>'+pageTrades[i].ticket_count+' 票</div></li>');
if(pageTrades[i].BestCompanyid==EnterpriseId){
$(element).find(".left").css('color','red');
$(element).find(".right").css('color','red');
}
$('.mingdan').append(element);
}
});
//点击上一页
$('.rank-up').click(function(){
if(pagenumber<2){
alert('已经是第一页了');
return;
}
$('.mingdan').html('');
pagenumber=pagenumber-1;
var pageTrades = pagination(pagenumber, 10, pagesList);
for(var i=0; i<pageTrades.length; i++){
var element = $('<li><div class="left"><strong>'+(pagenumber*10-10+i+1)+'.</strong>'+pageTrades[i].common_name+'</div><div class="right"><span></span>'+pageTrades[i].ticket_count+' 票</div></li>');
if(pageTrades[i].BestCompanyid==EnterpriseId){
$(element).find(".left").css('color','red');
$(element).find(".right").css('color','red');
}
$('.mingdan').append(element);
}
});