Authored by 郭成尧

分页数据处理

... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2016-05-25 18:16:59
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-31 16:55:37
* @Last Modified time: 2016-05-31 18:22:37
*/
'use strict';
... ... @@ -179,8 +179,8 @@ const handleSalebreakingYardsSortData = (origin, params) => {
// 判断是否在这组数据里面
if (!_.isEmpty(_.find(value.sort_id.split(','), o => {
return o === sortParam;
}))) {
return o === sortParam;
}))) {
// 如果在某组数据里面,组合数据退出循环
_.forEach(value.sub, function(subValue) {
... ... @@ -393,6 +393,7 @@ exports.handleSaleOptsData = (params, total) => {
dest.sortType.push(opt);
}
// 上下翻页数据处理
dest.pageCounts = [{
href: handleFilterUrl(params, { limit: 100 }),
count: 100
... ... @@ -653,3 +654,72 @@ exports.handleSaleCategoryData = () => {
}]
}];
};
/**
* 处理分页数据
* @param {[type]} total [description]
* @param {[type]} params [description]
* @return {[type]} [description]
*/
exports.handleSalePagerData = (total, params) => {
// 当前页
let currentPage = parseInt((_.isEmpty(params.page) ? 1 : params.page), 10);
let perPageCount = parseInt((_.isEmpty(params.limit) ? 60 : params.limit), 10);
let totalPage = parseInt(total / perPageCount, 10) + 1;
let dest = '<a href ="' + handleFilterUrl(params, { page: (currentPage) }) +
'" class="cur">' + currentPage + '</a>';
// 先处理大多数情况
if ((currentPage > 2) && (currentPage < (parseInt(total, 10) / perPageCount) - 1)) {
for (let i = 1; i < 3; i++) {
dest = '<a href ="' + handleFilterUrl(params, { page: (currentPage - i) }) + '">' +
(currentPage - i) + '</a> ' + dest + ' <a href ="' +
handleFilterUrl(params, { page: (currentPage + i) }) +
'">' + (currentPage + i) + '</a>';
}
// 处理页码小于2的情况
} else if (currentPage <= 2) {
for (let i = currentPage - 1; i > 0; i--) {
dest = '<a href ="' + handleFilterUrl(params, { page: i }) +
'" class="cur">' + i + '</a>' + dest;
}
for (let i = currentPage + 1; i < (totalPage < 6 ? totalPage : 6); i++) {
dest += '<a href ="' + handleFilterUrl(params, { page: i }) +
'" class="cur">' + i + '</a>';
}
// 处理页码大于最大页-2的情况
} else if (currentPage > totalPage - 2) {
for (let i = currentPage + 1; i < totalPage + 1; i++) {
dest += '<a href ="' + handleFilterUrl(params, { page: i }) +
'" class="cur">' + i + '</a>';
}
for (let i = currentPage - 1; i > (currentPage - 5 > 1 ? currentPage - 5 : 1); i--) {
dest = '<a href ="' + handleFilterUrl(params, { page: i }) +
'" class="cur">' + i + '</a>' + dest;
}
}
// 处理后省略号的情况
if ((totalPage > 5) && (currentPage < (totalPage - 2))) {
dest += ' ... <a href ="' + handleFilterUrl(params, { page: totalPage }) +
'">' + totalPage + '</a>';
}
// 处理前省略号的情况
if (currentPage > 3) {
dest = '<a href ="' + handleFilterUrl(params, { page: 1 }) +
'">1</a> ... ' + dest;
}
return dest;
};
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2016-05-19 10:20:08
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-31 16:53:44
* @Last Modified time: 2016-05-31 17:39:45
*/
'use strict';
... ... @@ -94,11 +94,14 @@ exports.getSaleOthersData = (params) => {
// 获取商品数据和顶部筛选条件
if (result[0].code === 200) {
finalResult.goods = productProcess.processProductList(result[0].data.product_list);
finalResult.filters = saleHandler.handleSaleFilterData(result[0].data.filter, params);
if (!_.isEmpty(result[0].data.filter)) {
finalResult.filters = saleHandler.handleSaleFilterData(result[0].data.filter, params);
}
// 处理排序数据
finalResult.opts = saleHandler.handleSaleOptsData(params, result[0].data.total);
finalResult.totalCount = result[0].data.total;
finalResult.pager = saleHandler.handleSalePagerData(result[0].data.total, params);
}
// 获取焦点图数据
... ...