Authored by biao

update for aysnc singlehot floor

... ... @@ -29,10 +29,6 @@ const getShelveTime = duration => {
// `
};
// 创意生活
// const CODE_LIFESTYLE_CHANNEL_1 = '380c38155fd8beee10913a3f5b462da6';
// const CODE_LIFESTYLE_CHANNEL_2 = '665f7c2fb9d037ee820766953ee34bf7';
const channelMap = {
boys: {
... ... @@ -49,6 +45,8 @@ const channelMap = {
},
lifestyle: {
code: '8a341ca7eacc069ba80f02dec80eaf34',
// code: '380c38155fd8beee10913a3f5b462da6',
// code: '665f7c2fb9d037ee820766953ee34bf7',
gender: '2,3'
}
};
... ... @@ -554,52 +552,99 @@ const getBoysSingleHot = (args, type) => {
};
const getGirlsSingleHot = (args, type) => {
const data = {
singlehot: {
name: args[0].data.text,
navs: [],
imgHot: [],
brands: []
}
};
let goods = args[2].data;
let skns = '';
let floorDatas = [];
_.forEach(goods, good => {
skns += good.id + ' ';
});
// searchApi.get('/search.json', {
// client_type: 'web',
// query: skns,
// order: 'shelve_time:desc',
// status: 1,
// sales: 'Y',
// attribute_not: '2',
// stocknumber: 1,
// page: 1,
// viewNum: 60
// }).then(res => {
// });
data.singlehot.navs = getNavs(args[1].data);
setChannelType(data.singlehot, type);
floorDatas.push(data);
return floorDatas;
return searchApi.get('/search.json', {
client_type: 'web',
query: skns,
order: 'shelve_time:desc',
status: 1,
sales: 'Y',
attribute_not: '2',
stocknumber: 1,
page: 1,
viewNum: 60
})
};
// 人气单品
const getSingleHotFloorData = (args, type) => {
if (type === 'boys') {
return getBoysSingleHot(args, type);
}
if (type === 'girls') {
} else {
return getGirlsSingleHot(args, type);
}
};
const getAsyncSingleHot = (args, queryResult, type) => {
const data = {
singlehot: {
name: args[0].data.text,
navs: [],
imgHot: [],
brands: []
}
};
if (args[3].template_name === 'app_icon_list') {
_.forEach(args[3].data, it => {
let obj = {};
obj.href = it.url;
obj.name = it.title;
obj.img = it.src;
data.singlehot.brands.push(obj);
});
}
_.forEach(queryResult.data.product_list, (it, index) => {
let obj = {};
const formatData = formatProduct(it, true, true, true, 280, 373);
if (index > 12) {
return;
}
obj.price = formatData.salePrice;
obj.href = formatData.url;
obj.img = formatData.thumb;
obj.name = formatData.name;
if (index < 3) {
obj.tip = 'TOP' + (index + 1);
}
data.singlehot.imgHot.push(obj);
});
data.singlehot.navs = getNavs(args[1].data);
setChannelType(data.singlehot, type);
return data;
};
const processFloorDataWithQueryReusult = (rawData, floorData, queryResult, title, type) => {
let data = {};
_.forEach(rawData, (subData, index) => {
const text = subData.data.text && getText(subData.data.text);
if (text === title) {
data = getAsyncSingleHot(rawData.slice(index, index + 4), queryResult, type);
}
});
return data;
}
/**
* 组装最新上架楼层数据
*
... ... @@ -740,6 +785,8 @@ const floorMap = {
hot: getHotGoodsFloorData,
最新速报: getNewReportFloorData,
人气单品: getSingleHotFloorData,
'GIRL KIDS': getSingleHotFloorData,
'BOY KIDS': getSingleHotFloorData,
优选品牌: getPreBrandTopData,
最新上架: getNewGoodsFloorData,
ad: getadbannerData,
... ... @@ -748,8 +795,26 @@ const floorMap = {
debrisSlide: getDebrisSlide
};
const getText = data => {
let text = data.split(' ')[0];
const regResult = /\w+/.exec(text);
if (data === 'GIRL KIDS' || data === 'BOY KIDS') {
return data;
}
if (regResult) {
text = text.replace(regResult[0], '');
}
return text;
}
const processFloorData = (rawData, type) => {
let floorList = [];
let searchPromise = [];
let singlehotFloorIndex = [];
let singlehotFloorTitile = [];
_.forEach(rawData, (data, index) => {
let floorData = null;
... ... @@ -760,12 +825,8 @@ const processFloorData = (rawData, type) => {
} else if (data.template_intro === '热门品类') { // 处理热门品类
floorData = floorMap.hot.call(null, rawData.slice(index, index + 2), type);
} else if (data.data.text) { // 处理一般楼层
let text = data.data.text.split(' ')[0];
const regResult = /\w+/.exec(text);
let text = getText(data.data.text);
if (regResult) {
text = text.replace(regResult[0], '');
}
floorData = floorMap[text] &&
floorMap[text].call(null, rawData.slice(index, index + 6), type);
... ... @@ -785,14 +846,28 @@ const processFloorData = (rawData, type) => {
floorData = floorMap.accordion.call(null, rawData.slice(index, index + 4));
}
if (!_.isNil(floorData)) {
if (floorData && floorData.then && typeof floorData.then === 'function') {
searchPromise.push(floorData);
// 记住楼层位置, 以便后面promise获取数据后插入楼层数据
singlehotFloorIndex.push(floorList.length);
// 记住楼层标题, 以便后面promise获取数据后插入楼层数据
singlehotFloorTitile.push(getText(data.data.text));
} else if (!_.isNil(floorData)) {
_.isArray(floorData) ?
floorList = floorList.concat(floorData) :
floorList.push(floorData);
}
});
return floorList;
return {
floors: floorList,
promise: _.reverse(searchPromise),
singlehotFloorTitile: _.reverse(singlehotFloorTitile),
singlehotFloorIndex: _.reverse(singlehotFloorIndex)
}
};
... ... @@ -810,14 +885,41 @@ exports.getContent = type => {
let data = {};
const processResult = processFloorData(contentData, type);
data = headerModel.setHeaderData(headerData, type);
data.module = 'channel';
data.page = 'channel';
data.pageType = type;
data.footerTop = true;
data.channel = processFloorData(contentData, type);
data.channel = processResult.floors;
return data;
return {
rawData: contentData,
floorData: data,
searchPromise: processResult.promise,
singlehotFloorIndex: processResult.singlehotFloorIndex,
singlehotFloorTitile: processResult.singlehotFloorTitile,
channelType: type
};
}
}).then(result => {
// 如果有promise则做相应处理
if (result.searchPromise.length) {
return Promise.all(result.searchPromise).then(res => {
_.forEach(res, (data, index) => {
result.floorData.channel
.splice(result.singlehotFloorIndex[index], 0,
processFloorDataWithQueryReusult(result.rawData, result.floorData, data, result.singlehotFloorTitile[index], result.channelType));
});
return result.floorData;
})
} else {
return result.floorData;
}
});
};
... ...
... ... @@ -77,12 +77,6 @@
</div>
{{/ debrisSlider}}
{{! 手风琴}}
{{# accordion}}
{{! {{> index/slide-accordion}} }}
{{/ accordion}}
{{! 优选品牌}}
{{# preferenceBrands}}
... ... @@ -109,6 +103,12 @@
{{#if girlsChannel}}
{{> girl-singlehot}}
{{/if}}
{{#if kidsChannel}}
{{> girl-singlehot}}
{{/if}}
{{#if lifestyleChannel}}
{{> girl-singlehot}}
{{/if}}
{{/ singlehot}}
{{! 广告}}
... ...
... ... @@ -8,7 +8,7 @@
{{# tip}}
<i class="top">{{.}}</i>
{{/ tip}}
<img class="lazy" data-original="{{img}}"/></div>
<img class="lazy" data-original="{{image img 280 373}}"/></div>
<p class="commodity-name">{{name}}</p>
<p class="commodity-price"><span>¥{{price}}</span></p>
</a>
... ... @@ -18,7 +18,7 @@
</div>
<div class="commodity-brands imgopacity clearfix">
{{#each brands}}
<a href="{{href}}" title="{{name}}" target= "_blank"><img class="lazy" data-original="{{img}}"/></a>
<a href="{{href}}" title="{{name}}" target= "_blank"><img class="lazy" data-original="{{image img 185 86}}"/></a>
{{/each}}
</div>
</div>
... ...