cart-together.js
3.37 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* Created by yoho on 2017-01-13.
*/
var capi = require('./cart-api');
var togetherTpl = require('hbs/cart/cart-together-item.hbs');
var $togetherSlide = $('[data-role=together-slide]');
var $fineSlide = $('[data-role=fine-slide]');
// 推荐、优选、浏览切换
$(function() {
var $togetherGoods = $('.individual-item-togetherGoods'),
$recommendGoods = $('.individual-item-recommendGoods'),
$latestWalk = $('.individual-item-latestWalk');
if ($togetherGoods.hasClass('none')) {
$recommendGoods.show();
}
$('.bottom-tab-slide').on('click', '.bottom-title', function() {
var $this = $(this),
index = $this.index();
console.log(index);
$togetherGoods.hide();
$recommendGoods.hide();
if ($this.hasClass('change')) {
return;
}
if ($this.hasClass('cur')) {
return;
}
$this.addClass('cur');
$this.siblings('.cur').removeClass('cur');
switch (index) {
case 0: {
$togetherGoods.slideDown();
$recommendGoods.hide();
$latestWalk.hide();
break;
}
case 1: {
$togetherGoods.hide();
$recommendGoods.slideDown();
$latestWalk.hide();
break;
}
case 2: {
$togetherGoods.hide();
$recommendGoods.hide();
$latestWalk.slideDown();
break;
}
}
});
});
// 凑单 底部 轮播
function loadSlideGoods() {
$.ajax({
type: 'GET',
url: '',
data: {
// skn: skn,
size: 20,
num: 1
}
}).then(function(data) {
// var pro = data.data.products;
// if (data.code === 200) {
// if (pro.length === 0) {
// return;
// }
$('#recommend-shop').removeClass('none');
$('.individual-item ').slider2({
shownum: 5,
isCircle: true
});
// } else {
// $('.bottom-title').filter('.change').addClass('none');
// }
});
}
loadSlideGoods();
function loadTogetherProduct(page) {
capi.getTogetherProduct(page).done(function(togetherInfo) {
if (togetherInfo && togetherInfo.code === 200) {
$togetherSlide.html(togetherTpl(togetherInfo.data));
}
});/* .fail(function() {
});*/
}
function loadFineProduct(page) {
capi.getFineProduct(page).done(function(fineInfo) {
if (fineInfo && fineInfo.code === 200) {
$fineSlide.html(togetherTpl(fineInfo.data));
}
});/* .fail(function() {
});*/
}
setTimeout(function() {
loadTogetherProduct(1);
loadFineProduct(1);
}, 0);
// 凑单商品翻页
$togetherSlide.on('click', '.pagenext, .pageprev', function() {
loadTogetherProduct(Math.ceil(Math.random() * 100) + 1);
});
// 为您优选翻页
$fineSlide.on('click', '.pagenext, .pageprev', function() {
var pageNum = Number($fineSlide.data('pagenum') || 1);
if ($(this).hasClass('pagenext')) {
if (pageNum !== 5) {
pageNum++;
} else {
pageNum = 1;
}
} else {
--pageNum > 0 || (pageNum = 1);
}
$fineSlide.data('pagenum', pageNum);
loadFineProduct(pageNum);
});