global.js
4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* 商品促销 model
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2017/4/6
*/
'use strict';
const _ = require('lodash');
const globalApi = require('./global-api');
const headerModel = require('../../../doraemon/models/header');
const searchHandler = require('./search-handler');
const pager = require(`${global.utils}/pager`).setPager;
const productProcess = require(`${global.utils}/product-process`);
const getGlobalProductListData = (params, yoho) => {
return Promise.props({
header: headerModel.requestHeaderData(yoho.channel),
list: globalApi.getGlobalProductListAsync(Object.assign({
physical_channel: yoho.channelNum
}, params, {limit: params.limit ? params.limit - 1 : 59}))
}).then(result => {
let resData = {};
Object.assign(resData, result.header);
if (result.list.code === 200) {
let totalNum = _.get(result.list, 'data.total', 0);
// let filters = Object.assign(searchHandler.handleFilterDataAll(result[2].data, params),
// finalResult.list.leftContent.sort);
// filters.checkedConditions.conditions = _.concat(filters.checkedConditions.conditions,
// finalResult.list.leftContent.checked);
resData.list = {
// filters: filters,
// opts: searchHandler.handleOptsData(params, result[2].data.total, result[2].data.filter),
totalCount: totalNum,
footPager: pager(_.get(result.list, 'data.page_total', 0), params),
goods: productProcess.processProductList(_.get(result.list, 'data.product_list', []),
Object.assign({showDiscount: false, isGlobal: true}, params)),
hasNextPage: searchHandler.handleNextPage(params, totalNum),
latestWalk: 6 // 最近浏览记录
};
}
return resData;
});
};
const getGlobalProductDetailData = (skn, channelNum, channel) => {
return Promise.props({
header: headerModel.requestHeaderData(channel),
detail: globalApi.getGlobalProductDetailAsync(skn, channelNum),
html: globalApi.getGlobalProductHtmlAsync(skn, channelNum)
}).then(result => {
let resData = {};
let detailInfo, html = '';
if (+result.detail.code === 200) {
detailInfo = _.get(result, 'detail.data', {});
if (!_.isEmpty(detailInfo.goods_list)) {
let colors = [];
_.forEach(detailInfo.goods_list, (value, index) => {
let size = [];
_.forEach(value.size_list || [], subVal => {
size.push({
sku: subVal.product_sku,
name: subVal.size_name,
soldOut: subVal.storage_number * 1 <= 0
});
});
if (_.isEmpty(value.images_list)) {
value.images_list = [{
image_url: value.color_image
}];
}
if (index === 0 && !detailInfo.mainThumb) {
value.focus = true;
detailInfo.mainThumb = _.get(value, 'images_list[0].image_url', value.color_image);
}
colors.push({
src: value.color_image,
name: value.color_name,
title: value.color_name,
imgList: value.images_list,
focus: value.focus,
size: size
});
});
detailInfo.colors = colors;
}
}
if (result.html) {
let regContent = /<body[^>]*>([\s\S]*)<\/body>/.exec(result.html);
html = regContent[1] || '';
html = html.replace(/<script.*?>.*?<\/script>/ig, '');
}
// console.log(result.detail.code);
Object.assign(resData, result.header, {
goodsInfo: detailInfo,
detailHtml: html || ''
});
return resData;
});
};
module.exports = {
getGlobalProductListData,
getGlobalProductDetailData
};