cart.page.js
7.15 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/**
* 订单结算页
* @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'),
$goodsChoose = $('#goodsChoose'),
$goodsItem = $('.cart-table li'),
pacList = 0,
shopNum = 1,
productId,
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);
}
});
// 凑单弹框 商品信息弹出框,加入收藏夹
$cartGoodsDetail.on('click', '.btn-favCount', function() {
$.ajax({
type: 'POST',
dataType: 'json',
url: '',
data: {
productId: productId,
type: 'add'
}
}).then(function(d) {
if (d.code === 200) {
new Alert(d.message).show();
} else if (d.code === 403) {
if (d.data.url) {
window.location = d.data.url;
}
} else {
new Alert(d.message).show();
}
});
});
// 购物车列表 显示隐藏
$goodsItem.on('click', '.pay-pro-info span', function() {
$('.pay-pro-info').find('span').removeClass('active');
$(this).addClass('active');
$('.goods-choose-box').addClass('none');
$(this).parents('li').children('.goods-choose-box').removeClass('none');
});
// 购物车列表 修改 颜色
$goodsChoose.on('click', '.choose-color .dt', function() {
pacList = $(this).index();
$('.choose-color').find('.dt').removeClass('active');
$(this).addClass('active');
$('.bigImg').addClass('none').eq($(this).index()).removeClass('none');
});
var giftBtn = '[data-role=gift-view-btn],[data-role=gift-resel-btn],[data-role=gift-sel-btn]';
$('.shop-cart').on('click', giftBtn, function() {
var mtext = $(this).closest('[data-role=promotion-wrap]').find('textarea[data-role=gifts-cansel]').text();
var mhtml = $(this).closest('[data-role=promotion-wrap]').find('textarea[data-role=gifts-cansel]').html();
console.log(mtext);
console.log(mhtml);
var textJson = $.parseJSON(mtext);
var htmlJson = $.parseJSON(mhtml);
console.log(textJson);
console.log(htmlJson);
});