Authored by 阿达

Merge branch 'release/4.6' of http://git.yoho.cn/fe/yohobuy-node into release/4.6

... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2016-06-02 15:50:47
* @Last Modified by: Targaryen
* @Last Modified time: 2016-06-17 20:31:46
* @Last Modified time: 2016-06-20 21:32:00
*/
'use strict';
... ... @@ -32,12 +32,11 @@ const handleFilterUrl = (originParam, newParam) => {
/**
* 处理最新降价折扣信息
* @return {[type]} [description]
* @param params 当前 URL 的参数
* @returns {Array|*[]}
*/
const handleSaleNewSaleSortData = (params) => {
var dest;
dest = [{
return [{
name: '1~3折',
href: handleFilterUrl(params, {p_d: '0.1,0.3'}),
checked: params.p_d === '0.1,0.3'
... ... @@ -50,8 +49,6 @@ const handleSaleNewSaleSortData = (params) => {
href: handleFilterUrl(params, {p_d: '0.7,1'}),
checked: params.p_d === '0.7,1'
}];
return dest;
};
/**
... ... @@ -59,7 +56,7 @@ const handleSaleNewSaleSortData = (params) => {
* @return {[type]} [description]
*/
const handleSalebreakingYardsSortData = (origin, params) => {
var dest = [];
let dest = [];
if (!_.isEmpty(params.sort)) {
... ... @@ -111,7 +108,7 @@ const handleSalebreakingYardsSortData = (origin, params) => {
* @return {[type]} [description]
*/
const handleCheckedData = (params, origin, param) => {
var dest = [];
let dest = [];
// 品牌选中数据
if (!_.isEmpty(origin)) {
... ... @@ -441,7 +438,7 @@ exports.handleSaleOptsData = (params, total, extra) => {
* @returns {{}}
*/
exports.handleSaleSortData = (origin, params, extra) => {
var leftContent = {};
let leftContent = {};
leftContent.allSort = {};
leftContent.allSort.list = [];
... ... @@ -497,12 +494,12 @@ exports.handleSaleSortData = (origin, params, extra) => {
};
/**
* 处理筛选数据
* @param {[type]} origin [description]
* @return {[type]} [description]
* 处理一般筛选数据
* @param origin 要处理的筛选数据 filter
* @param params 当前 URL 中已有的参数,处理选中状态使用
* @returns {{}}
*/
exports.handleSaleFilterData = (origin, params) => {
let dest = {
brand: {
default: [],
... ... @@ -527,10 +524,9 @@ exports.handleSaleFilterData = (origin, params) => {
}
};
let brandIndex = dest.brand.brandIndex;
// 品牌索引数据处理
for (let i = 65; i < 91; i++) {
brandIndex.push({
dest.brand.brandIndex.push({
index: String.fromCharCode(i).toLowerCase(),
name: String.fromCharCode(i)
});
... ... @@ -593,28 +589,19 @@ exports.handleSaleFilterData = (origin, params) => {
});
}
// 处理频道数据
for (let i = 0; i < 2; i++) {
dest.gender[i] = {};
dest.gender[i].checked = false;
}
Object.assign(dest.gender[0], {
name: 'BOYS',
href: handleFilterUrl(params, {
gender: '1,3'
}),
checked: params.gender === '1,3'
});
Object.assign(dest.gender[1], {
name: 'GIRLS',
href: handleFilterUrl(params, {
gender: '2,3'
}),
checked: params.gender === '2,3'
});
// 处理性别数据
dest.gender = [
{
name: 'BOYS',
href: handleFilterUrl(params, {gender: '1,3'}),
checked: params.gender === '1,3'
},
{
name: 'GIRLS',
href: handleFilterUrl(params, {gender: '2,3'}),
checked: params.gender === '2,3'
}
];
// 最新降价数据处理
if (parseInt(params.saleType, 10) === 3) {
... ... @@ -625,27 +612,36 @@ exports.handleSaleFilterData = (origin, params) => {
handleCheckedData(params, dest.discount, 'p_d'));
}
// 奥莱尺码处理
// 尺码处理
if (!_.isEmpty(origin.size)) {
dest.size = [];
dest.size.push({
checked: parseInt(params.size, 10) === parseInt(origin.size.size_id, 10),
href: handleFilterUrl(params, {
size: origin.size.size_id
}),
name: origin.size.size_name
});
dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,
handleCheckedData(params, dest.size, 'size'));
}
// 断码区尺码数据处理
if (!_.isEmpty(origin.size) && params.saleType === '1') {
dest.size = handleSalebreakingYardsSortData(origin.size, params);
if (params.saleType === '1') {
// 断码区尺码处理
dest.size = handleSalebreakingYardsSortData(origin.size, params);
} else {
dest.size = [];
if (_.isArray(origin.size)) {
_.forEach(origin.size, value => {
dest.size.push({
checked: parseInt(params.size, 10) === parseInt(value.size_id, 10),
href: handleFilterUrl(params, {
size: value.size_id
}),
name: value.size_name
});
});
} else {
dest.size.push({
checked: parseInt(params.size, 10) === parseInt(origin.size.size_id, 10),
href: handleFilterUrl(params, {
size: origin.size.size_id
}),
name: origin.size.size_name
});
}
}
// 处理断码区尺码筛选数据
dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,
handleCheckedData(params, dest.size, 'size'));
}
... ... @@ -663,8 +659,6 @@ exports.handleSaleFilterData = (origin, params) => {
handleCheckedData(params, dest.gender, 'gender'));
// 处理品牌筛选数据
// dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,
// handleCheckedData(params, dest.brand.brandsShow, 'brand'));
dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,
handleBrandCheckedData(params, dest.brand.brandsShow));
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2016-05-25 18:16:59
* @Last Modified by: Targaryen
* @Last Modified time: 2016-06-17 20:31:42
* @Last Modified time: 2016-06-20 21:31:11
*/
'use strict';
... ... @@ -69,350 +69,13 @@ const discountSplit = (text) => {
};
/**
* 处理用于筛选的 URL , 拼接 URL 参数
* @param originParam 当前 URL 中的参数
* @param newParam 要拼接的 参数
* @returns {string}
*/
const handleFilterUrl = (originParam, newParam) => {
let dest = '?';
let tempOriginParam = {};
tempOriginParam = Object.assign(tempOriginParam, originParam, newParam);
_.forEach(tempOriginParam, function(value, key) {
dest = dest + key + '=' + value + '&';
});
return _.trim(dest, '&');
};
/**
* 处理最新降价折扣信息
* @param params 当前 URL 的参数
* @returns {Array|*[]}
*/
const handleSaleNewSaleSortData = (params) => {
return [{
name: '1~3折',
href: handleFilterUrl(params, {p_d: '0.1,0.3'}),
checked: params.p_d === '0.1,0.3'
}, {
name: '4~6折',
href: handleFilterUrl(params, {p_d: '0.4,0.6'}),
checked: params.p_d === '0.4,0.6'
}, {
name: '7折以上',
href: handleFilterUrl(params, {p_d: '0.7,1'}),
checked: params.p_d === '0.7,1'
}];
};
/**
* 处理选中数据
* @param params 当前 URL 中已有的参数
* @param origin 要处理的数据
* @param param 此组数据的键名
* @returns {Array}
*/
const handleCheckedData = (params, origin, param) => {
var dest = [];
if (!_.isEmpty(origin)) {
_.forEach(origin, (value) => {
if (value.checked) {
let checked = {
name: value.name
};
let tempParam = {};
tempParam[param] = '';
checked.href = handleFilterUrl(params, tempParam);
dest.push(checked);
}
});
}
return dest;
};
/**
* 处理品牌筛选数据
* @param params
* @param origin
* @returns {{}}
*/
const handleBrandCheckedData = (params, origin) => {
let dest = [];
// 分拆品牌参数
let brands = _.split(params.brand, ',');
let intBrands = [];
_.forEach(brands, value => {
intBrands.push(parseInt(value, 10));
});
let checkedCount = 0;
// 遍历品牌数据,如果在参数中,那么加 checked,将此数据加入到 checked 数组中
if (!_.isEmpty(origin)) {
_.forEach(origin, (value) => {
if (typeof _.find(intBrands, o => {
return _.isEqual(o, value.id);
}) !== 'undefined') {
let checked = {
name: value.name
}; // push 到已选择数组
// 为了不污染原始数据
let tempIntBrands = _.cloneDeep(intBrands);
// 去掉当前选项
_.remove(tempIntBrands, n => {
return n === value.id;
});
// 拼接参数
let brand = '';
// 建议保留,需要品牌可以单个删除时放开注释即可
// _.forEach(tempIntBrands, subValue => {
// brand += subValue + ',';
// });
// 清除参数,保留没有去掉的参数
let tempParam = {
brand: brand
};
checked.href = handleFilterUrl(params, tempParam);
if (checkedCount === 0) {
dest[0] = checked;
} else if (checkedCount === 1) {
dest[0].name += '、' + checked.name.substring(0, 3) + '...';
}
checkedCount++;
// 建议保留,需要品牌可以单个删除时放开注释即可
// dest.push(checked);
}
});
}
return dest;
};
/**
* 处理断码区尺码筛选数据
* @param origin 尺码原始数据
* @param params 当前 URL 中已有的参数
* @returns {Array}
*/
const handleSalebreakingYardsSortData = (origin, params) => {
var dest = [];
if (!_.isEmpty(params.sort)) {
// 是否有分类筛选参数,如果有
_.forEach(params.sort.split(','), function(sortParam) {
_.forEach(origin, function(value) {
// 判断是否在这组数据里面
if (!_.isEmpty(_.find(value.sort_id.split(','), o => {
return o === sortParam;
}))) {
// 如果在某组数据里面,组合数据退出循环
_.forEach(value.sub, function(subValue) {
let size = {
checked: parseInt(params.size, 10) === parseInt(subValue.size_id, 10),
href: handleFilterUrl(params, {size: subValue.size_id}),
name: subValue.size_name
};
dest.push(size);
});
return false;
}
});
});
} else { // 如果没有筛选参数,返回所有分类
_.forEach(origin, function(value) {
_.forEach(value.sub, function(subValue) {
let size = {
checked: parseInt(params.size, 10) === parseInt(subValue.size_id, 10),
href: handleFilterUrl(params, {size: subValue.size_id}),
name: subValue.size_name
};
dest.push(size);
});
});
}
return _.uniqWith(dest, _.isEqual);
};
/**
* 处理一般筛选数据
* @param origin 要处理的筛选数据 filter
* @param params 当前 URL 中已有的参数,处理选中状态使用
* @returns {{}}
*/
exports.handleSaleFilterData = (origin, params) => {
var dest = {
brand: {
default: [],
brandsShow: [],
brandIndex: [
{
index: 'all',
name: '全部'
},
{
index: '0-9',
name: '0~9'
}
],
showMore: true,
showMulti: true
},
price: [],
gender: [],
checkedConditions: {
conditions: []
}
};
// 品牌索引数据处理
for (let i = 65; i < 91; i++) {
dest.brand.brandIndex.push({
index: String.fromCharCode(i).toLowerCase(),
name: String.fromCharCode(i)
});
}
// 品牌数据处理
// 分拆品牌参数
let brands = _.split(params.brand, ',');
let intBrands = [];
_.forEach(brands, value => {
intBrands.push(parseInt(value, 10));
});
if (!_.isEmpty(origin.brand)) {
let count = 0;
_.forEach(origin.brand, function(value) {
let brand = {
checked: (typeof _.find(intBrands, o => {
return _.isEqual(o, value.id);
}) !== 'undefined'),
href: handleFilterUrl(params, {brand: value.id}),
name: value.brand_name,
key: value.brand_domain,
id: value.id
};
if (!_.isEmpty(value.brand_alif)) {
if (!_.isNaN(parseInt(value.brand_alif, 10))) {
brand.index = '0-9';
} else {
brand.index = value.brand_alif.toLowerCase();
}
}
if (count < 10) {
dest.brand.default.push(brand);
}
dest.brand.brandsShow.push(brand);
count++;
});
}
// 来排排序
dest.brand.brandsShow = _.sortBy(dest.brand.brandsShow, function(o) {
return o.index;
});
// 处理 价格 筛选数据
if (!_.isEmpty(origin.priceRange)) {
_.forEach(origin.priceRange, function(value, key) {
let price = {
checked: params.price === key,
href: handleFilterUrl(params, {price: key}),
name: value
};
dest.price.push(price);
});
}
// 处理性别数据
dest.gender = [
{
name: 'BOYS',
href: handleFilterUrl(params, {gender: '1,3'}),
checked: params.gender === '1,3'
},
{
name: 'GIRLS',
href: handleFilterUrl(params, {gender: '2,3'}),
checked: params.gender === '2,3'
}
];
// 最新降价数据处理
if (parseInt(params.saleType, 10) === 3) {
dest.discount = handleSaleNewSaleSortData(params);
// 最新降价筛选数据处理
dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,
handleCheckedData(params, dest.discount, 'p_d'));
}
// 断码区尺码数据处理
if (!_.isEmpty(origin.size) && params.saleType === '1') {
dest.size = handleSalebreakingYardsSortData(origin.size, params);
// 处理断码区尺码筛选数据
dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,
handleCheckedData(params, dest.size, 'size'));
}
// 清除所有选中数据
dest.checkedConditions.clearUrl = '?';
// 处理频道筛选数据
dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,
handleCheckedData(params, dest.gender, 'gender'));
// 处理品牌筛选数据
// dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,
// handleCheckedData(params, dest.brand.brandsShow, 'brand'));
dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,
handleBrandCheckedData(params, dest.brand.brandsShow));
// 处理价格筛选数据
dest.checkedConditions.conditions = _.union(dest.checkedConditions.conditions,
handleCheckedData(params, dest.price, 'price'));
return dest;
};
/**
* 处理折扣专区活动数据
* @param origin 原始数据
* @param channel 频道 boys girls kids lifestyle
* @returns {{}}
*/
exports.handleSaleActivityData = (origin, channel) => {
var dest = {
let dest = {
big: [],
normal: []
};
... ... @@ -443,7 +106,7 @@ exports.handleSaleActivityData = (origin, channel) => {
* @returns {{}}
*/
exports.handleDiscountTitleData = (origin) => {
var dest = {
let dest = {
title: origin.title,
up: true,
time: parseInt(origin.left_time, 10) * 1000
... ... @@ -460,7 +123,7 @@ exports.handleDiscountTitleData = (origin) => {
* @returns {{}}
*/
exports.handleSaleBannerData = (origin) => {
var dest = {
let dest = {
list: []
};
... ... @@ -487,7 +150,7 @@ exports.handleSaleBannerData = (origin) => {
* @returns {Array}
*/
exports.handleSaleBannerSmallData = (origin) => {
var dest = [];
let dest = [];
let count = 0;
_.forEach(origin, function(value) {
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2016-05-19 10:20:08
* @Last Modified by: Targaryen
* @Last Modified time: 2016-06-17 16:43:11
* @Last Modified time: 2016-06-20 21:13:00
*/
'use strict';
... ... @@ -244,7 +244,7 @@ exports.getSaleOthersData = (params, channel) => {
if (!_.isEmpty(result[1].data.filter)) {
// 顶部筛选条件
finalResult.filters = saleHandler.handleSaleFilterData(result[1].data.filter, params);
finalResult.filters = publicHandler.handleSaleFilterData(result[1].data.filter, params);
}
// 处理排序数据
... ... @@ -417,7 +417,7 @@ exports.getSalebreakingYardsData = (params, channel) => {
if (subResult[1].code === 200) {
if (!_.isEmpty(subResult[1].data.filter)) {
finalResult.filters = saleHandler.handleSaleFilterData(
finalResult.filters = publicHandler.handleSaleFilterData(
Object.assign(subResult[1].data.filter, {size: result[2].data}),
params);
}
... ...
... ... @@ -27,8 +27,5 @@
{{/ list}}
</div>
</div>
<div class="product-pager clearfix">
<span class="total">{{sort.start}} - {{sort.end}} / 共{{sort.totalCount}}件商品</span>
<div class="pager">{{{pager}}}</div>
</div>
{{> common/foot-pager}}
{{/ goodsBoard}}
\ No newline at end of file
... ...
{{# footPager}}
<div class="product-pager clearfix">
<span class="total">{{tip}}</span>
<div class="pager">
{{# prePage}}
<a href="{{url}}" title="上一页">上一页<span class="iconfont">&#xe60e;</span></a>
{{/ prePage}}
{{# pages}}
<a{{#if url}} href="{{url}}"{{/if}}{{#if cur}} class="cur"{{/if}}>{{num}}</a>
{{/ pages}}
{{# nextPage}}
<a href="{{url}}" title="下一页">下一页<span class="iconfont">&#xe60c;</span></a>
{{/ nextPage}}
</div>
</div>
{{/ footPager}}
\ No newline at end of file
... ...