cart.page_bak.js
7.65 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/**
* 订单结算页
* @author: gxh<xuhui.ge@yoho.cn>
* @date: 2016/12/27
*/
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload'),
dialog = require('../common/dialog'),
rDialog = require('./rdialog');
require('../plugins/slider');
require('../common/center-slider');
require('../common');
var Dialog = dialog.Dialog,
// Confirm = dialog.Confirm,
Alert = dialog.Alert,
RConfirm = rDialog.RConfirm,
RAlert = rDialog.RAlert;
var $cartGoodsDetail = $('#goodsTogetherDetail'),
$paySum = $('#pay-sum'),
shopNum = 1,
productId,
promotionId,
understock,
$sellBox = $('.cart-table .pre-sell-box');
// 优惠券 显示和隐藏
$('.sale-info').mouseenter(function() {
$(this).addClass('active').children('ul').removeClass('none');
}).mouseleave(function() {
$(this).removeClass('active').children('ul').addClass('none');
});
$('.side-img-dd').slider2({
shownum: 5,
isCircle: true
});
// var dialogTpl = require('hbs/cart/cart-togetherGoods.hbs');
lazyLoad($('#details-html img'));
// ----------------底部 为你优选,最近浏览 begin--------------
// 推荐、优选、浏览切换
$(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() {
$('.bottom-tab .change').click(function() {
$('.img-brand-switch .next').trigger('click');
});
// 判断商品是否已收藏,是否全选
function isCheckFav() {
var pidArray = [],
isAllCheck = true;
$sellBox.each(function() {
var $checkItem = $(this).find('.cart-item-check');
// 有一个没选中,跳出循环
if (!$checkItem.hasClass('cart-item-checked')) {
isAllCheck = false;
return false;
}
});
if (isAllCheck) {
// 头部全选
$('.cart-title .cart-item-check').addClass('cart-item-checked');
// 底部全选
$('#cbSelAllGoods').addClass('cart-item-checked');
}
$sellBox.each(function() {
pidArray.push($(this).data('pid'));
});
$.ajax({
type: 'POST',
url: '/cart/index/checkFav',
data: {
pidList: pidArray.join(',')
}
}).then(function(result) {
$.each(result.data, function(pid, obj) {
if (obj.code !== 200) {
return false;
}
if (obj.data) {
$sellBox.each(function() {
if (String($(this).data('pid')) === String(pid)) {
$(this).find('.cart-col-btn').addClass('has-col-btn').html('已收藏');
return false;
}
});
}
});
});
}
isCheckFav();
});
$('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();
}
});
});
// 结算
$paySum.on('click', '.btn-account', function() {
// 结算
understock = '';
// if ($('.pay-wapper .cart-item-checked').parents('.tr').find('.tipNoStore').length > 0) {
// shopName = $('.pay-wapper .cart-item-checked').parents('.tr').find('.tipNoStore');
// $.each(shopName.parents('.tr').find('.pay-pro-info a'), function() {
// understock += $(this).html();
// });
// new Alert(understock + '库存不足').show();
// } else {
// if ($('.zp').length > 0 && !$(this).attr('title')) {
// $(this).attr('title', '1');
// new Confirm({
// className: 'shopCart-del-dialog',
// content: '<h4><i class="iconfont"></i>您还未选择赠品</h4>' +
// '<small>是否去选择赠品?</small>',
// }).show();
// } else {
// if ($('input:checked').length > 0) {
//
// if ($('.pre-sell-box .cart-item-checked').length > 0) {
// window.location.href = '/cart/index/orderEnsure?type=2';
// } else {
// window.location.href = '/cart/index/orderEnsure?type=1';
// }
// } else {
// new Alert('请至少选择一件商品').show();
// }
// }
// }
$('.cart-preSell-dialog').show();
// $('.togethor').show();
$('.cart-togetherGoods').show();
});
$('.shop-cart').on('click', '[data-role="cart-gift-win"] .close', function() {
$(this).closest('[data-role="cart-gift-win"]').hide();
});
require('./cart-action');
require('./cart-color-panel');
require('./cart-goods-win');