Authored by mark

add devidepage

... ... @@ -113,7 +113,7 @@ exports.pager = function() {
if (val === '.') {
ret += '<a>...</a>';
} else {
ret += `<a href="${base}${val}" ` +
ret += `<a href="${base}${val}"` +
(page === val ? `class="${currentClass}"` : '') +
` title="第${val}页">${val}</a>`;
}
... ...
... ... @@ -303,21 +303,11 @@
<div class="judge-content">
<div data-comment-list="7">
<ul></ul>
<p class="more-wrap">
<span class="load-more-comments load-more">
加载更多
<i class="iconfont">&#xe61d;</i>
</span>
</p>
</div>
<div data-comment-list="6" class="m-hide">
<ul></ul>
<p class="more-wrap">
<span class="load-more-comments load-more">
加载更多
<i class="iconfont">&#xe61d;</i>
</span>
</p>
</div>
<p class="btn-wrap">
... ...
... ... @@ -51,4 +51,5 @@
<span>{{date}}</span>
</div>
</li>
{{/each}}
... ...
... ... @@ -15,6 +15,7 @@ var lazyLoad = require('yoho-jquery-lazyload');
var yas = require('../common/data-yas');
var dataLazyLoad = require('../plugins/lazy-load')(document);
var handlebars = require('yoho-handlebars');
var setPager = require('./detail/pager');
var bindEvent = $.Callbacks(); // eslint-disable-line
var clickAcquireCouponEvent = $.Callbacks('unique'); // eslint-disable-line
... ... @@ -836,7 +837,21 @@ function fetchComment() {
loadingComments,
loadingConsults;
function loadComments(type) {
$('.comments ul').on('click', 'a', function() {
var $this = $(this);
var href = $this.data('page');
var data = href.split('?')[1].split('&');
var result = data.map(function(i) {
return i.split('=')[1];
});
loadAllComments(currentType, result[2]);
});
function loadComments(type, nowPage) {
if (loadingComments) {
return;
}
... ... @@ -849,20 +864,21 @@ function fetchComment() {
url: '/product/detail/comment',
data: {
productId: id,
page: commentPage[type],
page: nowPage,
filterId: type
}
});
}
// 购买评价
function loadAllComments(type) {
loadComments(type).then(function(data) {
var res, filter, $ul;
function loadAllComments(type, nowPage) {
loadComments(type, nowPage).then(function(data) {
var res, filter, $ul, totalnum;
if (data.code === 200) {
res = data.data;
filter = data.filter || [];
$ul = $('.comments [data-comment-list=' + type + '] ul');
if (res.length === 0) {
... ... @@ -871,22 +887,33 @@ function fetchComment() {
}
if (filter && filter.length && !cNumReady) {
cNumReady = true;
// cNumReady = true;
$(filter).each(function(idx, fit) {
if (fit.num) {
$('.comments [data-comment-type=' + fit.filterId + '] em').text(fit.num);
if (fit.filterId === '7') { // 全部数量
$('.consult-comment .block-title .comment-num').text(fit.num);
}
if (fit.filterId == type) {
totalnum = fit.num;
}
}
});
}
$ul.append(commentsTpl({
totalnum = Math.ceil(totalnum / 10) * 20;
$ul.empty().append(commentsTpl({
comments: res
}));
commentPage[type]++;
var baseUrl = '/product/detail/comment?productId=' + id + '&filterId=' + '7';
$ul.append(setPager({baseUrl: baseUrl, totalRecords: totalnum, page: nowPage, type: 'ellipsis', theme: 'msg-pager'}));
}
}).always(function() {
loadingComments = false;
... ... @@ -1315,6 +1342,5 @@ $(function() {
});
});
// 数据懒加载
dataLazyLoad.init({cls: '.datalazyload', threshold: 0});
... ...
/**
* guang
* @author: lcy<chuanyang.liu@yoho.cn>
* @date: 2016/09/01
*/
'use strict';
var $ = require('yoho-jquery');
var ALL_TYPES = {
stand: 'p-page-n',
mini: 'p-n',
full: 'f-p-page-n-l-info-input-gobtn',
fullellipsis: 'f-p-pe-n-l-info-input-gobtn',
ellipsis: 'p-pe-n'
};
module.exports = function(opts) {
var options = opts || {};
var baseUrl = options.baseUrl || '',
page = (options.page || 1) * 1,
showNum = (options.showNum || 7) * 1,
pageSize = options.pageSize || 20,
totalPages = options.totalPages,
totalRecords = options.totalRecords,
theme = options.theme || 'pager',
currentClass = options.currentClass || 'cur',
// min full stand ellipsis or: f-首页, p-上一页, page-页码,n-下一页,l-最后一页,info-displayMsg,inout输入框,gobtn-goto Btn
type = options.type || 'stand',
pageVar = options.pageVar || 'page',
pageSizeVar = options.pageSizeVar || 'pageSize';
// 清除原来page(page=1&) 重新定义page
var clearPageReg = new RegExp(pageVar + '=[^&]*(&|$)'),
clearSizeReg = new RegExp(pageSizeVar + '=[^&]*(&|$)'),
base = baseUrl.replace(clearPageReg, '');
if (options.pageSize) {
base = base.replace(clearSizeReg, '');
}
base += (base.indexOf('?') < 0 ? '?' : (/(\?|&)$/.test(base) ? '' : '&')) +
(options.pageSize ? (pageSizeVar + '=' + pageSize + '&') : '') +
pageVar + '=';
function getPageNums(ntype) {
var pageNums = [];
var num = showNum;
if (ntype === 'e') {
num = num - 2;
num = num > 2 ? num : 2;
}
/** 分页展示页码个数begin 规则:展示最靠近当前页的指定个数 **/
var pageShowMax = num % 2 === 0 ? page - 1 : page;
var pageShowMin = page;
for (var i = 0; i < Math.floor(num / 2); i++) {
pageShowMax++;
pageShowMin--;
if (pageShowMax > totalPages) {
pageShowMax = totalPages;
if (pageShowMin > 1) {
pageShowMin--;
}
}
if (pageShowMin < 1) {
pageShowMin = 1;
if (pageShowMax < totalPages) {
pageShowMax++;
}
}
}
for (var n = pageShowMin; n <= pageShowMax; n++) {
pageNums.push(n);
}
if (ntype === 'e') {
if (pageShowMin > 3) {
pageNums.unshift(1, '.');
} else if (pageShowMin === 2) {
pageNums.unshift(1);
} else if (pageShowMin === 3) {
pageNums.unshift(1, 2);
}
if (pageShowMax < totalPages - 2) {
pageNums.push('.', totalPages);
} else {
for (var x = pageShowMax + 1; x <= totalPages; x++) {
pageNums.push(x);
}
}
}
return pageNums;
}
function renderItem(arr) {
/** 分页展示页码个数end **/
var ret = '';
if ($.isArray(arr) && arr.length) {
arr.forEach((val) => {
if (val === '.') {
ret += '<a>...</a>';
} else {
ret += '<a href="javascript:void(0)" data-page="'+ base + val +'"' +
(page === val ? 'class="'+ currentClass +'"' : '') +
' title="第'+ val +'页">'+ val + '</a>';
}
});
}
return ret;
}
function createStandItems() {
return renderItem(getPageNums());
}
function createEllipsisItems() {
return renderItem(getPageNums('e'));
}
if (!totalPages) {
if (!totalRecords || !pageSize) {
return '';
} else {
totalPages = Math.ceil(totalRecords / pageSize);
}
}
var items = ALL_TYPES[type] ? ALL_TYPES[type] : type;
items = $.isArray(items) ? items : (items || ALL_TYPES.stand).split('-');
var hasPage = false; // 配置中如果配置了多次 page/pe 则将忽略,只第一次有效
var ret = '<div class="pager'+' '+theme +'">';
items.forEach(function(val) {
switch (val) {
case 'f' :
if (page > 1) {
ret += '<a href="javascript:void(0)" title="首页" data-page="'+ base +'1">首页</a>';
}
break;
case 'p' :
if (page > 1) {
ret += '<a href="javascript:void(0)" data-page="'+ base + (page - 1) +
'" title="上一页"><span class="iconfont">&#xe60e;</span>上一页</a>';
}
break;
case 'n' :
if (page < totalPages) {
ret += '<a href="javascript:void(0)" data-page="'+ base + (page + 1) +
'" title="下一页">下一页<span class="iconfont">&#xe60c;</span></a>';
}
break;
case 'l' :
if (page < totalPages) {
ret += '<a href="javascript:void(0)" data-page="'+ base + totalPages +'" title="尾页">尾页</a>';
}
break;
case 'info' :
ret += '共{totalRecords}条/{totalPages}页';
break;
case 'input' :
// input
// ret += '<span class="{cls}"><input value="{value}" type="text"></span>';
break;
case 'gobtn' :
// goto btn
break;
case 'page' :
if (!hasPage) {
ret += createStandItems();
}
hasPage = true;
break;
case 'pe' :
if (!hasPage) {
ret += createEllipsisItems();
}
hasPage = true;
break;
}
});
if (options.fn) {
ret += options.fn(options.context);
}
ret += '</div>';
return ret;
};
... ...
... ... @@ -2068,6 +2068,12 @@
.judge-content{
background-color: #fff;
.msg-pager{
text-align: center;
margin: 10px auto;
}
}
.comment-tabs{
... ...