Authored by 周少峰

add color & checks, color goods image

@@ -10,6 +10,13 @@ const _ = require('lodash'); @@ -10,6 +10,13 @@ const _ = require('lodash');
10 const helpers = global.yoho.helpers; 10 const helpers = global.yoho.helpers;
11 const queryString = require('querystring'); 11 const queryString = require('querystring');
12 12
  13 +// 打折、新品、限量
  14 +const checksName = {
  15 + new: '新品',
  16 + specialoffer: '打折',
  17 + limited: '限量'
  18 +};
  19 +
13 /** 20 /**
14 * 处理用于筛选的 URL , 拼接 URL 参数 21 * 处理用于筛选的 URL , 拼接 URL 参数
15 * @param originParam 当前 URL 中的参数 22 * @param originParam 当前 URL 中的参数
@@ -127,6 +134,29 @@ const handleBrandCheckedData = (params, origin) => { @@ -127,6 +134,29 @@ const handleBrandCheckedData = (params, origin) => {
127 }; 134 };
128 135
129 /** 136 /**
  137 + * 新品、折扣、限量
  138 + */
  139 +const hadleChecks = (name, params) => {
  140 + let tempParam = _.cloneDeep(params);
  141 +
  142 + tempParam[name] = 'Y';
  143 + let checksOpts = {
  144 + name: checksName[name],
  145 + checked: false,
  146 + href: handleFilterUrl(tempParam)
  147 + };
  148 +
  149 + if (params[name] && params[name] === 'Y') {
  150 + checksOpts.checked = false;
  151 + delete tempParam[name];
  152 + checksOpts.href = handleFilterUrl(tempParam);
  153 + }
  154 +
  155 + return checksOpts;
  156 +};
  157 +
  158 +
  159 +/**
130 * 处理 opts 排序数据 160 * 处理 opts 排序数据
131 * @param params 161 * @param params
132 * @param total 162 * @param total
@@ -135,7 +165,8 @@ const handleBrandCheckedData = (params, origin) => { @@ -135,7 +165,8 @@ const handleBrandCheckedData = (params, origin) => {
135 */ 165 */
136 exports.handleOptsData = (params, total, extra) => { 166 exports.handleOptsData = (params, total, extra) => {
137 let dest = { 167 let dest = {
138 - sortType: [] 168 + sortType: [],
  169 + checks: []
139 }; 170 };
140 171
141 // 用来标记是否是折扣专场,折扣专场只需要前三个排序参数 172 // 用来标记是否是折扣专场,折扣专场只需要前三个排序参数
@@ -276,6 +307,20 @@ exports.handleOptsData = (params, total, extra) => { @@ -276,6 +307,20 @@ exports.handleOptsData = (params, total, extra) => {
276 total : parseInt(dest.start, 10) + paramsLimit - 1; 307 total : parseInt(dest.start, 10) + paramsLimit - 1;
277 } 308 }
278 309
  310 + // 新品
  311 + if (extra.new === 'Y') {
  312 + dest.checks.push(hadleChecks('new', params));
  313 + }
  314 +
  315 + // 打折
  316 + if (extra.specialoffer === 'Y') {
  317 + dest.checks.push(hadleChecks('specialoffer', params));
  318 + }
  319 +
  320 + // 限量
  321 + if (extra.limited === 'Y') {
  322 + dest.checks.push(hadleChecks('limited', params));
  323 + }
279 return dest; 324 return dest;
280 }; 325 };
281 326
@@ -365,6 +410,7 @@ exports.handleFilterData = (origin, params) => { @@ -365,6 +410,7 @@ exports.handleFilterData = (origin, params) => {
365 }, 410 },
366 price: [], 411 price: [],
367 gender: [], 412 gender: [],
  413 + color: [],
368 checkedConditions: { 414 checkedConditions: {
369 conditions: [] 415 conditions: []
370 } 416 }
@@ -502,6 +548,20 @@ exports.handleFilterData = (origin, params) => { @@ -502,6 +548,20 @@ exports.handleFilterData = (origin, params) => {
502 handleCheckedData(params, dest.size, 'size')); 548 handleCheckedData(params, dest.size, 'size'));
503 } 549 }
504 550
  551 + // 处理颜色筛选数据
  552 + if (!_.isEmpty(origin.color)) {
  553 + _.forEach(origin.color, (value, key) => {
  554 + let color = {
  555 + checked: params.price === key,
  556 + href: handleFilterUrl(params, {color: value.color_id}),
  557 + name: value.color_name,
  558 + rgb: value.color_value ? 'url(' + value.color_value + ')' : '#' + value.color_code
  559 + };
  560 +
  561 + dest.color.push(color);
  562 + });
  563 + }
  564 +
505 // 清除所有选中数据 565 // 清除所有选中数据
506 let remainParams = {}; 566 let remainParams = {};
507 567
@@ -41,10 +41,11 @@ exports.getSearchData = (params) => { @@ -41,10 +41,11 @@ exports.getSearchData = (params) => {
41 if (result[2].code === 200) { 41 if (result[2].code === 200) {
42 Object.assign(finalResult.search, { 42 Object.assign(finalResult.search, {
43 filters: searchHandler.handleFilterData(result[2].data.filter, params), 43 filters: searchHandler.handleFilterData(result[2].data.filter, params),
44 - opts: searchHandler.handleOptsData(params, result[2].data.total), 44 + opts: searchHandler.handleOptsData(params, result[2].data.total, result[2].data.filter),
45 totalCount: result[2].data.total, 45 totalCount: result[2].data.total,
46 footPager: searchHandler.handlePagerData(result[2].data.total, params), 46 footPager: searchHandler.handlePagerData(result[2].data.total, params),
47 - goods: productProcess.processProductList(result[2].data.product_list, {showDiscount: false}) 47 + goods: productProcess.processProductList(result[2].data.product_list,
  48 + Object.assign({showDiscount: false}, params))
48 }); 49 });
49 } 50 }
50 return finalResult; 51 return finalResult;
@@ -104,22 +104,25 @@ exports.processProductList = (list, options) => { @@ -104,22 +104,25 @@ exports.processProductList = (list, options) => {
104 product.discount = (product.salesPrice / product.marketPrice * 10).toFixed(1); 104 product.discount = (product.salesPrice / product.marketPrice * 10).toFixed(1);
105 } 105 }
106 106
107 - // 判别默认的商品是否将默认的图片URL赋值到skn  
108 - let flag = false;  
109 -  
110 // 如果设置了默认图片,就取默认的图片 107 // 如果设置了默认图片,就取默认的图片
111 _.forEach(product.goodsList, (goods) => { 108 _.forEach(product.goodsList, (goods) => {
112 - if (flag) {  
113 - return;  
114 - }  
115 - if (goods.isDefault === 'Y') {  
116 - product.defaultImages = procProductImg(goods);  
117 - flag = true; 109 +
  110 + // (颜色优先)
  111 + if (options.color) {
  112 + if (goods.colorId === options.color) {
  113 + product.defaultImages = procProductImg(goods);
  114 + return;
  115 + }
  116 + } else {
  117 + if (goods.isDefault === 'Y') {
  118 + product.defaultImages = procProductImg(goods);
  119 + return;
  120 + }
118 } 121 }
119 }); 122 });
120 123
121 // 如果还未赋值,则取第一个skc产品的默认图片 124 // 如果还未赋值,则取第一个skc产品的默认图片
122 - if (!flag) { 125 + if (!product.defaultImages) {
123 product.defaultImages = procProductImg(product.goodsList[0]); 126 product.defaultImages = procProductImg(product.goodsList[0]);
124 } 127 }
125 128