|
@@ -2,93 +2,14 @@ |
|
@@ -2,93 +2,14 @@ |
2
|
* Created by yoho on 2017-01-13.
|
2
|
* Created by yoho on 2017-01-13.
|
3
|
*/
|
3
|
*/
|
4
|
|
4
|
|
|
|
5
|
+var lazyLoad = require('yoho-jquery-lazyload');
|
|
|
6
|
+var dataLazyLoad = require('../plugins/lazy-load')(document);
|
|
|
7
|
+
|
5
|
var capi = require('./cart-api');
|
8
|
var capi = require('./cart-api');
|
6
|
var togetherTpl = require('hbs/cart/cart-together-item.hbs');
|
9
|
var togetherTpl = require('hbs/cart/cart-together-item.hbs');
|
7
|
var $togetherSlide = $('[data-role=together-slide]');
|
10
|
var $togetherSlide = $('[data-role=together-slide]');
|
8
|
var $fineSlide = $('[data-role=fine-slide]');
|
11
|
var $fineSlide = $('[data-role=fine-slide]');
|
9
|
-
|
|
|
10
|
-// 推荐、优选、浏览切换
|
|
|
11
|
-$(function() {
|
|
|
12
|
- var $togetherGoods = $('.individual-item-togetherGoods'),
|
|
|
13
|
- $recommendGoods = $('.individual-item-recommendGoods'),
|
|
|
14
|
- $latestWalk = $('.individual-item-latestWalk');
|
|
|
15
|
-
|
|
|
16
|
- if ($togetherGoods.hasClass('none')) {
|
|
|
17
|
- $recommendGoods.show();
|
|
|
18
|
- }
|
|
|
19
|
-
|
|
|
20
|
- $('.bottom-tab-slide').on('click', '.bottom-title', function() {
|
|
|
21
|
- var $this = $(this),
|
|
|
22
|
- index = $this.index();
|
|
|
23
|
- console.log(index);
|
|
|
24
|
- $togetherGoods.hide();
|
|
|
25
|
- $recommendGoods.hide();
|
|
|
26
|
-
|
|
|
27
|
- if ($this.hasClass('change')) {
|
|
|
28
|
- return;
|
|
|
29
|
- }
|
|
|
30
|
- if ($this.hasClass('cur')) {
|
|
|
31
|
- return;
|
|
|
32
|
- }
|
|
|
33
|
-
|
|
|
34
|
- $this.addClass('cur');
|
|
|
35
|
- $this.siblings('.cur').removeClass('cur');
|
|
|
36
|
-
|
|
|
37
|
- switch (index) {
|
|
|
38
|
- case 0: {
|
|
|
39
|
- $togetherGoods.slideDown();
|
|
|
40
|
- $recommendGoods.hide();
|
|
|
41
|
- $latestWalk.hide();
|
|
|
42
|
- break;
|
|
|
43
|
- }
|
|
|
44
|
- case 1: {
|
|
|
45
|
- $togetherGoods.hide();
|
|
|
46
|
- $recommendGoods.slideDown();
|
|
|
47
|
- $latestWalk.hide();
|
|
|
48
|
- break;
|
|
|
49
|
- }
|
|
|
50
|
- case 2: {
|
|
|
51
|
- $togetherGoods.hide();
|
|
|
52
|
- $recommendGoods.hide();
|
|
|
53
|
- $latestWalk.slideDown();
|
|
|
54
|
- break;
|
|
|
55
|
- }
|
|
|
56
|
- }
|
|
|
57
|
- });
|
|
|
58
|
-});
|
|
|
59
|
-
|
|
|
60
|
-
|
|
|
61
|
-// 凑单 底部 轮播
|
|
|
62
|
-function loadSlideGoods() {
|
|
|
63
|
- $.ajax({
|
|
|
64
|
- type: 'GET',
|
|
|
65
|
- url: '',
|
|
|
66
|
- data: {
|
|
|
67
|
- // skn: skn,
|
|
|
68
|
- size: 20,
|
|
|
69
|
- num: 1
|
|
|
70
|
- }
|
|
|
71
|
- }).then(function(data) {
|
|
|
72
|
- // var pro = data.data.products;
|
|
|
73
|
-
|
|
|
74
|
- // if (data.code === 200) {
|
|
|
75
|
- // if (pro.length === 0) {
|
|
|
76
|
- // return;
|
|
|
77
|
- // }
|
|
|
78
|
-
|
|
|
79
|
- $('#recommend-shop').removeClass('none');
|
|
|
80
|
-
|
|
|
81
|
- $('.individual-item ').slider2({
|
|
|
82
|
- shownum: 5,
|
|
|
83
|
- isCircle: true
|
|
|
84
|
- });
|
|
|
85
|
-
|
|
|
86
|
- // } else {
|
|
|
87
|
- // $('.bottom-title').filter('.change').addClass('none');
|
|
|
88
|
- // }
|
|
|
89
|
- });
|
|
|
90
|
-}
|
|
|
91
|
-loadSlideGoods();
|
12
|
+var $latestWalkSlide = $('[data-role=latestWalk-slide]');
|
92
|
|
13
|
|
93
|
function loadTogetherProduct(page) {
|
14
|
function loadTogetherProduct(page) {
|
94
|
capi.getTogetherProduct(page).done(function(togetherInfo) {
|
15
|
capi.getTogetherProduct(page).done(function(togetherInfo) {
|
|
@@ -104,25 +25,88 @@ function loadTogetherProduct(page) { |
|
@@ -104,25 +25,88 @@ function loadTogetherProduct(page) { |
104
|
function loadFineProduct(page) {
|
25
|
function loadFineProduct(page) {
|
105
|
capi.getFineProduct(page).done(function(fineInfo) {
|
26
|
capi.getFineProduct(page).done(function(fineInfo) {
|
106
|
if (fineInfo && fineInfo.code === 200) {
|
27
|
if (fineInfo && fineInfo.code === 200) {
|
107
|
- $fineSlide.html(togetherTpl(fineInfo.data));
|
28
|
+ $fineSlide.html(togetherTpl($.extend({
|
|
|
29
|
+ showAdd2Cart: true
|
|
|
30
|
+ }, fineInfo.data)));
|
|
|
31
|
+
|
|
|
32
|
+ lazyLoad($fineSlide.find('.lazy'));
|
108
|
}
|
33
|
}
|
109
|
});/* .fail(function() {
|
34
|
});/* .fail(function() {
|
110
|
|
35
|
|
111
|
});*/
|
36
|
});*/
|
112
|
}
|
37
|
}
|
113
|
|
38
|
|
114
|
-setTimeout(function() {
|
|
|
115
|
- loadTogetherProduct(1);
|
|
|
116
|
- loadFineProduct(1);
|
|
|
117
|
-}, 0);
|
39
|
+function fetchLatestWalk(num) {
|
|
|
40
|
+
|
|
|
41
|
+ $.ajax({
|
|
|
42
|
+ url: 'http://www.yohobuy.com/common/recentReview',
|
|
|
43
|
+ dataType: 'jsonp',
|
|
|
44
|
+ data: {
|
|
|
45
|
+ limit: num || 15
|
|
|
46
|
+ },
|
|
|
47
|
+ success: function(data) {
|
|
|
48
|
+ var latestWalk = [],
|
|
|
49
|
+ res, i, cur;
|
|
|
50
|
+
|
|
|
51
|
+ if (data.code === 200) {
|
|
|
52
|
+ res = data.data;
|
|
|
53
|
+
|
|
|
54
|
+ // 若无最近浏览,请隐藏容器
|
|
|
55
|
+ if (res.length === 0) {
|
|
|
56
|
+ $latestWalkSlide.hide();
|
|
|
57
|
+ $('[data-role=latestWalk-tab]').hide();
|
|
|
58
|
+ return;
|
|
|
59
|
+ }
|
|
|
60
|
+
|
|
|
61
|
+ for (i = 0; i < res.length; i++) {
|
|
|
62
|
+ cur = res[i];
|
|
|
63
|
+
|
|
|
64
|
+ latestWalk.push({
|
|
|
65
|
+ href: cur.url,
|
|
|
66
|
+ img: cur.pic_url,
|
|
|
67
|
+ title: cur.product_name,
|
|
|
68
|
+ price: cur.price,
|
|
|
69
|
+ marketPrice: cur.market_price
|
|
|
70
|
+ });
|
|
|
71
|
+ }
|
|
|
72
|
+
|
|
|
73
|
+ $latestWalkSlide.html(togetherTpl({
|
|
|
74
|
+ item: latestWalk,
|
|
|
75
|
+ hasNext: latestWalk && latestWalk.length > 5,
|
|
|
76
|
+ hasPrev: latestWalk && latestWalk.length > 5
|
|
|
77
|
+ }));
|
|
|
78
|
+ lazyLoad($latestWalkSlide.find('.lazy'));
|
|
|
79
|
+
|
|
|
80
|
+ $latestWalkSlide.find('.individual-item').slider2({
|
|
|
81
|
+ shownum: 5,
|
|
|
82
|
+ isCircle: true
|
|
|
83
|
+ });
|
|
|
84
|
+ }
|
|
|
85
|
+ }
|
|
|
86
|
+ });
|
|
|
87
|
+}
|
118
|
|
88
|
|
119
|
// 凑单商品翻页
|
89
|
// 凑单商品翻页
|
120
|
$togetherSlide.on('click', '.pagenext, .pageprev', function() {
|
90
|
$togetherSlide.on('click', '.pagenext, .pageprev', function() {
|
121
|
loadTogetherProduct(Math.ceil(Math.random() * 100) + 1);
|
91
|
loadTogetherProduct(Math.ceil(Math.random() * 100) + 1);
|
122
|
});
|
92
|
});
|
123
|
|
93
|
|
|
|
94
|
+$('.bottom-tab-slide .change').on('click', function(){
|
|
|
95
|
+
|
|
|
96
|
+ var pageNum = Number($fineSlide.data('pagenum') || 1);
|
|
|
97
|
+
|
|
|
98
|
+ if (pageNum !== 3) {
|
|
|
99
|
+ pageNum++;
|
|
|
100
|
+ } else {
|
|
|
101
|
+ pageNum = 1;
|
|
|
102
|
+ }
|
|
|
103
|
+
|
|
|
104
|
+ $fineSlide.data('pagenum', pageNum);
|
|
|
105
|
+ loadFineProduct(pageNum);
|
|
|
106
|
+});
|
|
|
107
|
+
|
124
|
// 为您优选翻页
|
108
|
// 为您优选翻页
|
125
|
-$fineSlide.on('click', '.pagenext, .pageprev', function() {
|
109
|
+/*$fineSlide.on('click', '.pagenext, .pageprev', function() {
|
126
|
|
110
|
|
127
|
var pageNum = Number($fineSlide.data('pagenum') || 1);
|
111
|
var pageNum = Number($fineSlide.data('pagenum') || 1);
|
128
|
|
112
|
|
|
@@ -138,4 +122,41 @@ $fineSlide.on('click', '.pagenext, .pageprev', function() { |
|
@@ -138,4 +122,41 @@ $fineSlide.on('click', '.pagenext, .pageprev', function() { |
138
|
|
122
|
|
139
|
$fineSlide.data('pagenum', pageNum);
|
123
|
$fineSlide.data('pagenum', pageNum);
|
140
|
loadFineProduct(pageNum);
|
124
|
loadFineProduct(pageNum);
|
|
|
125
|
+});*/
|
|
|
126
|
+
|
|
|
127
|
+// 推荐、优选、浏览切换
|
|
|
128
|
+$('.bottom-tab-slide').on('click', '.bottom-title', function() {
|
|
|
129
|
+ var $this = $(this),
|
|
|
130
|
+ $triggers = $('.bottom-tab-slide .bottom-title'),
|
|
|
131
|
+ index = $this.index(),
|
|
|
132
|
+ $panels = $('.bottom-slide-content .slide-panel'),
|
|
|
133
|
+ $curPanel = $panels.eq(index),
|
|
|
134
|
+ $chgBtn = $('.bottom-tab-slide .change');
|
|
|
135
|
+
|
|
|
136
|
+ $panels.hide();
|
|
|
137
|
+ $panels.eq(index).show();
|
|
|
138
|
+
|
|
|
139
|
+ if ($this.hasClass('cur')) {
|
|
|
140
|
+ return;
|
|
|
141
|
+ }
|
|
|
142
|
+
|
|
|
143
|
+ $triggers.removeClass('cur');
|
|
|
144
|
+ $this.addClass('cur');
|
|
|
145
|
+
|
|
|
146
|
+ if($this.data('type') === 'fine') {
|
|
|
147
|
+ $chgBtn.show();
|
|
|
148
|
+ } else {
|
|
|
149
|
+ $chgBtn.hide();
|
|
|
150
|
+ }
|
|
|
151
|
+
|
|
|
152
|
+ $panels.hide();
|
|
|
153
|
+ $curPanel.slideDown();
|
141
|
});
|
154
|
});
|
|
|
155
|
+
|
|
|
156
|
+
|
|
|
157
|
+window.loadTogetherProduct = loadTogetherProduct;
|
|
|
158
|
+window.loadFineProduct = loadFineProduct;
|
|
|
159
|
+window.fetchLatestWalk = fetchLatestWalk;
|
|
|
160
|
+
|
|
|
161
|
+// 数据懒加载
|
|
|
162
|
+dataLazyLoad.init({cls: '.lazy-load-object', threshold: 700}); |