Authored by 周少峰

add color & checks, color goods image

... ... @@ -10,6 +10,13 @@ const _ = require('lodash');
const helpers = global.yoho.helpers;
const queryString = require('querystring');
// 打折、新品、限量
const checksName = {
new: '新品',
specialoffer: '打折',
limited: '限量'
};
/**
* 处理用于筛选的 URL , 拼接 URL 参数
* @param originParam 当前 URL 中的参数
... ... @@ -127,6 +134,29 @@ const handleBrandCheckedData = (params, origin) => {
};
/**
* 新品、折扣、限量
*/
const hadleChecks = (name, params) => {
let tempParam = _.cloneDeep(params);
tempParam[name] = 'Y';
let checksOpts = {
name: checksName[name],
checked: false,
href: handleFilterUrl(tempParam)
};
if (params[name] && params[name] === 'Y') {
checksOpts.checked = false;
delete tempParam[name];
checksOpts.href = handleFilterUrl(tempParam);
}
return checksOpts;
};
/**
* 处理 opts 排序数据
* @param params
* @param total
... ... @@ -135,7 +165,8 @@ const handleBrandCheckedData = (params, origin) => {
*/
exports.handleOptsData = (params, total, extra) => {
let dest = {
sortType: []
sortType: [],
checks: []
};
// 用来标记是否是折扣专场,折扣专场只需要前三个排序参数
... ... @@ -276,6 +307,20 @@ exports.handleOptsData = (params, total, extra) => {
total : parseInt(dest.start, 10) + paramsLimit - 1;
}
// 新品
if (extra.new === 'Y') {
dest.checks.push(hadleChecks('new', params));
}
// 打折
if (extra.specialoffer === 'Y') {
dest.checks.push(hadleChecks('specialoffer', params));
}
// 限量
if (extra.limited === 'Y') {
dest.checks.push(hadleChecks('limited', params));
}
return dest;
};
... ... @@ -365,6 +410,7 @@ exports.handleFilterData = (origin, params) => {
},
price: [],
gender: [],
color: [],
checkedConditions: {
conditions: []
}
... ... @@ -502,6 +548,20 @@ exports.handleFilterData = (origin, params) => {
handleCheckedData(params, dest.size, 'size'));
}
// 处理颜色筛选数据
if (!_.isEmpty(origin.color)) {
_.forEach(origin.color, (value, key) => {
let color = {
checked: params.price === key,
href: handleFilterUrl(params, {color: value.color_id}),
name: value.color_name,
rgb: value.color_value ? 'url(' + value.color_value + ')' : '#' + value.color_code
};
dest.color.push(color);
});
}
// 清除所有选中数据
let remainParams = {};
... ...
... ... @@ -41,10 +41,11 @@ exports.getSearchData = (params) => {
if (result[2].code === 200) {
Object.assign(finalResult.search, {
filters: searchHandler.handleFilterData(result[2].data.filter, params),
opts: searchHandler.handleOptsData(params, result[2].data.total),
opts: searchHandler.handleOptsData(params, result[2].data.total, result[2].data.filter),
totalCount: result[2].data.total,
footPager: searchHandler.handlePagerData(result[2].data.total, params),
goods: productProcess.processProductList(result[2].data.product_list, {showDiscount: false})
goods: productProcess.processProductList(result[2].data.product_list,
Object.assign({showDiscount: false}, params))
});
}
return finalResult;
... ...
... ... @@ -104,22 +104,25 @@ exports.processProductList = (list, options) => {
product.discount = (product.salesPrice / product.marketPrice * 10).toFixed(1);
}
// 判别默认的商品是否将默认的图片URL赋值到skn
let flag = false;
// 如果设置了默认图片,就取默认的图片
_.forEach(product.goodsList, (goods) => {
if (flag) {
return;
}
if (goods.isDefault === 'Y') {
product.defaultImages = procProductImg(goods);
flag = true;
// (颜色优先)
if (options.color) {
if (goods.colorId === options.color) {
product.defaultImages = procProductImg(goods);
return;
}
} else {
if (goods.isDefault === 'Y') {
product.defaultImages = procProductImg(goods);
return;
}
}
});
// 如果还未赋值,则取第一个skc产品的默认图片
if (!flag) {
if (!product.defaultImages) {
product.defaultImages = procProductImg(product.goodsList[0]);
}
... ...