...
|
...
|
@@ -6,7 +6,6 @@ |
|
|
|
|
|
'use strict';
|
|
|
const $ = require('cheerio');
|
|
|
const api = global.yoho.API;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
const yhchannelMap = {
|
...
|
...
|
@@ -16,88 +15,98 @@ const yhchannelMap = { |
|
|
lifestyle: '4'
|
|
|
};
|
|
|
|
|
|
module.exports = (data) => {
|
|
|
return api.get('', {
|
|
|
method: 'app.product.preference',
|
|
|
product_skn: data.productskn,
|
|
|
limit: data.limit || '20',
|
|
|
shopId: data.shopId,
|
|
|
yh_channel: yhchannelMap[data.yhChannel]
|
|
|
}, {cache: true}).then(result => {
|
|
|
let goodsContainer = $.load(result)('#shop-goods-container');
|
|
|
let goodThumb = goodsContainer.find('.good-thumb');
|
|
|
module.exports = class extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
goodThumb.each(function(index, domEle) {
|
|
|
let href = $(domEle).attr('href').split('?')[0];
|
|
|
let skn = $(domEle).closest('.good-info').data('id');
|
|
|
preference(data) {
|
|
|
return this.get({
|
|
|
data: {
|
|
|
method: 'app.product.preference',
|
|
|
product_skn: data.productskn,
|
|
|
limit: data.limit || '20',
|
|
|
shopId: data.shopId,
|
|
|
yh_channel: yhchannelMap[data.yhChannel]
|
|
|
},
|
|
|
param: {cache: true}
|
|
|
}).then(result => {
|
|
|
let goodsContainer = $.load(result)('#shop-goods-container');
|
|
|
let goodThumb = goodsContainer.find('.good-thumb');
|
|
|
|
|
|
if (skn) {
|
|
|
href = helpers.urlFormat(`/product/${skn}.html`); // 商品url改版
|
|
|
}
|
|
|
$(domEle).attr('href', href);
|
|
|
});
|
|
|
goodThumb.each(function(index, domEle) {
|
|
|
let href = $(domEle).attr('href').split('?')[0];
|
|
|
let skn = $(domEle).closest('.good-info').data('id');
|
|
|
|
|
|
if (skn) {
|
|
|
href = helpers.urlFormat(`/product/${skn}.html`); // 商品url改版
|
|
|
}
|
|
|
$(domEle).attr('href', href);
|
|
|
});
|
|
|
|
|
|
result = goodsContainer.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];
|
|
|
}
|
|
|
result = goodsContainer.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 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 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 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);
|
|
|
}
|
|
|
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') || '';
|
|
|
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();
|
|
|
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;
|
|
|
});
|
|
|
return result;
|
|
|
});
|
|
|
}
|
|
|
}; |
...
|
...
|
|