productListUtil.js
5.76 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
'use strict'
//获取应用实例
let app = getApp();
// const screenHeight = app.globalData.systemInfo.screenHeight;
const windowWidth = app.globalData.systemInfo.windowWidth;
// const windowHeight = app.globalData.systemInfo.windowHeight;
// const DEVICE_WIDTH_RATIO = windowWidth / 320;
let listWidth = windowWidth - 45;
// let listHeight = Math.ceil(254 * DEVICE_WIDTH_RATIO);
// const IMAGE_WIDTH = 161;
// const IMAGE_HEIGHT = 215;
const IMAGE_RATIO = 0.75;
let listImageTop = 31;
let listImageWidthDefault = listWidth / 2;
let listImageHeightDefault = Math.ceil(listImageWidthDefault * 4 / 3);
function parseProductListData(data, listImageWidth, listImageHeight) {
let newData = [];
let imageWidth = listImageWidth ? listImageWidth : listImageWidthDefault;
let imageHeight = listImageHeight ? listImageHeight : listImageHeightDefault;
data && data.map((item, index) => {
let salePrice = 0; // 售卖价
let originPrice = 0; // 原价
let salePriceStr = ''; // 拼接的售卖价
let originPriceStr = ''; // 拼接的原价
let showOriginPrice = true; // 是否显示原价
let salePriceFixed2 = '';
let originPriceFixed2 = '';
let isGlobalProduct = item.is_global && item.is_global == 'Y'; // 是否全球购商品
if (isGlobalProduct) {
salePrice = parseFloat(item.final_price);
originPrice = parseFloat(item.orign_price);
salePriceStr = item.formart_final_price;
originPriceStr = item.formart_orign_price;
} else {
salePrice = parseFloat(item.sales_price);
originPrice = parseFloat(item.market_price);
salePriceStr = '¥' + salePrice.toFixed(2);
originPriceStr = '¥' + originPrice.toFixed(2);
salePriceFixed2 = salePrice.toFixed(2);
originPriceFixed2 = originPrice.toFixed(2);
}
if (!originPrice || (salePrice == originPrice)) {
showOriginPrice = false;
}
item.showOriginPrice = showOriginPrice;
item.salePriceStr = salePriceStr;
item.originPriceStr = originPriceStr;
item.salePriceFixed2 = salePriceFixed2;
item.originPriceFixed2 = originPriceFixed2;
let default_images = item.default_images.replace(/{width}/g, imageWidth*2).replace(/{height}/g, imageHeight*2).replace('{mode}',2);
let shop_id = item.shop_id;
let shop_name = item.shop_name;
// console.log("util name:"+item.product_name+"==skn:"+item.product_skn)
let newItem = {
product_skn: item.product_skn,
default_images,
product_name: item.product_name,
showOriginPrice,
shop_id,
shop_name,
salePriceStr,
originPriceStr,
originPriceFixed2,
salePriceFixed2,
is_shop_cart_add: item.is_shop_cart_add,//是否应该展示右侧的加入购物车按钮 默认不展示
};
newData.push(newItem);
});
return newData;
}
function parseBrandListData(data, listImageWidth, listImageHeight) {
let newData = [];
let imageWidth = listImageWidth ? listImageWidth : listImageWidthDefault;
let imageHeight = listImageHeight ? listImageHeight : listImageHeightDefault;
data && data.map((item, index) => {
let salePrice = 0; // 售卖价
let originPrice = 0; // 原价
let salePriceStr = ''; // 拼接的售卖价
let originPriceStr = ''; // 拼接的原价
let showOriginPrice = true; // 是否显示原价
let salePriceFixed2 = '';
let originPriceFixed2 = '';
let isGlobalProduct = item.is_global && item.is_global == 'Y'; // 是否全球购商品
if (isGlobalProduct) {
salePrice = parseFloat(item.final_price);
originPrice = parseFloat(item.orign_price);
salePriceStr = item.formart_final_price;
originPriceStr = item.formart_orign_price;
} else {
salePrice = parseFloat(item.sales_price);
originPrice = parseFloat(item.market_price);
salePriceStr = '¥' + salePrice.toFixed(2);
originPriceStr = '¥' + originPrice.toFixed(2);
salePriceFixed2 = salePrice.toFixed(2);
originPriceFixed2 = originPrice.toFixed(2);
}
if (!originPrice || (salePrice == originPrice)) {
showOriginPrice = false;
}
item.showOriginPrice = showOriginPrice;
item.salePriceStr = salePriceStr;
item.originPriceStr = originPriceStr;
item.salePriceFixed2 = salePriceFixed2;
item.originPriceFixed2 = originPriceFixed2;
let default_images = item.default_images.replace(/{width}/g, imageWidth*2).replace(/{height}/g, imageHeight*2).replace('{mode}',2);
let shop_id = item.shop_id;
let shop_name = item.shop_name;
let newItem = {
product_skn: item.product_skn,
default_images,
product_name: item.product_name,
showOriginPrice,
shop_id,
shop_name,
salePriceStr,
originPriceStr,
originPriceFixed2,
salePriceFixed2,
is_shop_cart_add: item.is_shop_cart_add,//是否应该展示右侧的加入购物车按钮 默认不展示
};
newData.push(newItem);
});
return newData;
}
function cancelFilterSelectState(filters, exceptKey) {
let newFilters = {};
for (let itemKey in filters) {
if (filters.hasOwnProperty(itemKey)) {
if (itemKey != exceptKey) {
let newFilter = filters[itemKey];
newFilter.selected = false;
newFilters[itemKey] = newFilter;
}
}
}
return newFilters;
}
module.exports = {
parseProductListData,
parseBrandListData,
cancelFilterSelectState,
}