|
@@ -10,56 +10,37 @@ |
|
@@ -10,56 +10,37 @@ |
10
|
// 异步渲染的模板统一插入 #chose-panel ,兼容页面多个选择框
|
10
|
// 异步渲染的模板统一插入 #chose-panel ,兼容页面多个选择框
|
11
|
|
11
|
|
12
|
var $ = require('jquery'),
|
12
|
var $ = require('jquery'),
|
13
|
- Handlebars = require('yoho.handlebars'),
|
|
|
14
|
tip = require('../plugin/tip'),
|
13
|
tip = require('../plugin/tip'),
|
15
|
loading = require('../plugin/loading');
|
14
|
loading = require('../plugin/loading');
|
16
|
|
15
|
|
17
|
-var panelTmpl,
|
|
|
18
|
- $chosePanel = $('#chose-panel'),
|
16
|
+var $chosePanel = $('#chose-panel'),
|
19
|
$num,
|
17
|
$num,
|
20
|
$chosed,
|
18
|
$chosed,
|
21
|
|
19
|
|
22
|
// re = /\d+/,
|
20
|
// re = /\d+/,
|
23
|
leftNum,
|
21
|
leftNum,
|
24
|
confirming,
|
22
|
confirming,
|
25
|
- hasChooseColor = false,
|
|
|
26
|
- hasChooseSize = false,
|
|
|
27
|
curColorIndex,
|
23
|
curColorIndex,
|
28
|
curSizeIndex,
|
24
|
curSizeIndex,
|
29
|
$curSizeRow,
|
25
|
$curSizeRow,
|
30
|
- $curSizeBlock = null,
|
|
|
31
|
- $sizeRowList = $('.size-list ul');
|
|
|
32
|
-
|
|
|
33
|
-// 读取模板
|
|
|
34
|
-$.get('/cart/index/giftinfoTpl', function(html) {
|
|
|
35
|
- if (!html) {
|
|
|
36
|
- tip.show('网络错误');
|
|
|
37
|
- return;
|
|
|
38
|
- }
|
|
|
39
|
- panelTmpl = Handlebars.compile(html);
|
|
|
40
|
-}).fail(function() {
|
|
|
41
|
- tip.show('网络错误');
|
|
|
42
|
-});
|
26
|
+ hasChooseColor,
|
|
|
27
|
+ hasChooseSize,
|
|
|
28
|
+ $curSizeBlock,
|
|
|
29
|
+ $sizeRowList;
|
43
|
|
30
|
|
44
|
//初始化购物车面板显示
|
31
|
//初始化购物车面板显示
|
45
|
function init() {
|
32
|
function init() {
|
|
|
33
|
+ var $firstRow;
|
46
|
|
34
|
|
47
|
- //$colorList = $('.chose-panel .color-list ul>li');
|
|
|
48
|
- //$sizeList = $('.chose-panel .size-list ul>li');
|
|
|
49
|
- //firstColorId = $colorList.eq(0).data('id');
|
|
|
50
|
- //$sizeList.each(function() {
|
|
|
51
|
- // colorIndex = $(this).data('colorid');
|
|
|
52
|
- //
|
|
|
53
|
- // if (colorIndex === firstColorId) {
|
|
|
54
|
- // $(this).removeClass('hide');
|
|
|
55
|
- // }
|
|
|
56
|
- //});
|
|
|
57
|
-
|
|
|
58
|
- var $firstRow = $sizeRowList.eq(0);
|
|
|
59
|
-
|
35
|
+ hasChooseColor = false;
|
|
|
36
|
+ hasChooseSize = false;
|
|
|
37
|
+ $curSizeBlock = null;
|
|
|
38
|
+ $sizeRowList = $('.size-list ul');
|
|
|
39
|
+ $firstRow = $sizeRowList.eq(0);
|
60
|
$firstRow.toggleClass('hide');
|
40
|
$firstRow.toggleClass('hide');
|
61
|
$curSizeRow = $firstRow;
|
41
|
$curSizeRow = $firstRow;
|
62
|
}
|
42
|
}
|
|
|
43
|
+init();
|
63
|
|
44
|
|
64
|
function checkColorSizeNum() {
|
45
|
function checkColorSizeNum() {
|
65
|
if (!hasChooseColor && !hasChooseSize) {
|
46
|
if (!hasChooseColor && !hasChooseSize) {
|
|
@@ -75,11 +56,9 @@ function checkColorSizeNum() { |
|
@@ -75,11 +56,9 @@ function checkColorSizeNum() { |
75
|
return true;
|
56
|
return true;
|
76
|
}
|
57
|
}
|
77
|
|
58
|
|
78
|
-init();
|
|
|
79
|
-
|
|
|
80
|
-function show(data) {
|
|
|
81
|
- if (data) {
|
|
|
82
|
- $chosePanel.html(panelTmpl(data));
|
59
|
+function show(html) {
|
|
|
60
|
+ if (html) {
|
|
|
61
|
+ $chosePanel.html(html);
|
83
|
init();
|
62
|
init();
|
84
|
}
|
63
|
}
|
85
|
$('.chose-panel').show();
|
64
|
$('.chose-panel').show();
|
|
@@ -88,20 +67,55 @@ function show(data) { |
|
@@ -88,20 +67,55 @@ function show(data) { |
88
|
$num = $('#good-num');
|
67
|
$num = $('#good-num');
|
89
|
}
|
68
|
}
|
90
|
|
69
|
|
91
|
-////显示当前Panel
|
|
|
92
|
-//function show() {
|
|
|
93
|
-// $('.chose-panel').show();
|
|
|
94
|
-//
|
|
|
95
|
-// $('body').css('overflow', 'hidden');
|
|
|
96
|
-// $num = $('#good-num');
|
|
|
97
|
-//}
|
|
|
98
|
-
|
|
|
99
|
//隐藏当前Panel
|
70
|
//隐藏当前Panel
|
100
|
function hide() {
|
71
|
function hide() {
|
101
|
$('.chose-panel').hide();
|
72
|
$('.chose-panel').hide();
|
102
|
$('body').css('overflow', 'auto');
|
73
|
$('body').css('overflow', 'auto');
|
103
|
}
|
74
|
}
|
104
|
|
75
|
|
|
|
76
|
+//修改加入购物车的文字和背景
|
|
|
77
|
+function updateConformButtonClassAndText() {
|
|
|
78
|
+ $chosed = $('.chose-items').find('.chosed');
|
|
|
79
|
+ if (2 === $chosed.closest('.zero-stock').length) {
|
|
|
80
|
+ $('#chose-btn-sure').css('background-color', '#c0c0c0');
|
|
|
81
|
+ $('#chose-btn-sure').html('已售罄');
|
|
|
82
|
+ } else {
|
|
|
83
|
+ $('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
84
|
+ $('#chose-btn-sure').html('确定');
|
|
|
85
|
+ }
|
|
|
86
|
+}
|
|
|
87
|
+
|
|
|
88
|
+//重置颜色块的库存为0的样式
|
|
|
89
|
+function resetColorZeroStock($siblingBlock) {
|
|
|
90
|
+ var numArray = ($curSizeBlock.data('numstr') + '').split('/'),
|
|
|
91
|
+ i;
|
|
|
92
|
+
|
|
|
93
|
+ if (!hasChooseSize) {
|
|
|
94
|
+ $siblingBlock.find('ul>li').each(function() {
|
|
|
95
|
+ $(this).removeClass('zero-stock');
|
|
|
96
|
+ if ('0' === $(this).data('num')) {
|
|
|
97
|
+ $(this).addClass('zero-stock');
|
|
|
98
|
+ }
|
|
|
99
|
+ });
|
|
|
100
|
+
|
|
|
101
|
+ } else {
|
|
|
102
|
+ for (i = 0; i < numArray.length; i++) {
|
|
|
103
|
+ if ('0' === numArray[i]) {
|
|
|
104
|
+ $siblingBlock.find('.block').eq(i).addClass('zero-stock');
|
|
|
105
|
+ }
|
|
|
106
|
+ }
|
|
|
107
|
+ }
|
|
|
108
|
+}
|
|
|
109
|
+
|
|
|
110
|
+// 选择了颜色切换商品图片
|
|
|
111
|
+function changeGoodImgWhenClickColor() {
|
|
|
112
|
+ if (hasChooseColor && curColorIndex) {
|
|
|
113
|
+ $('.chose-panel').find('.thumb').addClass('hide').eq(curColorIndex).removeClass('hide');
|
|
|
114
|
+ }
|
|
|
115
|
+}
|
|
|
116
|
+
|
|
|
117
|
+init();
|
|
|
118
|
+
|
105
|
$('.yoho-page').on('touchstart', '.chose-panel', function(e) {
|
119
|
$('.yoho-page').on('touchstart', '.chose-panel', function(e) {
|
106
|
var $cur = $(e.target);
|
120
|
var $cur = $(e.target);
|
107
|
|
121
|
|
|
@@ -143,11 +157,6 @@ $('.color-list').on('touchstart', '.block', function(e) { |
|
@@ -143,11 +157,6 @@ $('.color-list').on('touchstart', '.block', function(e) { |
143
|
} else {
|
157
|
} else {
|
144
|
hasChooseColor = true;
|
158
|
hasChooseColor = true;
|
145
|
|
159
|
|
146
|
- //根据颜色切换图片
|
|
|
147
|
- if ($this.closest('.block-list').hasClass('color-list')) {
|
|
|
148
|
- $('.chose-panel').find('.thumb').addClass('hide').eq(index).removeClass('hide');
|
|
|
149
|
- }
|
|
|
150
|
-
|
|
|
151
|
//把当前选中颜色对应的尺码那一行显示出来
|
160
|
//把当前选中颜色对应的尺码那一行显示出来
|
152
|
$sizeRowList.addClass('hide');
|
161
|
$sizeRowList.addClass('hide');
|
153
|
$curSizeRow.removeClass('hide').addClass('show');
|
162
|
$curSizeRow.removeClass('hide').addClass('show');
|
|
@@ -180,91 +189,22 @@ $('.color-list').on('touchstart', '.block', function(e) { |
|
@@ -180,91 +189,22 @@ $('.color-list').on('touchstart', '.block', function(e) { |
180
|
curColorIndex = index;
|
189
|
curColorIndex = index;
|
181
|
|
190
|
|
182
|
// 设置按钮的样式和文字
|
191
|
// 设置按钮的样式和文字
|
183
|
- $chosed = $('.chose-items').find('.chosed');
|
|
|
184
|
- if (2 === $chosed.closest('.zero-stock').length) {
|
|
|
185
|
- $('#chose-btn-sure').css('background-color', '#c0c0c0');
|
|
|
186
|
- $('#chose-btn-sure').html('已售罄');
|
|
|
187
|
- } else {
|
|
|
188
|
- $('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
189
|
- $('#chose-btn-sure').html('确定');
|
|
|
190
|
- }
|
|
|
191
|
-
|
|
|
192
|
- /**if ($chosed.length === 0) {
|
|
|
193
|
- $this.closest('ul>li').each(function() {
|
|
|
194
|
- $(this).removeClass('zero-stock');
|
|
|
195
|
- if ('0' === $(this).data('num')) {
|
|
|
196
|
- $(this).addClass('zero-stock');
|
|
|
197
|
- }
|
|
|
198
|
- });
|
|
|
199
|
-
|
|
|
200
|
- $siblingBlock.find('ul>li').each(function() {
|
|
|
201
|
- $(this).removeClass('zero-stock');
|
|
|
202
|
- if ('0' === $(this).data('num')) {
|
|
|
203
|
- $(this).addClass('zero-stock');
|
|
|
204
|
- }
|
|
|
205
|
- });
|
|
|
206
|
- } else if ($chosed.length === 1 && $this.hasClass('chosed')) {
|
|
|
207
|
- $sizeList.addClass('hide');
|
|
|
208
|
-
|
|
|
209
|
- //切换尺码信息
|
|
|
210
|
- $sizeList.each(function() {
|
|
|
211
|
- colorIndex = $(this).data('colorid');
|
|
|
212
|
- if (colorIndex === $this.data('id')) {
|
|
|
213
|
- $(this).removeClass('hide');
|
|
|
214
|
- }
|
|
|
215
|
- });
|
|
|
216
|
-
|
|
|
217
|
- numArray = ($chosed.data('numstr') + '').split('/');
|
|
|
218
|
- $siblingBlock.find('.block').removeClass('zero-stock');
|
|
|
219
|
- for (i = 0; i < numArray.length; i++) {
|
|
|
220
|
- if ('0' === numArray[i]) {
|
|
|
221
|
- $siblingBlock.find('.block').eq(i).addClass('zero-stock');
|
|
|
222
|
- }
|
|
|
223
|
- }
|
|
|
224
|
- } else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
|
|
|
225
|
- $('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
226
|
- $('#chose-btn-sure').html('确定');
|
|
|
227
|
-
|
|
|
228
|
- $siblingBlock.find('ul>li').each(function() {
|
|
|
229
|
- $(this).removeClass('zero-stock');
|
|
|
230
|
- if ('0' === $(this).data('num')) {
|
|
|
231
|
- $(this).addClass('zero-stock');
|
|
|
232
|
- }
|
|
|
233
|
- });
|
|
|
234
|
- $that.find('.num .left-num').html('');
|
|
|
235
|
- } else if ($chosed.length === 2) {
|
|
|
236
|
- $siblingBlock.find('.block').removeClass('zero-stock');
|
|
|
237
|
- for (i = 0; i < currentNumArray.length; i++) {
|
|
|
238
|
- if ('0' === currentNumArray[i]) {
|
|
|
239
|
- $siblingBlock.find('.block').eq(i).addClass('zero-stock');
|
|
|
240
|
- }
|
|
|
241
|
- }
|
|
|
242
|
- numArray = ($siblingBlock.find('.chosed').data('numstr') + '').split('/');
|
|
|
243
|
- $that.find('.num .left-num').html('剩余' + numArray[index] + '件');
|
|
|
244
|
- if (2 === $chosed.closest('.zero-stock').length) {
|
|
|
245
|
- $('#chose-btn-sure').css('background-color', '#c0c0c0');
|
|
|
246
|
- $('#chose-btn-sure').html('已售罄');
|
|
|
247
|
- } else {
|
|
|
248
|
- $('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
249
|
- $('#chose-btn-sure').html('确定');
|
|
|
250
|
- }
|
|
|
251
|
- }**/
|
192
|
+ updateConformButtonClassAndText();
|
252
|
|
193
|
|
|
|
194
|
+ // 修改颜色时修改商品图片
|
|
|
195
|
+ changeGoodImgWhenClickColor();
|
253
|
});
|
196
|
});
|
254
|
|
197
|
|
255
|
$('.size-list').on('touchstart', '.block', function(e) {
|
198
|
$('.size-list').on('touchstart', '.block', function(e) {
|
256
|
var $this = $(this),
|
199
|
var $this = $(this),
|
257
|
$that = $(e.target).closest('.chose-items'),
|
200
|
$that = $(e.target).closest('.chose-items'),
|
258
|
index,
|
201
|
index,
|
259
|
- $colorChosed,
|
|
|
260
|
curGoodNum;
|
202
|
curGoodNum;
|
261
|
|
203
|
|
262
|
var $siblingBlock = $this.closest('.block-list').siblings(':first');
|
204
|
var $siblingBlock = $this.closest('.block-list').siblings(':first');
|
263
|
|
205
|
|
264
|
$this.siblings('.chosed').removeClass('chosed');
|
206
|
$this.siblings('.chosed').removeClass('chosed');
|
265
|
index = $this.index();
|
207
|
index = $this.index();
|
266
|
-
|
|
|
267
|
- $colorChosed = $siblingBlock.find('.chosed');
|
|
|
268
|
$curSizeRow = $sizeRowList.eq(index);
|
208
|
$curSizeRow = $sizeRowList.eq(index);
|
269
|
|
209
|
|
270
|
// 当前尺码已经是选中状态,再点击时
|
210
|
// 当前尺码已经是选中状态,再点击时
|
|
@@ -275,11 +215,6 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
@@ -275,11 +215,6 @@ $('.size-list').on('touchstart', '.block', function(e) { |
275
|
$('#left-num').val(0);
|
215
|
$('#left-num').val(0);
|
276
|
hasChooseSize = false;
|
216
|
hasChooseSize = false;
|
277
|
|
217
|
|
278
|
- // 去掉已经选中颜色的 数量为0的样式
|
|
|
279
|
- if ($colorChosed.length > 0) {
|
|
|
280
|
- $colorChosed.removeClass('zero-stock').addClass('zero-stock');
|
|
|
281
|
- }
|
|
|
282
|
-
|
|
|
283
|
// 当前尺码不是选中状态,选中时
|
218
|
// 当前尺码不是选中状态,选中时
|
284
|
} else {
|
219
|
} else {
|
285
|
hasChooseSize = true;
|
220
|
hasChooseSize = true;
|
|
@@ -296,10 +231,10 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
@@ -296,10 +231,10 @@ $('.size-list').on('touchstart', '.block', function(e) { |
296
|
$that.find('.num .left-num').html('剩余' + curGoodNum + '件');
|
231
|
$that.find('.num .left-num').html('剩余' + curGoodNum + '件');
|
297
|
$('#left-num').val(curGoodNum);
|
232
|
$('#left-num').val(curGoodNum);
|
298
|
} else {
|
233
|
} else {
|
299
|
- $colorChosed.removeClass('zero-stock').addClass('zero-stock');
|
|
|
300
|
$that.find('.num .left-num').html('');
|
234
|
$that.find('.num .left-num').html('');
|
301
|
$('#left-num').val(0);
|
235
|
$('#left-num').val(0);
|
302
|
}
|
236
|
}
|
|
|
237
|
+
|
303
|
}
|
238
|
}
|
304
|
|
239
|
|
305
|
$this.toggleClass('chosed');
|
240
|
$this.toggleClass('chosed');
|
|
@@ -307,78 +242,10 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
@@ -307,78 +242,10 @@ $('.size-list').on('touchstart', '.block', function(e) { |
307
|
$curSizeBlock = $this;
|
242
|
$curSizeBlock = $this;
|
308
|
|
243
|
|
309
|
// 设置按钮的样式和文字
|
244
|
// 设置按钮的样式和文字
|
310
|
- $chosed = $('.chose-items').find('.chosed');
|
|
|
311
|
- if (2 === $chosed.closest('.zero-stock').length) {
|
|
|
312
|
- $('#chose-btn-sure').css('background-color', '#c0c0c0');
|
|
|
313
|
- $('#chose-btn-sure').html('已售罄');
|
|
|
314
|
- } else {
|
|
|
315
|
- $('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
316
|
- $('#chose-btn-sure').html('确定');
|
|
|
317
|
- }
|
|
|
318
|
-
|
|
|
319
|
- /**if ($chosed.length === 0) {
|
|
|
320
|
- $this.closest('ul>li').each(function() {
|
|
|
321
|
- $(this).removeClass('zero-stock');
|
|
|
322
|
- if ('0' === $(this).data('num')) {
|
|
|
323
|
- $(this).addClass('zero-stock');
|
|
|
324
|
- }
|
|
|
325
|
- });
|
|
|
326
|
-
|
|
|
327
|
- $siblingBlock.find('ul>li').each(function() {
|
|
|
328
|
- $(this).removeClass('zero-stock');
|
|
|
329
|
- if ('0' === $(this).data('num')) {
|
|
|
330
|
- $(this).addClass('zero-stock');
|
|
|
331
|
- }
|
|
|
332
|
- });
|
|
|
333
|
- } else if ($chosed.length === 1 && $this.hasClass('chosed')) {
|
|
|
334
|
- if ($this.closest('.block-list').hasClass('color-list')) {
|
|
|
335
|
-
|
|
|
336
|
- $sizeList.addClass('hide');
|
|
|
337
|
-
|
|
|
338
|
- //切换尺码信息
|
|
|
339
|
- $sizeList.each(function() {
|
|
|
340
|
- colorIndex = $(this).data('colorid');
|
|
|
341
|
- if (colorIndex === $this.data('id')) {
|
|
|
342
|
- $(this).removeClass('hide');
|
|
|
343
|
- }
|
|
|
344
|
- });
|
|
|
345
|
- }
|
|
|
346
|
-
|
|
|
347
|
- numArray = ($chosed.data('numstr') + '').split('/');
|
|
|
348
|
- $siblingBlock.find('.block').removeClass('zero-stock');
|
|
|
349
|
- for (i = 0; i < numArray.length; i++) {
|
|
|
350
|
- if ('0' === numArray[i]) {
|
|
|
351
|
- $siblingBlock.find('.block').eq(i).addClass('zero-stock');
|
|
|
352
|
- }
|
|
|
353
|
- }
|
|
|
354
|
- } else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
|
|
|
355
|
- $('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
356
|
- $('#chose-btn-sure').html('确定');
|
245
|
+ updateConformButtonClassAndText();
|
357
|
|
246
|
|
358
|
- $siblingBlock.find('ul>li').each(function() {
|
|
|
359
|
- $(this).removeClass('zero-stock');
|
|
|
360
|
- if ('0' === $(this).data('num')) {
|
|
|
361
|
- $(this).addClass('zero-stock');
|
|
|
362
|
- }
|
|
|
363
|
- });
|
|
|
364
|
- $that.find('.num .left-num').html('');
|
|
|
365
|
- } else if ($chosed.length === 2) {
|
|
|
366
|
- $siblingBlock.find('.block').removeClass('zero-stock');
|
|
|
367
|
- for (i = 0; i < currentNumArray.length; i++) {
|
|
|
368
|
- if ('0' === currentNumArray[i]) {
|
|
|
369
|
- $siblingBlock.find('.block').eq(i).addClass('zero-stock');
|
|
|
370
|
- }
|
|
|
371
|
- }
|
|
|
372
|
- numArray = ($siblingBlock.find('.chosed').data('numstr') + '').split('/');
|
|
|
373
|
- $that.find('.num .left-num').html('剩余' + numArray[index] + '件');
|
|
|
374
|
- if (2 === $chosed.closest('.zero-stock').length) {
|
|
|
375
|
- $('#chose-btn-sure').css('background-color', '#c0c0c0');
|
|
|
376
|
- $('#chose-btn-sure').html('已售罄');
|
|
|
377
|
- } else {
|
|
|
378
|
- $('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
379
|
- $('#chose-btn-sure').html('确定');
|
|
|
380
|
- }
|
|
|
381
|
- }**/
|
247
|
+ // 重置颜色块的样式
|
|
|
248
|
+ resetColorZeroStock($siblingBlock);
|
382
|
|
249
|
|
383
|
});
|
250
|
});
|
384
|
|
251
|
|
|
@@ -426,6 +293,7 @@ $('#chose-btn-sure').on('touchstart', function() { |
|
@@ -426,6 +293,7 @@ $('#chose-btn-sure').on('touchstart', function() { |
426
|
numInCart = $('.num-tag').html() - 0,
|
293
|
numInCart = $('.num-tag').html() - 0,
|
427
|
num = $num.val();
|
294
|
num = $num.val();
|
428
|
|
295
|
|
|
|
296
|
+ //颜色尺码没有选择
|
429
|
if (!checkColorSizeNum()) {
|
297
|
if (!checkColorSizeNum()) {
|
430
|
return;
|
298
|
return;
|
431
|
}
|
299
|
}
|