Authored by 周少峰

delete search handler

1 -/*  
2 - * @Author: sefon  
3 - * @Date: 2016-06-02 15:50:47  
4 - * @Last Modified by: Targaryen  
5 - * @Last Modified time: 2016-06-22 18:36:26  
6 - */  
7 -  
8 -'use strict';  
9 -const _ = require('lodash');  
10 -const helpers = global.yoho.helpers;  
11 -const queryString = require('querystring');  
12 -  
13 -// 打折、新品、限量  
14 -const checksName = {  
15 - new: '新品',  
16 - specialoffer: '打折',  
17 - limited: '限量'  
18 -};  
19 -  
20 -/**  
21 - * 处理用于筛选的 URL , 拼接 URL 参数  
22 - * @param originParam 当前 URL 中的参数  
23 - * @param newParam 要拼接的 参数  
24 - * @returns {string}  
25 - */  
26 -const handleFilterUrl = (originParam, newParam) => {  
27 - let dest = '?';  
28 - let tempOriginParam = {};  
29 -  
30 - tempOriginParam = Object.assign(tempOriginParam, originParam, newParam);  
31 - delete tempOriginParam.uid;  
32 -  
33 - _.forEach(tempOriginParam, function(value, key) {  
34 - dest = dest + key + '=' + value + '&';  
35 - });  
36 -  
37 - return _.trim(dest, '&');  
38 -};  
39 -  
40 -  
41 -/**  
42 - * 处理选中数据  
43 - * @param {[type]} params [description]  
44 - * @param {[type]} origin [description]  
45 - * @param {[type]} param [description]  
46 - * @return {[type]} [description]  
47 - */  
48 -const handleCheckedData = (params, origin, param) => {  
49 - let dest = [];  
50 -  
51 - if (!_.isEmpty(origin)) {  
52 - _.forEach(origin, value => {  
53 - if (value.checked) {  
54 - let tempPatam = _.cloneDeep(params);  
55 -  
56 - // 删除选中  
57 - delete tempPatam[param];  
58 -  
59 - dest.push({  
60 - name: value.name,  
61 - href: handleFilterUrl(tempPatam)  
62 - });  
63 - }  
64 - });  
65 - }  
66 - return dest;  
67 -};  
68 -  
69 -/**  
70 - * 处理品牌筛选数据  
71 - * @param params  
72 - * @param origin  
73 - * @returns {{}}  
74 - */  
75 -const handleBrandCheckedData = (params, origin) => {  
76 - let dest = [];  
77 -  
78 - // 分拆品牌参数  
79 - let brands = _.split(params.brand, ',');  
80 - let intBrands = [];  
81 -  
82 - _.forEach(brands, value => {  
83 - intBrands.push(parseInt(value, 10));  
84 - });  
85 -  
86 - let checkedCount = 0;  
87 -  
88 - // 遍历品牌数据,如果在参数中,那么加 checked,将此数据加入到 checked 数组中  
89 - if (!_.isEmpty(origin)) {  
90 - _.forEach(origin, (value) => {  
91 - if (typeof _.find(intBrands, o => {  
92 - return _.isEqual(o, value.id);  
93 - }) !== 'undefined') {  
94 - let checked = {  
95 - name: value.name  
96 - }; // push 到已选择数组  
97 -  
98 - // 为了不污染原始数据  
99 - let tempIntBrands = _.cloneDeep(intBrands);  
100 -  
101 - // 去掉当前选项  
102 - _.remove(tempIntBrands, n => {  
103 - return n === value.id;  
104 - });  
105 -  
106 - // 拼接参数  
107 - let brand = '';  
108 -  
109 - // 建议保留,需要品牌可以单个删除时放开注释即可  
110 - // _.forEach(tempIntBrands, subValue => {  
111 - // brand += subValue + ',';  
112 - // });  
113 -  
114 - // 清除参数,保留没有去掉的参数  
115 - let tempParam = {  
116 - brand: brand  
117 - };  
118 -  
119 - checked.href = handleFilterUrl(params, tempParam);  
120 - if (checkedCount === 0) {  
121 - dest[0] = checked;  
122 - } else if (checkedCount === 1) {  
123 - dest[0].name += '、' + checked.name.substring(0, 3) + '...';  
124 - }  
125 - checkedCount++;  
126 -  
127 - // 建议保留,需要品牌可以单个删除时放开注释即可  
128 - // dest.push(checked);  
129 - }  
130 - });  
131 - }  
132 - return dest;  
133 -};  
134 -  
135 -/**  
136 - * 新品、折扣、限量  
137 - */  
138 -const hadleChecks = (name, params) => {  
139 - let tempParam = _.cloneDeep(params);  
140 -  
141 - tempParam[name] = 'Y';  
142 - let checksOpts = {  
143 - name: checksName[name],  
144 - checked: false,  
145 - href: handleFilterUrl(tempParam)  
146 - };  
147 -  
148 - if (params[name] && params[name] === 'Y') {  
149 - checksOpts.checked = false;  
150 - delete tempParam[name];  
151 - checksOpts.href = handleFilterUrl(tempParam);  
152 - }  
153 -  
154 - return checksOpts;  
155 -};  
156 -  
157 -  
158 -/**  
159 - * 处理 opts 排序数据  
160 - * @param params  
161 - * @param total  
162 - * @param extra 什么都可以传进来,多个参数传Object  
163 - * @returns {{}}  
164 - */  
165 -exports.handleOptsData = (params, total, extra) => {  
166 - let dest = {  
167 - sortType: [],  
168 - checks: []  
169 - };  
170 -  
171 - // 用来标记是否是折扣专场,折扣专场只需要前三个排序参数  
172 - let count = (extra === 'discont') ? 3 : 4;  
173 -  
174 - for (let i = 0; i < count; i++) {  
175 - let opt = {};  
176 -  
177 - switch (i) {  
178 - case 0:  
179 - opt.href = handleFilterUrl(params, {order: 's_t_desc'});  
180 - if (extra === 'discont') { // 如果是折扣专场  
181 - opt.name = '全部';  
182 - if (_.isEmpty(params.order) || params.order === 's_t_desc') {  
183 - opt.active = true;  
184 - } else {  
185 - opt.active = false;  
186 - }  
187 - } else {  
188 - opt.name = '默认';  
189 - opt.hasSortOrient = true;  
190 - if (_.isEmpty(params.order) || params.order === 's_n_desc') {  
191 - opt.active = true;  
192 - } else {  
193 - opt.active = false;  
194 - }  
195 - opt.desc = true;  
196 - }  
197 - break;  
198 - case 1:  
199 - if (params.order !== 's_t_desc' && params.order !== 's_t_asc') {  
200 - opt.href = handleFilterUrl(params, {order: 's_t_desc'});  
201 - opt.hasSortOrient = true;  
202 - } else {  
203 - opt.hasSortOrient = true;  
204 - opt.active = true;  
205 - if (params.order === 's_t_desc') {  
206 - opt.href = handleFilterUrl(params, {order: 's_t_asc'});  
207 - opt.desc = false;  
208 - } else {  
209 - opt.href = handleFilterUrl(params, {order: 's_t_desc'});  
210 - opt.desc = true;  
211 - }  
212 - }  
213 -  
214 - opt.name = '最新';  
215 - break;  
216 - case 2:  
217 - if (params.order !== 's_p_desc' && params.order !== 's_p_asc') {  
218 - opt.href = handleFilterUrl(params, {order: 's_p_desc'});  
219 - opt.hasSortOrient = true;  
220 - } else {  
221 - opt.hasSortOrient = true;  
222 - opt.active = true;  
223 - if (params.order === 's_p_desc') {  
224 - opt.href = handleFilterUrl(params, {order: 's_p_asc'});  
225 - opt.desc = false;  
226 - } else {  
227 - opt.href = handleFilterUrl(params, {order: 's_p_desc'});  
228 - opt.desc = true;  
229 - }  
230 - }  
231 -  
232 - opt.name = '价格';  
233 - break;  
234 - case 3:  
235 - if (params.order !== 'p_d_desc' && params.order !== 'p_d_asc') {  
236 - opt.href = handleFilterUrl(params, {order: 'p_d_desc'});  
237 - opt.hasSortOrient = true;  
238 - } else {  
239 - opt.hasSortOrient = true;  
240 - opt.active = true;  
241 - if (params.order === 'p_d_desc') {  
242 - opt.href = handleFilterUrl(params, {order: 'p_d_asc'});  
243 - opt.desc = false;  
244 - } else {  
245 - opt.href = handleFilterUrl(params, {order: 'p_d_desc'});  
246 - opt.desc = true;  
247 - }  
248 - }  
249 -  
250 - opt.name = '折扣';  
251 - break;  
252 - default:  
253 - break;  
254 - }  
255 -  
256 - dest.sortType.push(opt);  
257 - }  
258 -  
259 - // 上下翻页数据处理  
260 - dest.pageCounts = [{  
261 - href: handleFilterUrl(params, {limit: 200}),  
262 - count: 200  
263 - }, {  
264 - href: handleFilterUrl(params, {limit: 100}),  
265 - count: 100  
266 - }, {  
267 - href: handleFilterUrl(params, {limit: 60}),  
268 - count: 60  
269 - }];  
270 -  
271 - dest.curPage = _.isEmpty(params.page) ? 1 : params.page; // 当前页码数  
272 -  
273 - // 每页商品数量  
274 - dest.countPerPage = _.isEmpty(params.limit) ? 60 : params.limit;  
275 -  
276 - // 全部页码数量  
277 - dest.pageCount = parseInt(total / (_.isEmpty(params.limit) ? 60 : params.limit), 10) + 1;  
278 -  
279 - // 每页多少商品  
280 - let paramsLimit = parseInt((_.isEmpty(params.limit) ? 60 : params.limit), 10);  
281 -  
282 - // 上一页下一页  
283 - let preHref = (!_.isEmpty(params.page) && parseInt(params.page, 10) > 1) ?  
284 - parseInt(params.page, 10) - 1 : 1;  
285 - let nextHref = (!_.isEmpty(params.page)) ? parseInt(params.page, 10) + 1 : 2;  
286 -  
287 - if (dest.pageCount > 1 && (parseInt(params.page, 10) !== 1) &&  
288 - (parseInt(params.page, 10) !== dest.pageCount)) {  
289 - dest.preHref = handleFilterUrl(params, {page: preHref});  
290 - dest.nextHref = handleFilterUrl(params, {page: nextHref});  
291 - } else if (dest.pageCount > 1 && (parseInt(params.page, 10) === 1)) {  
292 - dest.nextHref = handleFilterUrl(params, {page: nextHref});  
293 - } else if (dest.pageCount > 1 && (parseInt(params.page, 10) === dest.pageCount)) {  
294 - dest.preHref = handleFilterUrl(params, {page: preHref});  
295 - }  
296 -  
297 - // 全部商品数  
298 - dest.totalCount = total;  
299 -  
300 - // 商品开始结束数  
301 - dest.start = (!_.isEmpty(params.page) ? (params.page - 1) : 0) * paramsLimit + 1;  
302 - if (total < paramsLimit) {  
303 - dest.end = total;  
304 - } else {  
305 - dest.end = (dest.pageCount === parseInt(params.page, 10)) ?  
306 - total : parseInt(dest.start, 10) + paramsLimit - 1;  
307 - }  
308 -  
309 - // 新品  
310 - if (extra.new === 'Y') {  
311 - dest.checks.push(hadleChecks('new', params));  
312 - }  
313 -  
314 - // 打折  
315 - if (extra.specialoffer === 'Y') {  
316 - dest.checks.push(hadleChecks('specialoffer', params));  
317 - }  
318 -  
319 - // 限量  
320 - if (extra.limited === 'Y') {  
321 - dest.checks.push(hadleChecks('limited', params));  
322 - }  
323 - return dest;  
324 -};  
325 -  
326 -/**  
327 - * 处理页面左侧分类筛选数据  
328 - * @param origin 分类原始数据,一般是接口返回数据中的 group_sort 字段  
329 - * @param params 当前 URL 中已有的参数  
330 - * @param extra 可以任意传值用来处理特殊情况  
331 - * @returns {{}}  
332 - */  
333 -exports.handleSortData = (origin, params) => {  
334 - let leftContent = {};  
335 -  
336 - leftContent.allSort = {};  
337 - leftContent.allSort.list = [];  
338 -  
339 - _.forEach(origin, value => {  
340 - let category = {  
341 - name: value.sort_name,  
342 - num: value.count,  
343 - childList: [  
344 - {  
345 - name: '全部' + value.sort_name,  
346 - num: value.count,  
347 - href: handleFilterUrl(params, {msort: value.sort_id}),  
348 - childActive: params.misort === value.sort_id  
349 - }  
350 - ],  
351 - href: handleFilterUrl(params, {msort: value.sort_id}),  
352 - active: params.msort === value.sort_id  
353 - };  
354 -  
355 - _.forEach(value.sub, subValue => {  
356 - category.childList.push({  
357 - name: subValue.sort_name,  
358 - num: subValue.count,  
359 - href: handleFilterUrl(params, {msort: value.sort_id, misort: subValue.sort_id}),  
360 - childActive: params.misort === subValue.sort_id  
361 - });  
362 - if (params.misort === subValue.sort_id) {  
363 - category.active = true;  
364 - }  
365 -  
366 - });  
367 -  
368 - leftContent.allSort.list.push(category);  
369 - });  
370 -  
371 - return leftContent;  
372 -};  
373 -  
374 -/**  
375 - * 处理一般筛选数据  
376 - * @param origin 要处理的筛选数据 filter  
377 - * @param params 当前 URL 中已有的参数,处理选中状态使用  
378 - * @returns {{}}  
379 - */  
380 -exports.handleFilterData = (origin, params) => {  
381 - let dest = {  
382 - ageLevel: [],  
383 - brand: {  
384 - default: [],  
385 - brandsShow: [],  
386 - brandIndex: [{  
387 - index: 'all',  
388 - name: '全部'  
389 - }, {  
390 - index: '0-9',  
391 - name: '0~9'  
392 - }],  
393 - showMore: true,  
394 - showMulti: true  
395 - },  
396 - price: [],  
397 - gender: [],  
398 - color: [],  
399 - checkedConditions: {  
400 - conditions: []  
401 - }  
402 - };  
403 -  
404 - // 品牌索引数据处理  
405 - for (let i = 65; i < 91; i++) {  
406 - dest.brand.brandIndex.push({  
407 - index: String.fromCharCode(i).toLowerCase(),  
408 - name: String.fromCharCode(i)  
409 - });  
410 - }  
411 -  
412 - // 品牌数据处理  
413 - // 分拆品牌参数  
414 - let brands = _.split(params.brand, ',');  
415 - let intBrands = [];  
416 -  
417 - _.forEach(brands, value => {  
418 - intBrands.push(parseInt(value, 10));  
419 - });  
420 -  
421 - if (origin.brand) {  
422 - let count = 0;  
423 -  
424 - _.forEach(origin.brand, function(value) {  
425 - let brand = {  
426 - checked: (typeof _.find(intBrands, o => {  
427 - return _.isEqual(o, value.id);  
428 - }) !== 'undefined'),  
429 - href: handleFilterUrl(params, {brand: value.id}),  
430 - name: value.brand_name,  
431 - key: value.brand_domain,  
432 - id: value.id  
433 - };  
434 -  
435 - if (!_.isEmpty(value.brand_alif)) {  
436 - if (!_.isNaN(parseInt(value.brand_alif, 10))) {  
437 - brand.index = '0-9';  
438 - } else {  
439 - brand.index = value.brand_alif.toLowerCase();  
440 - }  
441 - }  
442 -  
443 - if (count < 10) {  
444 - dest.brand.default.push(brand);  
445 - }  
446 -  
447 - dest.brand.brandsShow.push(brand);  
448 - count++;  
449 - });  
450 -  
451 - // 没有品牌的情况下将 brand 设置为 false,前端不显示 品牌  
452 - if (_.size(dest.brand.brandsShow) <= 0) {  
453 - dest.brand = false;  
454 - } else {  
455 - // 品牌排序  
456 - dest.brand.brandsShow = _.sortBy(dest.brand.brandsShow, o => {  
457 - return o.index;  
458 - });  
459 - }  
460 - }  
461 -  
462 - // 处理价格筛选数据  
463 - let priceRangechecked = false;  
464 -  
465 - if (!_.isEmpty(origin.priceRange)) {  
466 - _.forEach(origin.priceRange, (value, key) => {  
467 - if (params.price === key) {  
468 - priceRangechecked = true;  
469 - }  
470 - let price = {  
471 - checked: params.price === key,  
472 - href: handleFilterUrl(params, {price: key}),  
473 - name: value  
474 - };  
475 -  
476 - dest.price.push(price);  
477 - });  
478 - }  
479 -  
480 - // 处理用户自主填写的价格区间  
481 - if (!priceRangechecked && params.price) {  
482 - let customPrice = _.split(params.price, ',');  
483 -  
484 - if (customPrice[1] !== '99999') {  
485 - dest.customPrice = {  
486 - min: customPrice[0],  
487 - max: customPrice[1]  
488 - };  
489 - dest.checkedConditions.conditions.push({  
490 - name: '¥ ' + customPrice[0] + '-' + customPrice[1],  
491 - href: handleFilterUrl(params, {price: ''})  
492 - });  
493 - }  
494 - }  
495 -  
496 - // 处理性别数据  
497 - dest.gender = [{  
498 - name: 'BOYS',  
499 - href: handleFilterUrl(params, {gender: '1,3'}),  
500 - checked: params.gender === '1,3'  
501 - }, {  
502 - name: 'GIRLS',  
503 - href: handleFilterUrl(params, {gender: '2,3'}),  
504 - checked: params.gender === '2,3'  
505 - }];  
506 -  
507 - // 尺码处理  
508 - if (!_.isEmpty(origin.size) && (params.msort || params.misort || params.sort)) {  
509 -  
510 - dest.size = [];  
511 -  
512 - if (_.isArray(origin.size)) {  
513 - _.forEach(origin.size, value => {  
514 - dest.size.push({  
515 - checked: parseInt(params.size, 10) === parseInt(value.size_id, 10),  
516 - href: handleFilterUrl(params, {  
517 - size: value.size_id  
518 - }),  
519 - name: value.size_name  
520 - });  
521 - });  
522 - } else {  
523 - dest.size.push({  
524 - checked: parseInt(params.size, 10) === parseInt(origin.size.size_id, 10),  
525 - href: handleFilterUrl(params, {  
526 - size: origin.size.size_id  
527 - }),  
528 - name: origin.size.size_name  
529 - });  
530 - }  
531 -  
532 - dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,  
533 - handleCheckedData(params, dest.size, 'size'));  
534 - }  
535 -  
536 - // 处理颜色筛选数据  
537 - if (!_.isEmpty(origin.color)) {  
538 - _.forEach(origin.color, (value) => {  
539 - let color = {  
540 - checked: parseInt(params.color, 10) === parseInt(value.color_id, 10),  
541 - href: handleFilterUrl(params, {color: value.color_id}),  
542 - name: value.color_name,  
543 - rgb: value.color_value ? 'url(' + value.color_value + ')' : '#' + value.color_code  
544 - };  
545 -  
546 - // 处理颜色选中数据  
547 - if (color.checked) {  
548 - dest.checkedConditions.conditions.push(color);  
549 - }  
550 -  
551 - dest.color.push(color);  
552 - });  
553 - }  
554 -  
555 - // 处理年龄段  
556 - if (!_.isEmpty(origin.ageLevel)) {  
557 - _.forEach(origin.ageLevel, (value) => {  
558 - let ageLevel = {  
559 - checked: params.ageLevel === value.id,  
560 - href: handleFilterUrl(params, {ageLevel: value.id}),  
561 - name: value.name  
562 - };  
563 -  
564 - // 处理颜色年龄段数据  
565 - if (ageLevel.checked) {  
566 - dest.checkedConditions.conditions.push(ageLevel);  
567 - }  
568 -  
569 - dest.ageLevel.push(ageLevel);  
570 - });  
571 - }  
572 -  
573 - // 清除所有选中数据  
574 - let remainParams = {};  
575 -  
576 - if (params.id) {  
577 - remainParams.id = params.id;  
578 - }  
579 - dest.checkedConditions.clearUrl = '?' + queryString.stringify(remainParams);  
580 -  
581 - // 处理频道筛选数据  
582 - dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,  
583 - handleCheckedData(params, dest.gender, 'gender'));  
584 -  
585 - // 处理品牌筛选数据  
586 - if (dest.brand.brandsShow) {  
587 -  
588 - dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,  
589 - handleBrandCheckedData(params, dest.brand.brandsShow));  
590 - }  
591 -  
592 - // 处理价格筛选数据  
593 - dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,  
594 - handleCheckedData(params, dest.price, 'price'));  
595 -  
596 - return dest;  
597 -};  
598 -  
599 -/**  
600 - * 根据页面设置面包屑导航  
601 - * @type {[type]}  
602 - */  
603 -exports.handlePathNavData = (data, params, page) => {  
604 - let pathNav = [{  
605 - href: '/',  
606 - name: '首页', // TODO 从根据cookie获取频道  
607 - pathTitle: '首页'  
608 - }];  
609 -  
610 - switch (page) {  
611 - case 'search':  
612 - // 搜索结果提示  
613 - if (params.query || params.keywords) {  
614 - params.query = params.query || params.keywords;  
615 - pathNav.push({  
616 - name: '“<span id="nav_keyword">' +  
617 - params.query + '</span>”&nbsp;&nbsp;共<span id="nav_keyword_count">' +  
618 - data.total + '</span>个结果'  
619 - });  
620 - } else {  
621 - pathNav.push({  
622 - name: '所有商品'  
623 - });  
624 - }  
625 - break;  
626 - case 'brand':  
627 -  
628 - // 品牌  
629 - pathNav.push(  
630 - {  
631 - name: '品牌一览',  
632 - pathTitle: '品牌一览',  
633 - href: helpers.urlFormat('brand')  
634 - },  
635 - {  
636 - name: data.brandNameEn + data.brandNameCn,  
637 - pathTitle: data.brandNameEn + data.brandNameCn  
638 - }  
639 - );  
640 - break;  
641 - default :  
642 - // 分类  
643 - _.forEach(data, (sort) => {  
644 - if (sort.sort_id === params.msort) {  
645 - pathNav.push({  
646 - name: sort.sort_name,  
647 - href: helpers.urlFormat('/product/outlets/list', {msort: sort.sort_id}),  
648 - pathTitle: sort.sort_name  
649 - });  
650 - }  
651 -  
652 - if (!_.isEmpty(sort.sub)) {  
653 - _.forEach(sort.sub, misort => {  
654 - if (misort.sort_id === params.misort) {  
655 - pathNav.push({  
656 - name: misort.sort_name,  
657 - pathTitle: misort.sort_name  
658 - });  
659 -  
660 - }  
661 - });  
662 - }  
663 - });  
664 - break;  
665 - }  
666 - return {  
667 - pathNav: pathNav  
668 - };  
669 -};  
670 -  
671 -/**  
672 - * 分页  
673 - * @param {[type]} total 总页数  
674 - * @param {[type]} params 筛选条件  
675 - * @return {[type]} [description]  
676 - */  
677 -exports.handlePagerData = (total, params) => {  
678 - let dest = {  
679 - prePage: {  
680 - url: ''  
681 - },  
682 - nextPage: {  
683 - url: ''  
684 - },  
685 - pages: []  
686 - };  
687 -  
688 - let currentPage = parseInt((_.isEmpty(params.page) ? 1 : params.page), 10); // 当前页  
689 - let perPageCount = parseInt((_.isEmpty(params.limit) ? 60 : params.limit), 10); // 每页商品数  
690 - let totalPage = parseInt(total / perPageCount, 10) + 1; // 总页数  
691 -  
692 - if (currentPage === 1) {  
693 - // 当前页为 1,一定没有上一页  
694 - delete dest.prePage;  
695 - } else {  
696 - dest.prePage.url = handleFilterUrl(params, {page: currentPage - 1});  
697 - }  
698 -  
699 - if (currentPage === totalPage) {  
700 -  
701 - // 当前页为最后一页,一定没有下一页  
702 - delete dest.nextPage;  
703 - } else {  
704 - dest.nextPage.url = handleFilterUrl(params, {page: currentPage + 1});  
705 - }  
706 -  
707 - // 页码临时数据  
708 - let pages = [];  
709 -  
710 - if (currentPage > 2 && currentPage <= totalPage - 2) {  
711 - for (let i = currentPage - 2; i <= ((currentPage + 2) > totalPage ? totalPage : (currentPage + 2)); i++) {  
712 - pages.push({  
713 - url: handleFilterUrl(params, {page: i}),  
714 - num: i,  
715 - cur: currentPage === i  
716 - });  
717 - }  
718 -  
719 - // 处理页码小于等于 2 的情况  
720 - } else if (currentPage <= 2) {  
721 - for (let i = 1; i <= (totalPage < 5 ? totalPage : 5); i++) {  
722 - pages.push({  
723 - url: handleFilterUrl(params, {page: i}),  
724 - num: i,  
725 - cur: currentPage === i  
726 - });  
727 - }  
728 - } else if (currentPage > totalPage - 2) {  
729 - for (let i = totalPage; i >= totalPage - 4; i--) {  
730 - pages.push({  
731 - url: handleFilterUrl(params, {page: i}),  
732 - num: i,  
733 - cur: currentPage === i  
734 - });  
735 - }  
736 - pages = _.sortBy(pages, ['num']);  
737 - }  
738 -  
739 - let prevPages = [];  
740 - let nextPages = [];  
741 -  
742 - if (_.size(pages) === 5) {  
743 - if (currentPage > 4) {  
744 - prevPages.push({  
745 - url: handleFilterUrl(params, {page: 1}),  
746 - num: 1  
747 - });  
748 - prevPages.push({  
749 - num: '...'  
750 - });  
751 - }  
752 - if (currentPage < totalPage - 2) {  
753 - nextPages.push({  
754 - num: '...'  
755 - });  
756 - nextPages.push({  
757 - url: handleFilterUrl(params, {page: totalPage}),  
758 - num: totalPage  
759 - });  
760 - }  
761 - }  
762 -  
763 - // 商品开始结束数  
764 - dest.tip = {  
765 - total: total,  
766 - start: (currentPage ? currentPage - 1 : 0) * perPageCount + 1  
767 - };  
768 -  
769 - let endPageNum = (totalPage === currentPage) ?  
770 - total : parseInt(dest.tip.start, 10) + perPageCount - 1;  
771 -  
772 - dest.tip.end = (total < perPageCount) ? total : endPageNum;  
773 - dest.pages = _.concat(prevPages, pages, nextPages);  
774 -  
775 - return dest;  
776 -  
777 -};  
778 -  
779 -/**  
780 - * 处理分类介绍  
781 - * @type {[type]}  
782 - */  
783 -exports.handleSortIntro = (data, params) => {  
784 - let sortIntro = {  
785 - name: data.title,  
786 - enName: data.subtitle,  
787 - description: data.intro,  
788 - img: data.logo,  
789 - keyEntry: []  
790 - };  
791 -  
792 - _.forEach(data.keyword, function(value) {  
793 - sortIntro.keyEntry.push({  
794 - name: value.word,  
795 - url: helpers.urlFormat(value.url, params)  
796 - });  
797 - });  
798 -  
799 - return sortIntro;  
800 -};  
801 -  
802 -/**  
803 - * 处理分类页左侧广告  
804 - * @type {[type]}  
805 - */  
806 -exports.handleSortAds = (data) => {  
807 - let sortAds = {  
808 - picLink: {  
809 - picTitle: '',  
810 - list: []  
811 - }  
812 - };  
813 -  
814 - _.forEach(data, function(value) {  
815 - sortAds.picLink.list.push({  
816 - href: value.ads_url,  
817 - src: value.ads_image  
818 - });  
819 - });  
820 -  
821 - return sortAds;  
822 -};  
823 -  
824 -/**  
825 - * 处理一周新品上架  
826 - * @type {[type]}  
827 - */  
828 -exports.handleWeekNew = (data, params) => {  
829 - let dest = {  
830 - newSales: {  
831 - name: '',  
832 - list: []  
833 - }  
834 - };  
835 -  
836 - _.forEach(data.recent, function(value, key) {  
837 - dest.newSales.list.push({  
838 - name: key,  
839 - href: handleFilterUrl(params, {shelveTime: key}),  
840 - active: key === params.shelveTime  
841 - });  
842 - });  
843 -  
844 - return dest;  
845 -};  
846 -  
847 -/**  
848 - * 处理搜索提示  
849 - * @type {[type]}  
850 - */  
851 -exports.handleSuggest = (data) => {  
852 - let suggest = [];  
853 -  
854 - _.forEach(data, function(value) {  
855 - suggest.push({  
856 - href: helpers.urlFormat('', {query: value.keyword}, 'search'),  
857 - keyword: value.keyword,  
858 - count: value.count  
859 - });  
860 - });  
861 -  
862 - return suggest;  
863 -};  
864 -  
865 -/**  
866 - * 处理品牌页banner  
867 - * @type {[type]}  
868 - */  
869 -exports.handleBrandBanner = (data) => {  
870 -  
871 - return {  
872 - bannerHeight: 150,  
873 - banner: data.brandBanner.split('?')[0],  
874 - brandHome: data.url,  
875 - brandIntro: helpers.urlFormat('/about', '', data.brandDomain),  
876 - dataId: data.brandId  
877 - };  
878 -};  
879 -  
880 -/**  
881 - * 处理品牌系列  
882 - * @type {[type]}  
883 - */  
884 -exports.handleFolderData = (data) => {  
885 - let dest = [];  
886 -  
887 - _.forEach(data, (value) => {  
888 - dest.push({  
889 - href: '?series=' + value.id,  
890 - src: '?series=' + value.series_banner  
891 - });  
892 - });  
893 -};  
894 -  
895 -/**  
896 - * 筛选类链接处理的对外接口  
897 - * @type {[type]}  
898 - */  
899 -exports.handleFilterUrl = handleFilterUrl;  
900 -  
901 -/**  
902 - * 处理选中数据的对外接口  
903 - * @type {[type]}  
904 - */  
905 -exports.handleCheckedData = handleCheckedData;