individuation.js
3.69 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
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] || 400,
h = imgwh[1] || 300;
goods.each(function(indx, el) {
data = res[indx];
if (!data || !data.default_images) {
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}`);
var listDom = el.find('a.list-product');
if (listDom) {
var sortStr = '',
gender = cond.gender ? cond.gender : '1,3',
url = `//list.m.yohobuy.com?gender=${gender}`;
if (listDom.data('sort')) {
sortStr += `,"sort":${data.small_sort_id}`;
url += `&sort=${data.small_sort_id}`;
}
if (listDom.data('misort')) {
sortStr += `,"misort":${data.middle_sort_id}`;
url += `&misort=${data.middle_sort_id}`;
}
if (listDom.data('msort')) {
sortStr += `,"msort":${data.max_sort_id}`;
url += `&msort=${data.max_sort_id}`;
}
url += `&openby:yohobuy={"action":"go.list","params":{"actiontype":1,"gender":${gender}${sortStr}}}`;
listDom.attr('href', url);
}
});
}
});
});
};
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')
});
}
}
};