bundle.js
1.92 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
/**
* Created by targaryen on 2016/11/28.
*/
'use strict';
const utils = '../../../utils';
const _ = require('lodash');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const productProcess = require(`${utils}/product-process`);
/**
* 从接口获取套装数据
* @private
*/
const getBundleBySkn = (productSkn) => {
return api.get('', {
method: 'app.query.bundleSkn',
product_skn: productSkn
}, {cache: false}).then(result => {
return result;
});
};
/**
* 套装详情页数据
* @param params
* @returns {*}
*/
const detail = (params) => {
if (!params.skn && !params.bundle_skn) {
return Promise.resolve({});
}
let bundleIndex = (params.index || 1);
--bundleIndex;
return getBundleBySkn(params.skn || params.bundle_skn).then(result => {
if (_.has(result, `data[${bundleIndex}]`)) {
let shareInfo = _.get(result, 'data[0].shareInfo', {});
return {
bundleDatas: _.map(result.data, (bundle, index) => {
return {
selected: index === bundleIndex,
title: _.get(bundle, 'bundleInfo.tabName') || '',
href: helpers.urlFormat('/product/bundle/detail', {skn: params.skn, index: ++index}),
};
}),
shareInfo: {
imgUrl: `http:${helpers.image(shareInfo.imgUrl, 300, 300)}`,
subTitle: encodeURIComponent(shareInfo.subTitle),
title: encodeURIComponent(shareInfo.title),
url: shareInfo.url
},
bundleInfo: _.get(result, `data[${bundleIndex}].bundleInfo`, {}),
productList: productProcess.processProductList(_.get(result, `data[${bundleIndex}].productList`, []))
};
}
return {};
});
};
module.exports = {
getBundleBySkn,
detail
};