|
@@ -9,94 +9,139 @@ new Swiper('.swiper-container', { |
|
@@ -9,94 +9,139 @@ new Swiper('.swiper-container', { |
9
|
autoplay: 3000
|
9
|
autoplay: 3000
|
10
|
});
|
10
|
});
|
11
|
|
11
|
|
12
|
-//img-lazyload
|
|
|
13
|
-function lazyLoad(imgs) {
|
|
|
14
|
- var $imgs;
|
|
|
15
|
- if (typeof imgs === 'undefined') {
|
|
|
16
|
- $imgs = $('img.lazy');
|
|
|
17
|
- } else {
|
|
|
18
|
- $imgs = imgs;
|
12
|
+/**
|
|
|
13
|
+ * 初始化页面功能
|
|
|
14
|
+ */
|
|
|
15
|
+exports.init = function (url) {
|
|
|
16
|
+ //img-lazyload
|
|
|
17
|
+ function lazyLoad(imgs) {
|
|
|
18
|
+ var $imgs;
|
|
|
19
|
+ if (typeof imgs === 'undefined') {
|
|
|
20
|
+ $imgs = $('img.lazy');
|
|
|
21
|
+ } else {
|
|
|
22
|
+ $imgs = imgs;
|
|
|
23
|
+ }
|
|
|
24
|
+ $imgs.lazyload({
|
|
|
25
|
+ effect: 'fadeIn',
|
|
|
26
|
+ effect_speed: 10,
|
|
|
27
|
+ placeholder: 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
|
|
|
28
|
+ });
|
19
|
}
|
29
|
}
|
20
|
- $imgs.lazyload({
|
|
|
21
|
- effect: 'fadeIn',
|
|
|
22
|
- effect_speed: 10,
|
|
|
23
|
- placeholder: 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
|
|
|
24
|
- });
|
|
|
25
|
-}
|
|
|
26
|
-
|
|
|
27
|
-lazyLoad();
|
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-var $newArrival = $('.new-arrival:last');
|
|
|
31
|
-
|
|
|
32
|
-// 无最新单品推荐模块时直接返回
|
|
|
33
|
-if ($newArrival.length === 0) {
|
|
|
34
|
- return;
|
|
|
35
|
-}
|
|
|
36
|
|
30
|
|
37
|
-var isLogin = $('#is-login').val();
|
|
|
38
|
-isLogin = isLogin ? isLogin : 'N';
|
|
|
39
|
-//登录提示变量
|
|
|
40
|
-var $loginTip = $('#login-tip');
|
31
|
+ lazyLoad();
|
41
|
|
32
|
|
42
|
-var winH = $(window).height(),
|
|
|
43
|
- loading = false,
|
|
|
44
|
- end = false,
|
|
|
45
|
- page = 1,
|
|
|
46
|
- tpl;
|
|
|
47
|
|
33
|
|
48
|
-var $goodList = $newArrival.children('.goods-list'),
|
|
|
49
|
- mblTop = $newArrival.offset().top; //页面内容固定,可以预先求出高度
|
34
|
+ var $newArrival = $('.new-arrival:last');
|
50
|
|
35
|
|
51
|
-//read good-info template
|
|
|
52
|
-$.get('/common/goodinfo', function (data) {
|
|
|
53
|
- tpl = '{{# goods}}' + data + '{{/ goods}}';
|
|
|
54
|
- Mustache.parse(tpl);
|
|
|
55
|
-});
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-//srcoll to load more
|
|
|
59
|
-$(window).scroll(function () {
|
|
|
60
|
- var num;
|
|
|
61
|
- if (end || loading) {
|
36
|
+ // 无最新单品推荐模块时直接返回
|
|
|
37
|
+ if ($newArrival.length === 0) {
|
62
|
return;
|
38
|
return;
|
63
|
}
|
39
|
}
|
64
|
|
40
|
|
65
|
- if ($(window).scrollTop() + winH < mblTop + $newArrival.height()) {
|
|
|
66
|
- return;
|
|
|
67
|
- }
|
41
|
+ var isLogin = $('#is-login').val();
|
|
|
42
|
+ isLogin = isLogin ? isLogin : 'N';
|
|
|
43
|
+ //登录提示变量
|
|
|
44
|
+ var $loginTip = $('#login-tip');
|
|
|
45
|
+
|
|
|
46
|
+ var winH = $(window).height(),
|
|
|
47
|
+ loading = false,
|
|
|
48
|
+ end = false,
|
|
|
49
|
+ page = 1,
|
|
|
50
|
+ tpl;
|
|
|
51
|
+ var $father = $('.new-arrival-content');
|
|
|
52
|
+ //var $goodList = $newArrival.children('.goods-list'),
|
|
|
53
|
+ var mblTop = $newArrival.offset().top; //页面内容固定,可以预先求出高度
|
|
|
54
|
+
|
|
|
55
|
+ tpl = ["<div class=\"good-info\" data-id=\"{{id}}\">",
|
|
|
56
|
+ " <div class=\"tag-container clearfix\">",
|
|
|
57
|
+ " {{# tags}}",
|
|
|
58
|
+ " {{# isNew}}",
|
|
|
59
|
+ " <p class=\"good-tag new-tag\">NEW</p>",
|
|
|
60
|
+ " {{/ isNew}}",
|
|
|
61
|
+ " {{# isReNew}}",
|
|
|
62
|
+ " <p class=\"good-tag renew-tag\">再到着</p>",
|
|
|
63
|
+ " {{/ isReNew}}",
|
|
|
64
|
+ " {{# isSale}}",
|
|
|
65
|
+ " <p class=\"good-tag sale-tag\">SALE</p>",
|
|
|
66
|
+ " {{/ isSale}}",
|
|
|
67
|
+ " {{# isYohood}}",
|
|
|
68
|
+ " <div class=\"good-tag yohood-tag\"></div>",
|
|
|
69
|
+ " {{/ isYohood}}",
|
|
|
70
|
+ " {{# isLimit}}",
|
|
|
71
|
+ " <p class=\"good-tag limit-tag\">限量商品</p>",
|
|
|
72
|
+ " {{/ isLimit}}",
|
|
|
73
|
+ " {{/ tags}}",
|
|
|
74
|
+ " </div>",
|
|
|
75
|
+ " <div class=\"good-detail-img\">",
|
|
|
76
|
+ " <a class=\"good-islike {{# isLike}}good-like{{/ isLike}} iconfont\" href=\"{{likeUrl}}\"></a>",
|
|
|
77
|
+ " <a class=\"good-thumb\" href=\"{{url}}\">",
|
|
|
78
|
+ " <img class=\"lazy\" data-original=\"{{src}}\">",
|
|
|
79
|
+ " </a>",
|
|
|
80
|
+ " {{# isFew}}",
|
|
|
81
|
+ " <p class=\"few-tag\">即将售罄</p>",
|
|
|
82
|
+ " {{/ isFew}}",
|
|
|
83
|
+ " </div>",
|
|
|
84
|
+ " <div class=\"good-detail-text\">",
|
|
|
85
|
+ " <div class=\"name\">",
|
|
|
86
|
+ " <a href=\"{{url}}\">{{name}}</a>",
|
|
|
87
|
+ " </div>",
|
|
|
88
|
+ " <div class=\"price\">",
|
|
|
89
|
+ " <span class=\"sale-price {{^price}}no-price{{/price}}\">¥{{salePrice}}</span>",
|
|
|
90
|
+ " {{#price}}",
|
|
|
91
|
+ " <span class=\"market-price\">¥{{.}}</span>",
|
|
|
92
|
+ " {{/price}}",
|
|
|
93
|
+ " </div>",
|
|
|
94
|
+ " </div>",
|
|
|
95
|
+ "</div>"].join("");
|
|
|
96
|
+ tpl = '{{# goods}}' + tpl + '{{/ goods}}';
|
|
|
97
|
+ //read good-info template
|
|
|
98
|
+ /*$.get('/common/goodinfo', function (data) {
|
|
|
99
|
+ tpl = '{{# goods}}' + data + '{{/ goods}}';
|
|
|
100
|
+ Mustache.parse(tpl);
|
|
|
101
|
+ });*/
|
|
|
102
|
+ Mustache.parse(tpl);
|
68
|
|
103
|
|
69
|
- loading = true;
|
|
|
70
|
- num = $goodList.children('.good-info').length;
|
|
|
71
|
- $.ajax({
|
|
|
72
|
- type: 'GET',
|
|
|
73
|
- url: '/goods/more',
|
|
|
74
|
- data: {
|
|
|
75
|
- //gender: 0, //性别
|
|
|
76
|
- page: page + 1
|
104
|
+ //srcoll to load more
|
|
|
105
|
+ $(window).scroll(function () {
|
|
|
106
|
+ var num;
|
|
|
107
|
+ if (end || loading) {
|
|
|
108
|
+ return;
|
77
|
}
|
109
|
}
|
78
|
- }).then(function (data) {
|
|
|
79
|
- var res,
|
|
|
80
|
- i;
|
|
|
81
|
- if (data.code === 200) {
|
|
|
82
|
- res = data.data;
|
|
|
83
|
-
|
|
|
84
|
- if (res.end) {
|
|
|
85
|
- end = res.end;
|
|
|
86
|
- }
|
|
|
87
|
|
110
|
|
88
|
- $goodList.append(Mustache.render(tpl, {
|
|
|
89
|
- goods: res.goods
|
|
|
90
|
- }));
|
|
|
91
|
-
|
|
|
92
|
- //lazyLoad
|
|
|
93
|
- lazyLoad($goodList.children('.good-info:gt(' + (num - 1) + ')').find('img.lazy'));
|
|
|
94
|
-
|
|
|
95
|
- loading = false;
|
|
|
96
|
- page++;
|
111
|
+ if ($(window).scrollTop() + winH < mblTop + $newArrival.height()) {
|
|
|
112
|
+ return;
|
97
|
}
|
113
|
}
|
98
|
- });
|
|
|
99
|
-});
|
|
|
100
|
-
|
|
|
101
|
|
114
|
|
|
|
115
|
+ loading = true;
|
|
|
116
|
+ num = $father.children('.good-info').length;
|
|
|
117
|
+ $.ajax({
|
|
|
118
|
+ type: 'GET',
|
|
|
119
|
+ url: url,
|
|
|
120
|
+ data: {
|
|
|
121
|
+ //gender: 0, //性别
|
|
|
122
|
+ page: page + 1
|
|
|
123
|
+ }
|
|
|
124
|
+ }).then(function (data) {
|
|
|
125
|
+ var res,
|
|
|
126
|
+ i;
|
|
|
127
|
+ if (data.code === 200) {
|
|
|
128
|
+ res = data.data;
|
|
|
129
|
+
|
|
|
130
|
+ if (res.end) {
|
|
|
131
|
+ end = res.end;
|
|
|
132
|
+ }
|
|
|
133
|
+ console.log("aaa");
|
|
|
134
|
+ $father.append(Mustache.render(tpl, {
|
|
|
135
|
+ goods: res.goods
|
|
|
136
|
+ }));
|
|
|
137
|
+
|
|
|
138
|
+ //lazyLoad
|
|
|
139
|
+ lazyLoad($father.children('.good-info:gt(' + (num - 1) + ')').find('img.lazy'));
|
|
|
140
|
+
|
|
|
141
|
+ loading = false;
|
|
|
142
|
+ page++;
|
|
|
143
|
+ }
|
|
|
144
|
+ });
|
|
|
145
|
+ });
|
|
|
146
|
+};
|
102
|
|
147
|
|