preference.js
4.47 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
/*
* @Author: Targaryen
* @Date: 2016-05-18 11:42:11
* @Last Modified by: Targaryen
* @Last Modified time: 2017-02-21 10:03:05
*/
'use strict';
const _ = require('lodash');
const $ = require('cheerio');
const utils = '../../../utils';
const productNameProcess = require(`${utils}/product-name-process`);
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const yhchannelMap = {
boys: '1',
girls: '2',
kids: '3',
lifestyle: '4'
};
const _formatProduct = (data) => {
let list = [];
_.forEach(data, function(value) {
if (!value.product_skn || !value.goods_list || !value.goods_list.length) {
return;
}
value.goodsId = value.goods_list[0].goods_id;
if (value.cn_alphabet) {
value.cn_alphabet = productNameProcess(value.cn_alphabet);
}
let goods = {
salePrice: value.sales_price ? value.sales_price : '',
price: value.market_price ? value.market_price : '',
url: helpers.urlFormat(`/product/pro_${value.product_id}_${value.goodsId}/${value.cn_alphabet}.html`),
thumb: value.default_images,
name: value.product_name
};
// 市场价和售价一样,则不显示市场价
if (goods.salePrice === goods.price) {
goods.price = false;
}
list.push(goods);
});
return list;
};
module.exports = (data) => {
return api.get('', {
method: 'app.product.preference',
product_skn: data.productskn,
limit: data.limit || '20'
}).then(result => {
result = $.load(result)('#goods-container').append(
`<script type="text/javascript">
(function() {
var qs = {};
var hashes = window.location.search.slice(1).split('&');
for (var i = 0; i < hashes.length; i++) {
var hash = hashes[i].split('=');
qs[hash[0]] = hash[1];
}
var uid = '';
window._ozuid = uid; // 暴露ozuid
if (window._yas) {
window._yas(1 * new Date(), '2.0.0', 'yohobuy_m', uid, '', '');
}
// 店铺推荐点击商品 埋点
var C_ID = qs.yh_channel || 1;
var RECID = (new Date().getTime() + '_H5_YOHOBUY_' + Math.floor(Math.random() * 1000000 + 1000000) + '_' + Math.floor(Math.random() * 1000000 + 1000000));
var goodDom = document.getElementsByClassName("good-info");
for(var i = 0; i < goodDom.length; i++) {
goodDom[i].addEventListener('click', function(e) {
if (!window._yas || !window._yas.sendAppLogs) {
return;
}
var PRD_ID = e.currentTarget.getAttribute('data-good-id');
var PRD_NUM = e.currentTarget.getAttribute('data-good-index');
window._yas.sendAppLogs({
appop: 'YB_CHOOSE_FOR_YOU',
param: JSON.stringify({
REC_POSE: 100013,
REC_ID: RECID,
PRD_ID: PRD_ID,
PRD_NUM: PRD_NUM,
C_ID: C_ID,
ACTION_ID: 1
})
}, true);
}, false);
}
// 店铺推荐展示 埋点
setTimeout(function(){
// 店铺推荐展示 埋点
if (window._yas && typeof window._yas.sendAppLogs === 'function') {
var prdIds = document.getElementById('prdIds') || {};
var ids = prdIds.getAttribute('value') || '';
window._yas.sendAppLogs({
appop: 'YB_CHOOSE_FOR_YOU',
param: JSON.stringify({
REC_POSE: 100013,
REC_ID: RECID,
PRD_ID: ids,
PRD_NUM: ids.split(',').length,
C_ID: C_ID,
ACTION_ID: 0
})
}, true);
}
}, 2000);
}());</script>`
).html();
return result;
});
};