...
|
...
|
@@ -33,12 +33,16 @@ const _getShelveTime = duration => { |
|
|
const _getText = data => {
|
|
|
let text = data.split(' ')[0];
|
|
|
const regResult = /\w+/.exec(text);
|
|
|
const titleWithoutChinese = /^(?=.*[A-Za-z0-9])[A-Za-z0-9 _]*$/;
|
|
|
|
|
|
if (data === 'GIRL KIDS' || data === 'BOY KIDS') {
|
|
|
// 对于不含中文的标题,直接返回
|
|
|
if (titleWithoutChinese.test(data)) {
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
if (regResult) {
|
|
|
|
|
|
// 去掉标题中的英文部分
|
|
|
text = text.replace(regResult[0], '');
|
|
|
}
|
|
|
|
...
|
...
|
@@ -317,13 +321,17 @@ const _getBoysSingleHot = (args, type) => { |
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getGirlsSingleHot = args => {
|
|
|
let goods = args[2].data;
|
|
|
let goods = args[2] && args[2].data;
|
|
|
let skns = '';
|
|
|
|
|
|
if (goods) {
|
|
|
_.forEach(goods, good => {
|
|
|
skns += good.id + ' ';
|
|
|
});
|
|
|
} else {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
_.forEach(goods, good => {
|
|
|
skns += good.id + ' ';
|
|
|
});
|
|
|
|
|
|
return searchApi.get('/search.json', {
|
|
|
client_type: 'web',
|
...
|
...
|
@@ -356,12 +364,13 @@ const _getSingleHotFloorData = (args, type) => { |
|
|
/**
|
|
|
* 处理异步获取的人气单品数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} originQuery 原始skns
|
|
|
* @param {Object} queryResult 异步获取的数据
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getSingehotViaResult = (args, queryResult, type) => {
|
|
|
const data = {
|
|
|
const _getSingehotViaResult = (args, originQuery, queryResult, type) => {
|
|
|
let data = {
|
|
|
singlehot: {
|
|
|
name: args[0].data.text,
|
|
|
navs: [],
|
...
|
...
|
@@ -370,28 +379,59 @@ const _getSingehotViaResult = (args, queryResult, type) => { |
|
|
}
|
|
|
};
|
|
|
|
|
|
let pos = 0;
|
|
|
|
|
|
|
|
|
const getIndex = skn => {
|
|
|
const originQueryArr = originQuery.split(' ');
|
|
|
let index;
|
|
|
|
|
|
|
|
|
_.forEach(originQueryArr, (query, idx) => {
|
|
|
if (query.toString() === skn.toString()) {
|
|
|
index = idx;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return index;
|
|
|
};
|
|
|
|
|
|
if (args[3].template_name === 'app_icon_list') {
|
|
|
data.singlehot.brands = args[3].data;
|
|
|
}
|
|
|
|
|
|
if (queryResult.data) {
|
|
|
_.forEach(queryResult.data.product_list || [], (it, index) => {
|
|
|
_.forEach(queryResult.data.product_list || [], it => {
|
|
|
const formatData = processProduct(it, {
|
|
|
width: 280,
|
|
|
height: 373
|
|
|
});
|
|
|
|
|
|
if (index > 12) {
|
|
|
if (pos > 12) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (index < 3) {
|
|
|
formatData.tip = 'TOP' + (index + 1);
|
|
|
}
|
|
|
|
|
|
data.singlehot.imgHot.push(formatData);
|
|
|
if (it.product_id) {
|
|
|
formatData.idx = getIndex(it.product_skn);
|
|
|
|
|
|
data.singlehot.imgHot.push(formatData);
|
|
|
pos +=1 ;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
data.singlehot.imgHot = _.sortBy(data.singlehot.imgHot, item => {
|
|
|
return item.idx;
|
|
|
});
|
|
|
|
|
|
pos = 1;
|
|
|
_.forEach(data.singlehot.imgHot, item => {
|
|
|
if (pos < 4 && item) {
|
|
|
item.tip = 'TOP' + pos;
|
|
|
pos += 1;
|
|
|
}
|
|
|
});
|
|
|
data.singlehot.navs = args[1].data;
|
|
|
_setChannelType(data.singlehot, type);
|
|
|
return data;
|
...
|
...
|
@@ -401,19 +441,20 @@ const _getSingehotViaResult = (args, queryResult, type) => { |
|
|
* 异步获取人气单品
|
|
|
* @param {[Object]} rawData 接口返回的原始数据
|
|
|
* @param {[Object]} floorData 已经经过处理的楼层数据
|
|
|
* @param {String} originQuery 原始的query数据
|
|
|
* @param {Object} queryResult 接口中用于请求人气单品的数据
|
|
|
* @param {String} title 人气单品楼层的标题
|
|
|
* @param {Type} type 人气单品楼层的类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _processFloorDataWithQueryReusult = (rawData, queryResult, title, type) => {
|
|
|
const _processFloorDataWithQueryReusult = (rawData, originQuery, queryResult, title, type) => {
|
|
|
let data = {};
|
|
|
|
|
|
_.forEach(rawData, (subData, index) => {
|
|
|
const text = subData.data.text && _getText(subData.data.text);
|
|
|
|
|
|
if (text === title) {
|
|
|
data = _getSingehotViaResult(rawData.slice(index, index + 4), queryResult, type);
|
|
|
data = _getSingehotViaResult(rawData.slice(index, index + 4), originQuery, queryResult, type);
|
|
|
}
|
|
|
});
|
|
|
|
...
|
...
|
@@ -519,12 +560,33 @@ const floorMap = { |
|
|
};
|
|
|
|
|
|
|
|
|
const needQuery = {
|
|
|
'GIRL KIDS': true,
|
|
|
'BOY KIDS': true,
|
|
|
人气单品: true,
|
|
|
ACCESSORIES: true
|
|
|
}
|
|
|
|
|
|
const getQuery = args => {
|
|
|
let goods = args[2] && args[2].data;
|
|
|
let skns = '';
|
|
|
|
|
|
if (goods) {
|
|
|
_.forEach(goods, good => {
|
|
|
skns += good.id + ' ';
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return skns;
|
|
|
}
|
|
|
|
|
|
|
|
|
const _processFloorData = (rawData, type) => {
|
|
|
let floorList = [];
|
|
|
let searchPromise = [];
|
|
|
let singlehotFloorIndex = [];
|
|
|
let singlehotFloorTitle = [];
|
|
|
let queryParam = '';
|
|
|
|
|
|
// 定义各种楼层需要用到的接口返回的数组中元素的个数
|
|
|
const bigFloorLength = 5;
|
...
|
...
|
@@ -549,6 +611,10 @@ const _processFloorData = (rawData, type) => { |
|
|
floorData = floorMap[text] &&
|
|
|
floorMap[text].call(null, rawData.slice(index, lastIndex), type);
|
|
|
|
|
|
if (needQuery[text]) {
|
|
|
queryParam = getQuery(rawData.slice(index, lastIndex));
|
|
|
}
|
|
|
|
|
|
} else if (data.template_name === 'debrisSlider') { // 处理girls的banner
|
|
|
floorData = floorMap.debrisSlide.call(null, data.data);
|
|
|
}
|
...
|
...
|
@@ -587,6 +653,7 @@ const _processFloorData = (rawData, type) => { |
|
|
return {
|
|
|
floors: floorList,
|
|
|
promise: _.reverse(searchPromise),
|
|
|
queryParam: queryParam,
|
|
|
singlehotFloorTitle: _.reverse(singlehotFloorTitle),
|
|
|
singlehotFloorIndex: _.reverse(singlehotFloorIndex)
|
|
|
};
|
...
|
...
|
@@ -794,6 +861,7 @@ const getContent = type => { |
|
|
searchPromise: processResult.promise,
|
|
|
singlehotFloorIndex: processResult.singlehotFloorIndex,
|
|
|
singlehotFloorTitle: processResult.singlehotFloorTitle,
|
|
|
queryParam: processResult.queryParam,
|
|
|
channelType: type
|
|
|
};
|
|
|
|
...
|
...
|
@@ -807,6 +875,7 @@ const getContent = type => { |
|
|
.splice(result.singlehotFloorIndex[index], 0,
|
|
|
_processFloorDataWithQueryReusult(
|
|
|
result.rawData,
|
|
|
result.queryParam,
|
|
|
data,
|
|
|
result.singlehotFloorTitle[index],
|
|
|
result.channelType
|
...
|
...
|
|