Showing
11 changed files
with
33 additions
and
125 deletions
static/js/home/boys.js
deleted
100644 → 0
static/js/home/column-goods.js
deleted
100644 → 0
static/js/home/girls.js
deleted
100644 → 0
static/js/home/kids.js
deleted
100644 → 0
static/js/home/lifestyle.js
deleted
100644 → 0
@@ -4,103 +4,35 @@ | @@ -4,103 +4,35 @@ | ||
4 | * @date: 2015/10/12 | 4 | * @date: 2015/10/12 |
5 | */ | 5 | */ |
6 | 6 | ||
7 | - /** | ||
8 | - * “你可能喜欢”模块JS | ||
9 | - * @author: xuqi(qi.xu@yoho.cn) | ||
10 | - * @date: 2015/7/15 | ||
11 | - */ | ||
12 | - | ||
13 | var $ = require('yoho.zepto'), | 7 | var $ = require('yoho.zepto'), |
14 | - lazyLoad = require('yoho.lazyload'); | ||
15 | - | ||
16 | -var $maybeLike = $('.maybe-like:last'); | 8 | + lazyLoad = require('yoho.lazyload'), |
9 | + tip = require('../plugin/tip'); | ||
17 | 10 | ||
18 | var winH = $(window).height(), | 11 | var winH = $(window).height(), |
12 | + loadMoreH = $('#load-more').height(), | ||
19 | loading = false, | 13 | loading = false, |
20 | end = false, | 14 | end = false, |
21 | - page = 1, | ||
22 | - type = '', | 15 | + page = 0, |
16 | + gender = '', | ||
23 | num, | 17 | num, |
24 | res; | 18 | res; |
25 | 19 | ||
26 | -var $goodList = $maybeLike.children('.goods-list'), | ||
27 | - mblTop; //页面内容固定,可以预先求出高度 | ||
28 | - | ||
29 | -var isLogin = 'Y'; //是否登录,后台提供,区分走Ajax还是页面跳转 | ||
30 | - | ||
31 | -if ($('.maybe-like').size() <= 0) { | ||
32 | - return; | ||
33 | -} | ||
34 | - | ||
35 | -mblTop = $maybeLike.offset().top; | ||
36 | - | ||
37 | -// 无可能喜欢模块时直接返回 | ||
38 | -if ($maybeLike.length === 0) { | ||
39 | - return; | ||
40 | -} | ||
41 | - | ||
42 | -//read good-info template | ||
43 | -/*$.get('/common/goodinfo', function (data) { | ||
44 | - tpl = '{{# goods}}' + data + '{{/ goods}}'; | ||
45 | - Mustache.parse(tpl); | ||
46 | -});*/ | ||
47 | - | ||
48 | - | ||
49 | -type = $('.mobile-wrap').hasClass('boys-wrap') ? 'index' : 'girl'; | ||
50 | - | ||
51 | -//商品收藏 | ||
52 | -$('.goods-list').delegate('.good-islike', 'touchstart', function (e) { | ||
53 | - var $cur, $good, id, url; | ||
54 | - | ||
55 | - if (isLogin === 'Y') { | ||
56 | - e.preventDefault(); // 阻止链接跳转改AJAX | ||
57 | - | ||
58 | - $cur = $(e.currentTarget); | ||
59 | - $good = $cur.closest('.good-info'); | ||
60 | - id = $good.data('id'); | ||
61 | - | ||
62 | - if ($cur.hasClass('good-like')) { | ||
63 | - url = '/' + type + '/cancelprise'; | ||
64 | - } else { | ||
65 | - url = '/' + type + '/prise'; | ||
66 | - } | ||
67 | - | ||
68 | - | ||
69 | - $.ajax({ | ||
70 | - type: 'GET', | ||
71 | - url: url, | ||
72 | - data: { | ||
73 | - id: id | ||
74 | - } | ||
75 | - }).then(function (data) { | ||
76 | - if (data.code === 200) { | ||
77 | - $cur.toggleClass('good-like'); | ||
78 | - } | ||
79 | - }); | ||
80 | - } | ||
81 | -}); | ||
82 | - | 20 | +gender = $('.mobile-wrap').hasClass('boys-wrap') ? '1,3' : '2,3'; |
83 | 21 | ||
22 | +var $goodList = $('#goods-list'); | ||
84 | 23 | ||
85 | //srcoll to load more | 24 | //srcoll to load more |
86 | $(window).scroll(function () { | 25 | $(window).scroll(function () { |
87 | - if (end || loading) { | ||
88 | - return; | ||
89 | - } | ||
90 | - | ||
91 | - if ($(window).scrollTop() + winH < mblTop + $maybeLike.height()) { | ||
92 | - return; | ||
93 | - } | ||
94 | - | 26 | + if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) { |
95 | loading = true; | 27 | loading = true; |
96 | num = $goodList.children('.good-info').length; | 28 | num = $goodList.children('.good-info').length; |
97 | $.ajax({ | 29 | $.ajax({ |
98 | type: 'GET', | 30 | type: 'GET', |
99 | - url: '/' + type + '/getmore', | 31 | + url: '/product/recom/maylike?gender='+gender, |
100 | data: { | 32 | data: { |
101 | page: page + 1 | 33 | page: page + 1 |
102 | - } | ||
103 | - }).then(function (data) { | 34 | + }, |
35 | + success: function(data) { | ||
104 | if (data.code === 200) { | 36 | if (data.code === 200) { |
105 | res = data.data; | 37 | res = data.data; |
106 | 38 | ||
@@ -108,10 +40,7 @@ $(window).scroll(function () { | @@ -108,10 +40,7 @@ $(window).scroll(function () { | ||
108 | end = res.end; | 40 | end = res.end; |
109 | } | 41 | } |
110 | 42 | ||
111 | - /*$goodList.append(Mustache.render(tpl, { | ||
112 | - goods: res.goods | ||
113 | - }));*/ | ||
114 | - $goodList.append(res.goods); | 43 | + $goodList.append(res.product); |
115 | 44 | ||
116 | //lazyLoad | 45 | //lazyLoad |
117 | lazyLoad($goodList.children('.good-info:gt(' + (num - 1) + ')').find('img.lazy')); | 46 | lazyLoad($goodList.children('.good-info:gt(' + (num - 1) + ')').find('img.lazy')); |
@@ -119,5 +48,13 @@ $(window).scroll(function () { | @@ -119,5 +48,13 @@ $(window).scroll(function () { | ||
119 | loading = false; | 48 | loading = false; |
120 | page++; | 49 | page++; |
121 | } | 50 | } |
51 | + }, | ||
52 | + error: function() { | ||
53 | + tip.show('网络断开连接了~'); | ||
54 | + loading = false; | ||
55 | + } | ||
122 | }); | 56 | }); |
57 | + } | ||
58 | + | ||
59 | + | ||
123 | }); | 60 | }); |
@@ -3,9 +3,18 @@ | @@ -3,9 +3,18 @@ | ||
3 | <i class="icon"></i> | 3 | <i class="icon"></i> |
4 | <span>你可能喜欢</span> | 4 | <span>你可能喜欢</span> |
5 | </p> | 5 | </p> |
6 | + {{# maybeLike}} | ||
6 | <div class="goods-list clearfix"> | 7 | <div class="goods-list clearfix"> |
7 | {{# goods}} | 8 | {{# goods}} |
8 | {{> good}} | 9 | {{> good}} |
9 | {{/ goods}} | 10 | {{/ goods}} |
10 | </div> | 11 | </div> |
12 | + {{/ maybeLike}} | ||
13 | + | ||
14 | + <div id="load-more-info" class="load-more-info"> | ||
15 | + <div class="loading status"> | ||
16 | + 正在加载... | ||
17 | + </div> | ||
18 | + <span class="no-more status hide">没有更多啦</span> | ||
19 | + </div> | ||
11 | </div> | 20 | </div> |
-
Please register or login to post a comment