individuation.js
4.11 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
import $ from 'jquery';
import jsonp from './jsonp';
import utils from './utils';
import cookies from './cookies';
let _replaceData = function(el, cond, data, wh) {
el.find('.brand-name').html(data.brand_name);
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, wh.w, wh.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}`);
let brandDom = el.find('a.product-brand');
if (brandDom) {
if (data.shop_id) {
brandDom.attr('href', `//m.yohobuy.com/product/index/brand?domain=${data.brand_domain}&openby:yohobuy={"action":"go.shop","params":{"shop_id":${data.shop_id},"shop_template_type":${data.shop_template_type}}}`);
} else {
brandDom.attr('href', `//m.yohobuy.com/product/index/brand?domain=${data.brand_domain}&openby:yohobuy={"action":"go.brand","params":{"brand_id":${data.brand_id}}}`);
}
}
let listDom = el.find('a.list-product');
if (listDom) {
let 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);
}
};
let _getProduct = function(param) {
$('.product-source').each(function(indx, el){
el = $(el);
let cloneitem = el.attr('cloneitem'),
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 goods = el.find('.feature-product-info');
if (!goods.length) {
return;
}
if (cloneitem) { // 可复制item
let cnt = cond.limit || 10;
while (goods.length <= cnt) {
goods.push(goods[0].clone().appendTo(el));
}
}
// 获取图片宽x高
let imgwh = el.find('.imgwh').val() || '';
imgwh = imgwh.split('x') || [];
let data,
wh = {
w: imgwh[0] || 300,
h: imgwh[1] || 400
};
goods.each(function(indx, el) {
data = res[indx];
if (!data || !data.default_images) {
return;
}
_replaceData($(el), cond, data, wh);
});
}
});
});
};
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')
});
}
}
};