cart.page.js
5.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/**
* 订单结算页
* @author: gxh<xuhui.ge@yoho.cn>
* @date: 2016/12/27
*/
var $ = require('yoho-jquery');
var lazyLoad = require('yoho-jquery-lazyload');
var Dialog = require('../common/dialog').Dialog;
var Alert = Dialog.Alert;
var $cartGoodsDetail = $('#goodsTogetherDetail'),
pacList = 0,
shopNum = 1,
promotionId,
shopNumAll;
// 优惠券 显示和隐藏
$('.sale-info').mouseenter(function() {
$(this).addClass('active').children('ul').removeClass('none');
}).mouseleave(function() {
$(this).removeClass('active').children('ul').addClass('none');
});
// 推荐、优选、浏览切换
$('.bottom-tab-slide').on('click', '.bottom-title', function() {
var $this = $(this),
index = $this.index();
console.log(index);
var $togetherGoods = $('.individual-item-togetherGoods'),
$latestWalk = $('.individual-item-latestWalk'),
$recommendGoods = $('.individual-item-recommendGoods');
if ($this.hasClass('cur')) {
return;
}
$this.addClass('cur');
$this.siblings('.cur').removeClass('cur');
switch (index) {
case 0: {
$togetherGoods.removeClass('none');
$recommendGoods.addClass('none');
$latestWalk.addClass('none');
break;
}
case 1: {
$togetherGoods.addClass('none');
$recommendGoods.removeClass('none');
$latestWalk.addClass('none');
break;
}
case 2: {
$togetherGoods.addClass('none');
$recommendGoods.addClass('none');
$latestWalk.removeClass('none');
break;
}
}
});
// 凑单图片懒加载
var togetherDialog = {};
var dialogTpl = require('hbs/cart/cart-togetherGoods.hbs');
lazyLoad($('#details-html img'));
$('.shop-cart').on('click', '.gift-sell .btn-clear', function() {
var tid = $(this).attr('data-together-id');
showTogetherGoods(tid);
});
// 凑单
function showTogetherGoods(id) {
if (!id) {
return;
}
var dialog = togetherDialog[id];
if (!dialog) {
dialog = new Dialog({
content: dialogTpl(),
className: 'cart-togetherGoods'
});
togetherDialog[id] = dialog;
}
dialog.show();
}
// 凑单弹框 详情切换
$('body').on('click', '.piclist li', function() {
console.log(99999);
pacList = $(this).index();
$('.detail-bigpic:not(.none) .piclist li').removeClass('active');
$(this).addClass('active');
$('.detail-bigpic:not(.none) .bigpic').hide().eq($(this).index()).show();
});
$('body').on('click', '.pre, .next', function() {
if ($(this).hasClass('next')) {
if (pacList >= $(this).siblings('.con').find('li').length - 1) {
return false;
}
pacList++;
} else {
if (pacList < 1) {
return false;
}
pacList--;
}
$(this).siblings('.con').find('li').removeClass('active').eq(pacList).addClass('active');
$('.detail-bigpic:not(.none) .bigpic').hide().eq(pacList).show();
});
$('body').on('click', '.color', function() {
pacList = 0;
$('.color').find('p').removeClass('active');
$(this).find('p').addClass('active');
$('.showSizeBox').addClass('none').eq($(this).index()).removeClass('none');
if ($('.showSizeBox:not(.none) span').length < 2) {
$('.showSizeBox:not(.none) span:first').addClass('active');
}
$('.detail-bigpic').addClass('none').eq($(this).index()).removeClass('none');
$('.detail-bigpic').eq($(this).index()).find('.bigpic').hide();
$('.detail-bigpic').eq($(this).index()).find('.bigpic:first').show();
$('.detail-bigpic').eq($(this).index()).find('.con li').removeClass('active');
$('.detail-bigpic').eq($(this).index()).find('.con li:first').addClass('active');
$('.showSizeBox').eq($(this).index()).find('span').each(function() {
if ($(this).hasClass('null-atcivec')) {
$('.addcart').addClass('none');
$('.btn_sellout').removeClass('none');
} else {
$('.addcart').removeClass('none');
$('.btn_sellout').addClass('none');
return false;
}
});
});
$('body').on('click', '.showSizeBox span', function() {
shopNumAll = $(this).data('num');
if ($(this).data('num') > 0) {
$('.showSizeBox:not(.none) span').removeClass('atcivec atcive').eq($(this).index()).addClass('active');
$('.addcart').removeClass('none');
$('.btn_sellout').addClass('none');
} else {
$('.showSizeBox:not(.none) span').removeClass('atcivec atcive').eq($(this).index()).addClass('active');
$('.addcart').addClass('none');
$('.btn_sellout').removeClass('none');
}
});
$('body').on('click', '.cut, .add', function() {
count = $(this).hasClass('minus') ? 'decreaseNum' : 'increaseNum';
if (promotionId) {
if ($(this).hasClass('cut')) {
new Alert('-_-,已经是最后一件,不能再减了!').show();
} else {
new Alert('最多只能购买一件,您好像购买的太多了!').show();
}
} else {
if ($(this).hasClass('add')) {
shopNum++;
} else {
shopNum--;
}
if (shopNum < 1) {
new Alert('-_-,已经是最后一件,不能在减了!').show();
shopNum = 1;
return false;
}
$('#num').val(shopNum);
}
});