latest-walk.js
1.61 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
/**
* 最近浏览取接口渲染模板
* @author: xuqi<qi.xu@yoho.cn>
8 @date: 2016/1/20
*/
var $ = require('yoho-jquery');
var Handlebars = require('yoho-handlebars');
var lazyLoad = require('yoho-jquery-lazyload');
var $latestWalkCount = $('#latest-walk-count');
(function() {
var tpl;
if ($latestWalkCount.length === 0) {
return;
}
tpl = Handlebars.compile($('#latest-walk-tpl').html());
$.ajax({
url: 'http://www.yohobuy.com/common/recentReview',
dataType: 'jsonp',
data: {
limit: $latestWalkCount.val()
},
success: function(data) {
var latestWalk = [],
res, i, cur;
if (data.code === 200) {
res = data.data;
// 若无最近浏览,请隐藏容器
if (res.length === 0) {
$('.latest-walk').addClass('hide');
return;
}
for (i = 0; i < res.length; i++) {
cur = res[i];
latestWalk.push({
href: cur.url,
img: cur.pic_url,
name: cur.product_name,
salePrice: cur.price,
marketPrice: cur.market_price
});
}
if (latestWalk.length > 0) {
$('#latest-walk-goods').html(tpl({
latestWalk: latestWalk
}));
lazyLoad($('#latest-walk-goods .lazy'));
}
}
}
});
}());