item.js
1.71 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
/**
* 商品详情页model
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/7/11
*/
'use strict';
const itemAPI = require('./item-api');
const itemFUN = require('./item-handler');
const _getMultiResourceByBaseInfo = (base, uid) => {
let productId = base.id;
let skn = base.erpProductId;
// let brandId = base.brand.id ? base.brand.id : 0;
// 获取相关数据
let promiseData = [
itemAPI.getsizeInfoAsync(skn),
itemAPI.getProductComfort(productId)
];
if (uid) {
console.log(uid);
// promiseData.push(favoriteBrandService.isFavoriteAsync(uid, productId));
}
return Promise.all(promiseData).then(result => {
return {
sizeInfo: result[0],
comfort: result[1].data
};
});
};
let getProductItemData = (params) => {
let pid = params[0];
// let gid = params[1];
return itemAPI.getProductBaseAsync(pid).then(result => {
let data = {};
if (!result.productName &&
!result.erpProductId &&
!result.productPriceBo) {
return data;
}
// 商品基本信息
Object.assign(data, {
goodInfo: itemFUN.setProductData(result)
});
if (result.brand) {
Object.assign(data, itemFUN.setBrandBanner(result.brand));
// BRAND品牌简介
Object.assign(data, itemFUN.setBrandIntro(result.brand));
}
return _getMultiResourceByBaseInfo(result).then(mulRes => {
// 设置商品描述
Object.assign(data, itemFUN.setDescriptionInfo(mulRes.sizeInfo, mulRes.comfort));
return data;
});
});
};
module.exports = {
getProductItemData
};