Authored by 郭成尧

分页

@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 * @Author: Targaryen 2 * @Author: Targaryen
3 * @Date: 2016-05-30 16:20:03 3 * @Date: 2016-05-30 16:20:03
4 * @Last Modified by: Targaryen 4 * @Last Modified by: Targaryen
5 - * @Last Modified time: 2016-06-03 16:04:18 5 + * @Last Modified time: 2016-06-03 16:29:40
6 */ 6 */
7 7
8 'use strict'; 8 'use strict';
@@ -17,7 +17,7 @@ const outletsApi = require('./outlets-api'); @@ -17,7 +17,7 @@ const outletsApi = require('./outlets-api');
17 const productProcess = require(`${utils}/product-process`); 17 const productProcess = require(`${utils}/product-process`);
18 const headerModel = require('../../../doraemon/models/header'); 18 const headerModel = require('../../../doraemon/models/header');
19 19
20 -// const publicHandler = require('./public-handler'); 20 +const publicHandler = require('./public-handler');
21 21
22 // 奥莱频道资源码 22 // 奥莱频道资源码
23 const channelCode = { 23 const channelCode = {
@@ -70,7 +70,7 @@ exports.getOutletsIndexData = (params) => { @@ -70,7 +70,7 @@ exports.getOutletsIndexData = (params) => {
70 if (result[5].code === 200) { 70 if (result[5].code === 200) {
71 finalResult.goodsBoard.list = productProcess.processProductList(result[5].data.product_list); 71 finalResult.goodsBoard.list = productProcess.processProductList(result[5].data.product_list);
72 72
73 - // finalResult.pager = publicHandler.handleSalePagerData(result[0].data.total, params); 73 + finalResult.pager = publicHandler.handleSalePagerData(result[5].data.total, params);
74 } 74 }
75 75
76 return finalResult; 76 return finalResult;
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 * @Author: Targaryen 2 * @Author: Targaryen
3 * @Date: 2016-06-02 15:50:47 3 * @Date: 2016-06-02 15:50:47
4 * @Last Modified by: Targaryen 4 * @Last Modified by: Targaryen
5 -* @Last Modified time: 2016-06-02 16:05:54 5 +* @Last Modified time: 2016-06-03 16:36:28
6 */ 6 */
7 7
8 'use strict'; 8 'use strict';
@@ -14,7 +14,7 @@ const _ = require('lodash'); @@ -14,7 +14,7 @@ const _ = require('lodash');
14 * @param {[type]} newParam [description] 14 * @param {[type]} newParam [description]
15 * @return {[type]} [description] 15 * @return {[type]} [description]
16 */ 16 */
17 -exports.handleFilterUrl = (originParam, newParam) => { 17 +const handleFilterUrl = (originParam, newParam) => {
18 let dest = '?'; 18 let dest = '?';
19 let tempOriginParam = {}; 19 let tempOriginParam = {};
20 20
@@ -45,6 +45,12 @@ exports.handleFilterUrl = (originParam, newParam) => { @@ -45,6 +45,12 @@ exports.handleFilterUrl = (originParam, newParam) => {
45 }; 45 };
46 46
47 /** 47 /**
  48 + * 筛选类链接处理的对外接口
  49 + * @type {[type]}
  50 + */
  51 +exports.handleFilterUrl = handleFilterUrl;
  52 +
  53 +/**
48 * 处理选中数据 54 * 处理选中数据
49 * @param {[type]} params [description] 55 * @param {[type]} params [description]
50 * @param {[type]} origin [description] 56 * @param {[type]} origin [description]
@@ -66,7 +72,7 @@ exports.handleCheckedData = (params, origin, param) => { @@ -66,7 +72,7 @@ exports.handleCheckedData = (params, origin, param) => {
66 72
67 tempParam[param] = ''; 73 tempParam[param] = '';
68 74
69 - // checked.href = handleFilterUrl(params, tempParam); 75 + checked.href = handleFilterUrl(params, tempParam);
70 76
71 dest.push(checked); 77 dest.push(checked);
72 } 78 }
@@ -75,3 +81,83 @@ exports.handleCheckedData = (params, origin, param) => { @@ -75,3 +81,83 @@ exports.handleCheckedData = (params, origin, param) => {
75 81
76 return dest; 82 return dest;
77 }; 83 };
  84 +
  85 +/**
  86 + * 处理分页数据
  87 + * @param {[type]} total [description]
  88 + * @param {[type]} params [description]
  89 + * @return {[type]} [description]
  90 + */
  91 +exports.handleSalePagerData = (total, params) => {
  92 +
  93 +
  94 + // 当前页
  95 + let currentPage = parseInt((_.isEmpty(params.page) ? 1 : params.page), 10);
  96 + let perPageCount = parseInt((_.isEmpty(params.limit) ? 60 : params.limit), 10);
  97 + let totalPage = parseInt(total / perPageCount, 10) + 1;
  98 +
  99 + let dest = '<a href ="' + handleFilterUrl(params, { page: (currentPage) }) +
  100 + '" class="cur">' + currentPage + '</a>';
  101 +
  102 + // 先处理大多数情况
  103 + if ((currentPage > 2) && (currentPage < (parseInt(total, 10) / perPageCount) - 1)) {
  104 +
  105 + for (let i = 1; i < 3; i++) {
  106 + dest = '<a href ="' + handleFilterUrl(params, { page: (currentPage - i) }) + '">' +
  107 + (currentPage - i) + '</a> ' + dest + ' <a href ="' +
  108 + handleFilterUrl(params, { page: (currentPage + i) }) +
  109 + '">' + (currentPage + i) + '</a>';
  110 + }
  111 +
  112 + // 处理页码小于2的情况
  113 + } else if (currentPage <= 2) {
  114 + for (let i = currentPage - 1; i > 0; i--) {
  115 + dest = '<a href ="' + handleFilterUrl(params, { page: i }) +
  116 + '">' + i + '</a>' + dest;
  117 + }
  118 +
  119 + for (let i = currentPage + 1; i < (totalPage < 6 ? totalPage : 6); i++) {
  120 + dest += '<a href ="' + handleFilterUrl(params, { page: i }) +
  121 + '">' + i + '</a>';
  122 + }
  123 +
  124 + // 处理页码大于最大页-2的情况
  125 + } else if (currentPage > totalPage - 2) {
  126 + for (let i = currentPage + 1; i < totalPage + 1; i++) {
  127 + dest += '<a href ="' + handleFilterUrl(params, { page: i }) +
  128 + '">' + i + '</a>';
  129 + }
  130 +
  131 + for (let i = currentPage - 1; i > (currentPage - 5 > 1 ? currentPage - 5 : 1); i--) {
  132 + dest = '<a href ="' + handleFilterUrl(params, { page: i }) +
  133 + '">' + i + '</a>' + dest;
  134 + }
  135 + }
  136 +
  137 + // 处理后省略号的情况
  138 + if ((totalPage > 5) && (currentPage < (totalPage - 2))) {
  139 +
  140 + dest += ' ... <a href ="' + handleFilterUrl(params, { page: totalPage }) +
  141 + '">' + totalPage + '</a>';
  142 +
  143 + }
  144 +
  145 + // 处理前省略号的情况
  146 + if (currentPage > 3) {
  147 + dest = '<a href ="' + handleFilterUrl(params, { page: 1 }) +
  148 + '">1</a> ... ' + dest;
  149 + }
  150 +
  151 + // 处理上一页下一页
  152 + if (currentPage !== 1) {
  153 + dest = '<a href="' + handleFilterUrl(params, { page: currentPage - 1 }) +
  154 + '"><span class="iconfont">&#xe60e;上一页</span></a>' + dest;
  155 + }
  156 +
  157 + if (currentPage !== totalPage) {
  158 + dest += '<a href="' + handleFilterUrl(params, { page: currentPage + 1 }) +
  159 + '"><span class="iconfont">下一页&#xe60c;</span></a>';
  160 + }
  161 +
  162 + return dest;
  163 +};