...
|
...
|
@@ -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) {
|
...
|
...
|
|