Authored by yyq

global list

@@ -18,7 +18,8 @@ const globalModel = require(`${mRoot}/global`); // global model @@ -18,7 +18,8 @@ const globalModel = require(`${mRoot}/global`); // global model
18 exports.list = (req, res, next) => { 18 exports.list = (req, res, next) => {
19 globalModel.getGlobalProductListData(req.query, req.yoho).then(result => { 19 globalModel.getGlobalProductListData(req.query, req.yoho).then(result => {
20 res.render('list/index', Object.assign({ 20 res.render('list/index', Object.assign({
21 - page: 'list' 21 + page: 'list',
  22 + pageClass: 'global-list-page'
22 }, result)); 23 }, result));
23 }).catch(next); 24 }).catch(next);
24 }; 25 };
@@ -17,9 +17,133 @@ const searchHandler = require('./search-handler'); @@ -17,9 +17,133 @@ const searchHandler = require('./search-handler');
17 const pager = require(`${global.utils}/pager`).setPager; 17 const pager = require(`${global.utils}/pager`).setPager;
18 const productProcess = require(`${global.utils}/product-process`); 18 const productProcess = require(`${global.utils}/product-process`);
19 19
  20 +const GLOBAL_LIST_URI = '/product/global/list';
  21 +
  22 +const _handelGlobalPathNav = (data, channel, page) => {
  23 + let rootName = '首页';
  24 +
  25 + if (channel && _.isString(channel)) {
  26 + rootName = `${channel.toUpperCase()}首页`;
  27 + }
  28 +
  29 + let pathNav = [{
  30 + href: channel === 'boys' ? '/' : helpers.urlFormat(`/${channel}/`),
  31 + name: rootName,
  32 + pathTitle: rootName
  33 + }, {
  34 + href: helpers.urlFormat(GLOBAL_LIST_URI),
  35 + name: '全球购',
  36 + pathTitle: '全球购'
  37 + }];
  38 +
  39 + if (data.sort) {
  40 + pathNav.push({
  41 + href: helpers.urlFormat(GLOBAL_LIST_URI, data.sort.params),
  42 + name: data.sort.name,
  43 + pathTitle: data.sort.name
  44 + });
  45 + }
  46 +
  47 + if (data.brand) {
  48 + pathNav.push({
  49 + name: data.brand.name,
  50 + pathTitle: data.brand.name
  51 + });
  52 + page = 'global-brand';
  53 + }
  54 +
  55 + return {
  56 + pathNav: pathNav,
  57 + listType: page
  58 + };
  59 +};
  60 +
  61 +const _checkSortEqual = (rp, params) => {
  62 + let status = true;
  63 +
  64 + _.forEach(rp, (value, key) => {
  65 + if (status && params[key] !== value) {
  66 + status = false;
  67 + }
  68 + });
  69 +
  70 + return status;
  71 +};
  72 +
  73 +const _handelGlobalSort = (origin, params, originParams) => {
  74 + let all = [{
  75 + name: '全部品类',
  76 + href: `${searchHandler.handleFilterUrl(params, {}, {msort: true, misort: true, sort: true})}`
  77 + }];
  78 + let list = [];
  79 + let selectSort = {};
  80 +
  81 + _.forEach(origin, value => {
  82 + let equalCategory = _checkSortEqual(value.relation_parameter, originParams);
  83 + let category = {
  84 + name: value.category_name,
  85 + num: value.node_count,
  86 + childList: [
  87 + {
  88 + name: `全部${value.category_name}`,
  89 + num: value.node_count,
  90 + href: `${searchHandler.handleFilterUrl(params, value.relation_parameter)}`,
  91 + childActive: _checkSortEqual(value.relation_parameter, originParams)
  92 + }
  93 + ]
  94 + };
  95 +
  96 + if (equalCategory) {
  97 + Object.assign(selectSort, {
  98 + name: value.category_name,
  99 + params: value.relation_parameter
  100 + });
  101 + }
  102 +
  103 + _.forEach(value.sub, subValue => {
  104 + let child = {
  105 + name: subValue.category_name,
  106 + num: subValue.node_count,
  107 + href: `${searchHandler.handleFilterUrl(params, subValue.relation_parameter)}`,
  108 + childActive: _checkSortEqual(subValue.relation_parameter, originParams)
  109 + };
  110 +
  111 + category.childList.push(child);
  112 +
  113 + if (child.childActive) {
  114 + category.active = true;
  115 + Object.assign(selectSort, {
  116 + name: subValue.category_name,
  117 + params: subValue.relation_parameter
  118 + });
  119 + }
  120 + });
  121 +
  122 + list.push(category);
  123 + });
  124 +
  125 + return {
  126 + allSort: {
  127 + all: all,
  128 + list: list
  129 + },
  130 + selectSort: selectSort
  131 + };
  132 +};
  133 +
