Showing
11 changed files
with
54 additions
and
146 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,120 +4,57 @@ | @@ -4,120 +4,57 @@ | ||
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 | - } | 20 | +gender = $('.mobile-wrap').hasClass('boys-wrap') ? '1,3' : '2,3'; |
67 | 21 | ||
22 | +var $goodList = $('#goods-list'); | ||
68 | 23 | ||
24 | +//srcoll to load more | ||
25 | +$(window).scroll(function () { | ||
26 | + if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) { | ||
27 | + loading = true; | ||
28 | + num = $goodList.children('.good-info').length; | ||
69 | $.ajax({ | 29 | $.ajax({ |
70 | type: 'GET', | 30 | type: 'GET', |
71 | - url: url, | 31 | + url: '/product/recom/maylike?gender='+gender, |
72 | data: { | 32 | data: { |
73 | - id: id | ||
74 | - } | ||
75 | - }).then(function (data) { | ||
76 | - if (data.code === 200) { | ||
77 | - $cur.toggleClass('good-like'); | 33 | + page: page + 1 |
34 | + }, | ||
35 | + success: function(data) { | ||
36 | + if (data.code === 200) { | ||
37 | + res = data.data; | ||
38 | + | ||
39 | + if (res.end) { | ||
40 | + end = res.end; | ||
41 | + } | ||
42 | + | ||
43 | + $goodList.append(res.product); | ||
44 | + | ||
45 | + //lazyLoad | ||
46 | + lazyLoad($goodList.children('.good-info:gt(' + (num - 1) + ')').find('img.lazy')); | ||
47 | + | ||
48 | + loading = false; | ||
49 | + page++; | ||
50 | + } | ||
51 | + }, | ||
52 | + error: function() { | ||
53 | + tip.show('网络断开连接了~'); | ||
54 | + loading = false; | ||
78 | } | 55 | } |
79 | }); | 56 | }); |
80 | } | 57 | } |
81 | -}); | ||
82 | - | ||
83 | - | ||
84 | - | ||
85 | -//srcoll to load more | ||
86 | -$(window).scroll(function () { | ||
87 | - if (end || loading) { | ||
88 | - return; | ||
89 | - } | ||
90 | - | ||
91 | - if ($(window).scrollTop() + winH < mblTop + $maybeLike.height()) { | ||
92 | - return; | ||
93 | - } | ||
94 | - | ||
95 | - loading = true; | ||
96 | - num = $goodList.children('.good-info').length; | ||
97 | - $.ajax({ | ||
98 | - type: 'GET', | ||
99 | - url: '/' + type + '/getmore', | ||
100 | - data: { | ||
101 | - page: page + 1 | ||
102 | - } | ||
103 | - }).then(function (data) { | ||
104 | - if (data.code === 200) { | ||
105 | - res = data.data; | ||
106 | - | ||
107 | - if (res.end) { | ||
108 | - end = res.end; | ||
109 | - } | ||
110 | - | ||
111 | - /*$goodList.append(Mustache.render(tpl, { | ||
112 | - goods: res.goods | ||
113 | - }));*/ | ||
114 | - $goodList.append(res.goods); | ||
115 | - | ||
116 | - //lazyLoad | ||
117 | - lazyLoad($goodList.children('.good-info:gt(' + (num - 1) + ')').find('img.lazy')); | ||
118 | 58 | ||
119 | - loading = false; | ||
120 | - page++; | ||
121 | - } | ||
122 | - }); | 59 | + |
123 | }); | 60 | }); |
@@ -54,11 +54,9 @@ | @@ -54,11 +54,9 @@ | ||
54 | {{# plusStar}} | 54 | {{# plusStar}} |
55 | {{> home/plus_star}} | 55 | {{> home/plus_star}} |
56 | {{/ plusStar}} | 56 | {{/ plusStar}} |
57 | - | ||
58 | - | ||
59 | - {{! 可能喜欢}} | ||
60 | - {{# maybeLike}} | ||
61 | - {{> home/maybe_like}} | ||
62 | - {{/ maybeLike}} | 57 | + |
58 | + {{! 可能喜欢}} | ||
59 | + {{> home/maybe_like}} | ||
60 | + | ||
63 | 61 | ||
64 | {{/ content}} | 62 | {{/ content}} |
@@ -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