resources-process.js
3.29 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
'use strict';
const _ = require('lodash');
const processTime = require('./time-process');
/**
* 处理楼层数据
* @param {[array]} list
* @return {[array]}
*/
module.exports = (list) => {
const formatData = [];
list = list || [];
_.forEach(list, (floor) => {
floor[_.camelCase(floor.template_name)] = true;
// 特殊资源位处理
// PLUS
if (floor.singleNameImage && floor.data) {
floor.data.title = {
title: floor.data.title
};
}
// 潮流时装/经典裤裙/时尚靴履/潮人配饰/潮流上装
if (floor.recommendContentOne && floor.data) {
if (floor.data.big_image && floor.data.big_image.length > 1) {
floor.data.big_image = {
bigList: floor.data.big_image
};
}
}
// OUTLETS
if (floor.titleImage && floor.data) {
if (floor.data.image) {
floor.data.big_image = {
bigList: [floor.data.image]
};
}
floor.data.title = {
more_name: floor.data.more_name,
more_url: floor.data.more_url,
title: floor.data.title
};
}
// 折扣专场
if (floor.discountActivity && floor.data && floor.data.list.length) {
_.map(floor.data.list, (item) => {
Object.assign(item, processTime(item.left_time));
});
}
// 断码区 , 此资源位数据结构比较坑
if (floor.offCodeArea && floor.data && floor.data.list.length) {
floor.data = {
title: floor.data.title,
data: [floor.data.list[0]],
left: [floor.data.list[1]],
right: floor.data.list.slice(2)
};
}
// 会员专享
if (floor.vipFloor && floor.data) {
floor.data.data = floor.data.image;
}
// 单张轮播图
floor.singleImage &&
floor.data.length === 1 &&
(floor.singleOne = true);
if (floor.newSingleImage && floor.data.list.length === 1) {
floor.singleOne = true;
floor.data = {
imageWidth: floor.data.imageWidth,
imageHeight: floor.data.imageHeight,
src: floor.data.list[0].src,
url: floor.data.list[0].url
};
}
// 处理价格两位小数
if ((floor.vipUse || floor.popularSingleProduct || floor.newUserFloor) && floor.data) {
for (let item of floor.data.list) {
item.vip1_price && (item.vip1_price = item.vip1_price.toFixed(2));
item.vip2_price && (item.vip2_price = item.vip2_price.toFixed(2));
item.vip3_price && (item.vip3_price = item.vip3_price.toFixed(2));
item.sales_price && (item.sales_price = item.sales_price.toFixed(2));
item.market_price && (item.market_price = item.market_price.toFixed(2));
}
}
// sale banner名字
if (floor.sale1T1L4R && floor.data && floor.data.big_image) {
floor.data.banner_image = floor.data.big_image;
}
formatData.push(floor);
});
return formatData;
};