20 const getGlobalProductListData = (params, yoho) => { 134 const getGlobalProductListData = (params, yoho) => {
  135 + let dps = {};
  136 +
  137 + if (params.brand) {
  138 + dps.brand = params.brand;
  139 + }
  140 +
21 return Promise.props({ 141 return Promise.props({
22 header: headerModel.requestHeaderData(yoho.channel), 142 header: headerModel.requestHeaderData(yoho.channel),
  143 + fullList: globalApi.getGlobalProductListAsync({
  144 + physical_channel: yoho.channelNum,
  145 + limit: 1
  146 + }),
23 list: globalApi.getGlobalProductListAsync(Object.assign({ 147 list: globalApi.getGlobalProductListAsync(Object.assign({
24 physical_channel: yoho.channelNum 148 physical_channel: yoho.channelNum
25 }, params, {limit: params.limit ? params.limit - 1 : 59})) 149 }, params, {limit: params.limit ? params.limit - 1 : 59}))
@@ -29,23 +153,49 @@ const getGlobalProductListData = (params, yoho) => { @@ -29,23 +153,49 @@ const getGlobalProductListData = (params, yoho) => {
29 Object.assign(resData, result.header); 153 Object.assign(resData, result.header);
30 154
31 if (result.list.code === 200) { 155 if (result.list.code === 200) {
32 - let totalNum = _.get(result.list, 'data.total', 0); 156 + let listData = _.get(result.list, 'data', {});
  157 + let totalNum = _.get(listData, 'total', 0);
33 158
34 - // let filters = Object.assign(searchHandler.handleFilterDataAll(result[2].data, params),  
35 - // finalResult.list.leftContent.sort); 159 + // opts 显示新品、折扣
  160 + listData.filter = listData.filter || {};
  161 + Object.assign(listData.filter, {
  162 + new: 'Y',
  163 + specialoffer: 'Y'
  164 + });
36 165
37 - // filters.checkedConditions.conditions = _.concat(filters.checkedConditions.conditions,  
38 - // finalResult.list.leftContent.checked);  
39 resData.list = { 166 resData.list = {
40 - // filters: filters,  
41 - // opts: searchHandler.handleOptsData(params, result[2].data.total, result[2].data.filter), 167 + leftContent: _handelGlobalSort(_.get(result.fullList, 'data.filter.group_sort', []), dps, params),
  168 + filters: searchHandler.handleFilterDataAll(listData, params),
  169 + opts: searchHandler.handleOptsData(params, totalNum, listData.filter),
42 totalCount: totalNum, 170 totalCount: totalNum,
43 - footPager: pager(_.get(result.list, 'data.page_total', 0), params),  
44 - goods: productProcess.processProductList(_.get(result.list, 'data.product_list', []), 171 + footPager: pager(_.get(listData, 'page_total', 0), params),
  172 + goods: productProcess.processProductList(_.get(listData, 'product_list', []),
45 Object.assign({showDiscount: false, isGlobal: true}, params)), 173 Object.assign({showDiscount: false, isGlobal: true}, params)),
46 hasNextPage: searchHandler.handleNextPage(params, totalNum), 174 hasNextPage: searchHandler.handleNextPage(params, totalNum),
47 latestWalk: 6 // 最近浏览记录 175 latestWalk: 6 // 最近浏览记录
48 }; 176 };
  177 +
  178 + let pathInfo = {};
  179 +
  180 + if (dps.brand) {
  181 + let bandInfo = _.find(_.get(result.fullList, 'data.filter.brand', []), o => {
  182 + return o.id * 1 === dps.brand * 1;
  183 + });
  184 +
  185 + if (bandInfo) {
  186 + pathInfo.brand = {
  187 + name: bandInfo.brand_name
  188 + };
  189 + }
  190 + }
  191 +
  192 + let selectedSort = _.get(resData.list, 'leftContent.selectSort', {});
  193 +
  194 + if (!_.isEmpty(selectedSort)) {
  195 + pathInfo.sort = selectedSort;
  196 + }
  197 +
  198 + Object.assign(resData.list, _handelGlobalPathNav(pathInfo, yoho.channel, 'global-list'));
49 } 199 }
50 200
51 return resData; 201 return resData;
@@ -68,7 +218,7 @@ const getGlobalProductDetailData = (skn, channelNum, channel) => { @@ -68,7 +218,7 @@ const getGlobalProductDetailData = (skn, channelNum, channel) => {
68 218
69 resData.banner = { 219 resData.banner = {
70 bgColor: '#000', 220 bgColor: '#000',
71 - homeUrl: helpers.urlFormat('/product/global/list', {brand: brandInfo.brand_id}), 221 + homeUrl: helpers.urlFormat(GLOBAL_LIST_URI, {brand: brandInfo.brand_id}),
72 brandName: brandInfo.brand_name, 222 brandName: brandInfo.brand_name,
73 logo: brandInfo.brand_ico 223 logo: brandInfo.brand_ico
74 }; 224 };
@@ -76,7 +226,7 @@ const getGlobalProductDetailData = (skn, channelNum, channel) => { @@ -76,7 +226,7 @@ const getGlobalProductDetailData = (skn, channelNum, channel) => {
76 resData.pathNav = _.concat( 226 resData.pathNav = _.concat(
77 homeService.getHomeChannelNav(channel), 227 homeService.getHomeChannelNav(channel),
78 [ 228 [
79 - {name: '全球购', href: helpers.urlFormat('/product/global/list')}, 229 + {name: '全球购', href: helpers.urlFormat(GLOBAL_LIST_URI)},
80 {name: detailInfo.product_name || ''} 230 {name: detailInfo.product_name || ''}
81 ] 231 ]
82 ); 232 );
@@ -137,7 +287,7 @@ const getGlobalProductDetailData = (skn, channelNum, channel) => { @@ -137,7 +287,7 @@ const getGlobalProductDetailData = (skn, channelNum, channel) => {
137 } 287 }
138 } 288 }
139 289
140 - if (result.html) { 290 + if (result.html && !_.get(result.html, 'code', '')) {
141 let regContent = /<body[^>]*>([\s\S]*)<\/body>/.exec(result.html); 291 let regContent = /<body[^>]*>([\s\S]*)<\/body>/.exec(result.html);
142 292
143 html = regContent[1] || ''; 293 html = regContent[1] || '';
@@ -647,7 +647,9 @@ exports.handleFilterData = (origin, params, total) => { @@ -647,7 +647,9 @@ exports.handleFilterData = (origin, params, total) => {
647 } 647 }
648 }; 648 };
649 649
650 - dest.brand = formatterFilterBrands(origin.brand, origin.paramBrand, params); 650 + if (origin.brand) {
  651 + dest.brand = formatterFilterBrands(origin.brand, origin.paramBrand, params);
  652 + }
651 653
652 // 处理价格筛选数据 654 // 处理价格筛选数据
653 let priceRangechecked = false; 655 let priceRangechecked = false;
@@ -751,6 +753,8 @@ exports.handleFilterData = (origin, params, total) => { @@ -751,6 +753,8 @@ exports.handleFilterData = (origin, params, total) => {
751 // 处理颜色筛选数据 753 // 处理颜色筛选数据
752 if (!_.isEmpty(origin.color)) { 754 if (!_.isEmpty(origin.color)) {
753 _.forEach(origin.color, (value) => { 755 _.forEach(origin.color, (value) => {
  756 + value.color_code = value.color_code.replace(/#/ig, '');
  757 +
754 let color = { 758 let color = {
755 checked: parseInt(params.color, 10) === parseInt(value.color_id, 10), 759 checked: parseInt(params.color, 10) === parseInt(value.color_id, 10),
756 href: handleFilterUrl(params, {color: value.color_id}), 760 href: handleFilterUrl(params, {color: value.color_id}),
@@ -817,7 +821,7 @@ exports.handleFilterData = (origin, params, total) => { @@ -817,7 +821,7 @@ exports.handleFilterData = (origin, params, total) => {
817 handleCheckedData(params, dest.gender, 'gender')); 821 handleCheckedData(params, dest.gender, 'gender'));
818 822
819 // 处理品牌筛选数据 823 // 处理品牌筛选数据
820 - if (dest.brand.brandsShow) { 824 + if (dest.brand && dest.brand.brandsShow) {
821 825
822 dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions, 826 dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,
823 handleBrandCheckedData(params, dest.brand.selectedBrands)); 827 handleBrandCheckedData(params, dest.brand.selectedBrands));
@@ -1364,10 +1368,9 @@ exports.handleFilterUrl = handleFilterUrl; @@ -1364,10 +1368,9 @@ exports.handleFilterUrl = handleFilterUrl;
1364 exports.handleCheckedData = handleCheckedData; 1368 exports.handleCheckedData = handleCheckedData;
1365 1369
1366 exports.handleNextPage = (params, total) => { 1370 exports.handleNextPage = (params, total) => {
1367 -  
1368 let href; 1371 let href;
1369 - let currentPage = parseInt((_.isEmpty(params.page) ? 1 : params.page), 10); // 当前页  
1370 - let perPageCount = parseInt((_.isEmpty(params.limit) ? 60 : params.limit) - 1, 10); // 每页商品数 1372 + let currentPage = parseInt((params.page ? params.page : 1), 10); // 当前页
  1373 + let perPageCount = parseInt((params.limit ? params.limit : 60) - 1, 10); // 每页商品数
1371 let totalPage = _.ceil(total / perPageCount); // 总页数 1374 let totalPage = _.ceil(total / perPageCount); // 总页数
1372 1375
1373 if (currentPage >= totalPage) { 1376 if (currentPage >= totalPage) {
1 -<div class="product-page yoho-page product-list-page"> 1 +<div class="product-page yoho-page product-list-page {{pageClass}}">
2 {{#if hideInfo}} 2 {{#if hideInfo}}
3 <div id="page-hide-info"{{#each hideInfo}} data-{{@key}}="{{.}}"{{/each}}></div> 3 <div id="page-hide-info"{{#each hideInfo}} data-{{@key}}="{{.}}"{{/each}}></div>
4 {{/if}} 4 {{/if}}
@@ -6,7 +6,11 @@ @@ -6,7 +6,11 @@
6 {{#each pathNav}} 6 {{#each pathNav}}
7 {{#if name}} 7 {{#if name}}
8 {{#if href}} 8 {{#if href}}
9 - <a {{#if @last}}class="last"{{/if}} href="{{href}}" title="{{pathTitle}}">{{{name}}}</a> 9 + {{#if @last}}
  10 + <span class="last" title="{{pathTitle}}">{{{name}}}</span>
  11 + {{^}}
  12 + <a href="{{href}}" title="{{pathTitle}}">{{{name}}}</a>
  13 + {{/if}}
10 {{^}} 14 {{^}}
11 <span {{#if @last}}class="last"{{/if}} title="{{pathTitle}}">{{{name}}}</span> 15 <span {{#if @last}}class="last"{{/if}} title="{{pathTitle}}">{{{name}}}</span>
12 {{/if}} 16 {{/if}}

2.22 KB | W: | H:

3.76 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
1 @import "detail"; 1 @import "detail";
  2 +
  3 +.global-list-page {
  4 + .path-nav:after {
  5 + content: "";
  6 + width: 54px;
  7 + height: 20px;
  8 + margin-left: 6px;
  9 + display: inline-block;
  10 + background-image: url("/product/global-path-icon.png");
  11 + vertical-align: bottom;
  12 + }
  13 +}
@@ -33,10 +33,11 @@ const joinUrl = (params) => { @@ -33,10 +33,11 @@ const joinUrl = (params) => {
33 */ 33 */
34 exports.setPager = (total, params)=>{ 34 exports.setPager = (total, params)=>{
35 let resData = {}; 35 let resData = {};
  36 + let defParams = _.cloneDeep(params);
36 let cutStatus, // 切割状态 1:去头 2:去尾 3:双切 37 let cutStatus, // 切割状态 1:去头 2:去尾 3:双切
37 i; 38 i;
38 let pages = []; 39 let pages = [];
39 - let currentPage = parseInt(params.page || 1, 10); // 当前页 40 + let currentPage = parseInt(defParams.page || 1, 10); // 当前页
40 41
41 // 小于两页直接退出 42 // 小于两页直接退出
42 if (total < 2) { 43 if (total < 2) {
@@ -55,7 +56,7 @@ exports.setPager = (total, params)=>{ @@ -55,7 +56,7 @@ exports.setPager = (total, params)=>{
55 } 56 }
56 57
57 pages.push({ 58 pages.push({
58 - url: joinUrl(Object.assign(params, {page: i})), 59 + url: joinUrl(Object.assign(defParams, {page: i})),
59 num: i, 60 num: i,
60 cur: currentPage === i 61 cur: currentPage === i
61 }); 62 });
@@ -74,7 +75,7 @@ exports.setPager = (total, params)=>{ @@ -74,7 +75,7 @@ exports.setPager = (total, params)=>{
74 } 75 }
75 76
76 list.push({ 77 list.push({
77 - url: joinUrl(Object.assign(params, {page: p})), 78 + url: joinUrl(Object.assign(defParams, {page: p})),
78 num: p 79 num: p
79 }); 80 });
80 } 81 }
@@ -88,7 +89,7 @@ exports.setPager = (total, params)=>{ @@ -88,7 +89,7 @@ exports.setPager = (total, params)=>{
88 } 89 }
89 90
90 list.push({ 91 list.push({
91 - url: joinUrl(Object.assign(params, {page: p})), 92 + url: joinUrl(Object.assign(defParams, {page: p})),
92 num: p 93 num: p
93 }); 94 });
94 } 95 }
@@ -102,12 +103,12 @@ exports.setPager = (total, params)=>{ @@ -102,12 +103,12 @@ exports.setPager = (total, params)=>{
102 if (fnum > 1) { 103 if (fnum > 1) {
103 if (fnum > 2) { 104 if (fnum > 2) {
104 pages = _.concat({ 105 pages = _.concat({
105 - url: joinUrl(Object.assign(params, {page: 1})), 106 + url: joinUrl(Object.assign(defParams, {page: 1})),
106 num: 1 107 num: 1
107 }, {num: '...'}, pages); 108 }, {num: '...'}, pages);
108 } else { 109 } else {
109 pages = _.concat({ 110 pages = _.concat({
110 - url: joinUrl(Object.assign(params, {page: 1})), 111 + url: joinUrl(Object.assign(defParams, {page: 1})),
111 num: 1 112 num: 1
112 }, pages); 113 }, pages);
113 } 114 }
@@ -116,12 +117,12 @@ exports.setPager = (total, params)=>{ @@ -116,12 +117,12 @@ exports.setPager = (total, params)=>{
116 if (lnum < total) { 117 if (lnum < total) {
117 if (lnum < total - 1) { 118 if (lnum < total - 1) {
118 pages = _.concat(pages, {num: '...'}, { 119 pages = _.concat(pages, {num: '...'}, {
119 - url: joinUrl(Object.assign(params, {page: total})), 120 + url: joinUrl(Object.assign(defParams, {page: total})),
120 num: total 121 num: total
121 }); 122 });
122 } else { 123 } else {
123 pages = _.concat(pages, { 124 pages = _.concat(pages, {
124 - url: joinUrl(Object.assign(params, {page: total})), 125 + url: joinUrl(Object.assign(defParams, {page: total})),
125 num: total 126 num: total
126 }); 127 });
127 } 128 }
@@ -131,12 +132,12 @@ exports.setPager = (total, params)=>{ @@ -131,12 +132,12 @@ exports.setPager = (total, params)=>{
131 132
132 // 上一页 133 // 上一页
133 if (currentPage > 1) { 134 if (currentPage > 1) {
134 - resData.prePage = {url: joinUrl(Object.assign(params, {page: currentPage - 1}))}; 135 + resData.prePage = {url: joinUrl(Object.assign(defParams, {page: currentPage - 1}))};
135 } 136 }
136 137
137 // 下一页 138 // 下一页
138 if (currentPage < total) { 139 if (currentPage < total) {
139 - resData.nextPage = {url: joinUrl(Object.assign(params, {page: currentPage + 1}))}; 140 + resData.nextPage = {url: joinUrl(Object.assign(defParams, {page: currentPage + 1}))};
140 } 141 }
141 142
142 return resData; 143 return resData;
1 'use strict'; 1 'use strict';
2 const _ = require('lodash'); 2 const _ = require('lodash');
3 3
4 -const config = global.yoho.config;  
5 const camelCase = global.yoho.camelCase; 4 const camelCase = global.yoho.camelCase;
6 const helpers = global.yoho.helpers; 5 const helpers = global.yoho.helpers;
7 6
@@ -208,9 +207,13 @@ exports.processProductList = (list, options) => { @@ -208,9 +207,13 @@ exports.processProductList = (list, options) => {
208 product.is_few = product.is_soon_sold_out === 'Y'; 207 product.is_few = product.is_soon_sold_out === 'Y';
209 208
210 if (product.is_global === 'Y') { 209 if (product.is_global === 'Y') {
211 - product.url = `${config.siteUrl}/product/global/${product.product_skn}.html`; 210 + product.url = helpers.urlFormat(`/product/global/${product.product_skn}.html`, null);
212 } else { 211 } else {
213 - product.url = helpers.getUrlBySkc(product.product_id);// eslint-disable-line 212 + if (product.product_id) {
  213 + product.url = helpers.getUrlBySkc(product.product_id);
  214 + } else if (product.product_skn) {
  215 + product.url = helpers.urlFormat('/common/erp2goods', {skn: product.product_skn});
  216 + }
214 } 217 }
215 218
216 // 4.6需求 商品列表显示店铺名 219 // 4.6需求 商品列表显示店铺名