individuation.js
2.57 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
import $ from 'jquery';
import jsonp from './jsonp';
import utils from './utils';
import cookies from './cookies';
let _getProduct = function(param) {
$('.product-source').each(function(indx, el){
el = $(el);
let cond = JSON.parse(el.attr('condition') || '{}');
jsonp({
url: '//m.yohobuy.com/activity/individuation?callback=?',
data: Object.assign({}, param, cond)
}).then((res)=> {
if (res && res.length) {
let data,
goods = el.find('.feature-product-info');
if (!goods.length) {
return;
}
// 获取图片宽x高
let imgwh = el.find('#imgwh').val() || '';
imgwh = imgwh.split('x') || [];
let w = imgwh[0] || 450,
h = imgwh[1] || 500;
goods.each(function(indx, el) {
data = res[indx];
if (!data) {
return;
}
el = $(el);
el.find('.brand-name').html(data.brand_name);
el.find('a.product-brand').attr('href', `//m.yohobuy.com/product/index/brand?domain=${data.brand_domain}`);
el.find('a.product-detail').attr('href', `//m.yohobuy.com/product/pro_${data.product_id}_${data.goods_id}/${data.cn_alphabet}.html?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${data.product_skn}}}`);
el.find('.product-detail-img').attr('src', utils.image(data.default_images, w, h, 2, 60));
el.find('.product-name').html(data.product_name);
el.find('.sale-price').html(`¥${data.sales_price}`);
el.find('.market-price').html(`¥${data.market_price}`);
});
}
});
});
};
export default {
init(uid) {
if (utils.isApp()) {
document.addEventListener('deviceready', function() {
window.yohoInterface.triggerEvent(function(data) {
// 获取个性话数据
_getProduct({
uid: data.uid,
udid: data.udid
});
}, function() {}, {
method: 'get.analyticAppData'
});
}, false);
} else {
// 获取个性话数据
_getProduct({
uid: uid,
udid: cookies.cookie('_yasvd')
});
}
}
};