intro.js
12.9 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*
* @Author: Targaryen
* @Date: 2016-05-18 10:02:21
* @Last Modified by: Targaryen
* @Last Modified time: 2017-05-22 10:06:22
*/
'use strict';
const $ = require('cheerio');
const _ = require('lodash');
// const log = require(`${library}/logger`);
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 商品尺码信息处理
* @param {object} sizeInfo [接口原始数据]
* @return {object} [description]
*/
getSizeInfo(sizeInfo) {
var dest = {},
temp = {};
dest.goodsDescription = {};
dest.goodsDescription.detail = {};
dest.goodsDescription.detail.list = [];
if (_.has(sizeInfo, 'productDescBo.erpProductId')) {
let sex = '通用';
switch (_.get(sizeInfo, 'productDescBo.gender', 0)) {
case 1:
sex = '男款';
break;
case 2:
sex = '女款';
break;
default:
break;
}
dest.goodsDescription.title = '商品信息';
dest.goodsDescription.enTitle = 'DESCRIPTION';
temp = {};
temp.param = '编号:' + _.get(sizeInfo, 'productDescBo.erpProductId', '');
dest.goodsDescription.detail.list.push(temp);
temp = {};
temp.param = '颜色:' + _.get(sizeInfo, 'productDescBo.colorName', '');
dest.goodsDescription.detail.list.push(temp);
temp = {};
temp.param = '性别:' + sex;
dest.goodsDescription.detail.list.push(temp);
}
if (_.has(sizeInfo, 'productDescBo.standardBos')) {
_.forEach(sizeInfo.productDescBo.standardBos, function(value) {
temp = {};
temp.param = value.standardName + ':' +
value.standardVal;
dest.goodsDescription.detail.list.push(temp);
});
}
if (sizeInfo.phrase) {
dest.goodsDescription.desc = sizeInfo.phrase;
}
// 尺码信息
if (sizeInfo.sizeInfoBo) {
dest.sizeInfo = {};
dest.sizeInfo.title = '尺码信息';
dest.sizeInfo.enTitle = 'SIZE INFO';
dest.sizeInfo.detail = {};
dest.sizeInfo.detail.list = [];
// 参考尺码
let boyReference = _.get(sizeInfo, 'productExtra.boyReference', null);
let girlReference = _.get(sizeInfo, 'productExtra.girlReference', null);
let gender = _.get(sizeInfo, 'productDescBo.gender', 3);
let referenceName = '参考尺码';
if ((gender === 1 && boyReference) || (gender === 2 && girlReference)) {
referenceName = '参考尺码';
} else if (gender === 3 && boyReference) {
referenceName = '参考尺码(男)';
} else if (gender === 3 && girlReference) {
referenceName = '参考尺码(女)';
}
let referenceList = [];
// 判断是否显示参考尺码
let showReference = (boyReference && sizeInfo.sizeInfoBo &&
sizeInfo.sizeInfoBo.sizeBoList && sizeInfo.sizeInfoBo.sizeBoList[0] &&
sizeInfo.sizeInfoBo.sizeBoList[0].boyReferSize) ||
(girlReference && sizeInfo.sizeInfoBo && sizeInfo.sizeInfoBo.sizeBoList &&
sizeInfo.sizeInfoBo.sizeBoList[0] && sizeInfo.sizeInfoBo.sizeBoList[0].girlReferSize);
if (showReference) {
referenceList[0] = {};
referenceList[0].param = referenceName;
}
if (_.has(sizeInfo, 'sizeInfoBo.sizeAttributeBos')) {
// [{param: attrName}] th
let sizeNameList = [];
temp = {};
temp.param = '吊牌尺码';
sizeNameList.push(temp);
// {id: [{param: str},......]} sizeBoGroup[id][0] 属性名, sizeBoGroup[id][index] 属性值
let sizeBoGroup = {};
if (_.has(sizeInfo, 'sizeInfoBo.sizeAttributeBos')) {
_.forEach(sizeInfo.sizeInfoBo.sizeAttributeBos, function(attr) {
sizeBoGroup[attr.id] = [];
sizeBoGroup[attr.id][0] = {};
sizeBoGroup[attr.id][0].param = attr.attributeName;
});
}
if (_.has(sizeInfo, 'sizeInfoBo.sizeBoList')) {
_.forEach(sizeInfo.sizeInfoBo.sizeBoList, function(value) {
temp = {};
temp.param = value.sizeName;
sizeNameList.push(temp);
if (boyReference && (gender === 1 || gender === 3)) {
temp = {};
temp.param = (value.boyReferSize && value.boyReferSize.referenceName) || '';
referenceList.push(temp);
} else if (girlReference && (gender === 2 || gender === 3)) {
temp = {};
temp.param = (value.girlReferSize && value.girlReferSize.referenceName) || '';
referenceList.push(temp);
} else {
showReference = false;
}
_.forEach(value.sortAttributes, function(attr) {
temp = {};
temp.param = attr.sizeValue || ' ';
sizeBoGroup[attr.id].push(temp);
});
});
}
// 根据模板页面的显示,按表格一列一列来显示
dest.sizeInfo.detail.list[0] = {};
dest.sizeInfo.detail.list[0].params = sizeNameList;
if (showReference) {
dest.sizeInfo.detail.list[1] = {};
dest.sizeInfo.detail.list[1].params = referenceList;
}
_.forEach(sizeBoGroup, function(value) {
temp = {};
temp.params = value;
dest.sizeInfo.detail.list.push(temp);
});
} else {
dest.sizeInfo.detail.list[0] && (dest.sizeInfo.detail.list[0].params[0] = '');
}
}
// 测量方式
if (sizeInfo.sizeImage) {
dest.measurementMethod = {};
dest.measurementMethod.title = '测量方式';
dest.measurementMethod.enTitle = 'MEASUREMENT METHOD';
dest.measurementMethod.img = sizeInfo.sizeImage;
}
// 模特试穿, 竖着输出排列显示
if (sizeInfo.modelBos) {
let reference = {
title: '模特试穿',
enTitle: 'REFERENCE'
};
dest.reference = reference;
// 控制是否显示备注
let showRemark = false;
let remarkList = [{
param: '备注'
}];
let detail = {
list: [{
params: [{
param: ''
}]
}, {
params: [{
param: '模特'
}]
}, {
params: [{
param: '身高'
}]
}, {
params: [{
param: '体重'
}]
}, {
params: [{
param: '三围'
}]
}, {
params: [{
param: '吊牌尺码'
}]
}, {
params: [{
param: '试穿描述'
}]
}]
};
reference.detail = detail;
_.forEach(sizeInfo.modelBos, function(value) {
detail.list[0].params.push({
param: value.avatar.replace('http://', '//')
});
detail.list[1].params.push({
param: value.modelName
});
detail.list[2].params.push({
param: value.height
});
detail.list[3].params.push({
param: value.weight
});
detail.list[4].params.push({
param: value.vitalStatistics
});
detail.list[5].params.push({
param: value.fitModelBo && value.fitModelBo.fit_size
});
detail.list[6].params.push({
param: value.fitModelBo && value.fitModelBo.feel
});
if (value.fitModelBo && value.fitModelBo.fit_remark) {
showRemark = true;
remarkList.push({
param: value.fitModelBo && value.fitModelBo.fit_remark
});
} else {
remarkList.push({
param: ''
});
}
});
// 显示模特备注
if (showRemark) {
detail.list[7] = {};
detail.list[7].params = remarkList;
}
}
// 商品材质
if (sizeInfo.productMaterialList) {
dest.materials = {};
dest.materials.title = '商品材质';
dest.materials.enTitle = 'MATERIALS';
dest.materials.list = [];
_.forEach(sizeInfo.productMaterialList, function(value) {
temp = {};
temp.img = value.imageUrl;
temp.desc = value.remark;
dest.materials.list.push(temp);
});
}
// 洗涤提示
if (sizeInfo.washTipsBoList) {
dest.washTips = {};
dest.washTips.list = [];
_.forEach(sizeInfo.washTipsBoList, function(value) {
dest.washTips.list.push(value);
});
}
// 详情配图
if (_.has(sizeInfo, 'productIntroBo.productIntro')) {
let productIntro = '';
if (_.has(sizeInfo, 'productDescBo.phrase')) {
productIntro = productIntro + sizeInfo.productDescBo.phrase +
'<br />';
}
if (_.has(sizeInfo, 'productIntroBo.productIntro')) {
productIntro = productIntro + sizeInfo.productIntroBo.productIntro;
}
if (productIntro) {
dest.productDetail = {};
dest.productDetail.title = '商品详情';
dest.productDetail.enTitle = 'DETAILS';
dest.productDetail.desc = productIntro.replace(/\r\n\t/g, '').
replace(/<\/p>/g, '').
replace(/<img src=/g, '<img class="lazy" src="data:image/gif;' +
'base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=="' +
' data-original=').
replace(/<img border="0" src=/g, '<img border="0" class="lazy" ' +
'src="data:image/gif;base64,' +
'R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=="' +
' data-original=').
replace(/.jpg/g, '.jpg?imageMogr2/thumbnail/750x/quality/90');
}
// 清空变量,释放内存
sizeInfo = {};
}
return dest;
}
getintroData(data, req) {
var finalResult;
return this.get({
data: {
method: 'h5.product.intro',
productskn: data.productskn,
udid: req.cookies.udid || 'yoho'
}
}).then(result => {
finalResult = this.getSizeInfo(result);
return finalResult;
});
}
getintroIntro(data) {
return this.get({
data: {
method: 'app.product.intro',
product_skn: data.productskn,
app_version: '6.9.1'
},
param: {cache: true}
}).then(result => {
result = _.isString(result) ? result : '';
result = $.load(result);
result = result('#productDesc');
return (result.html() || '').replace(/<img src=/g, '<img class="lazy" src="data:image/gif;' +
'base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=="' +
' data-original=').replace(/<img border="0" src=/g, '<img border="0" class="lazy" ' +
'src="data:image/gif;base64,' +
'R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=="' +
' data-original=');
});
}
};