|
@@ -11,7 +11,8 @@ var $ = require('jquery'); |
|
@@ -11,7 +11,8 @@ var $ = require('jquery'); |
11
|
|
11
|
|
12
|
// var $page = $('.yoho-page');
|
12
|
// var $page = $('.yoho-page');
|
13
|
|
13
|
|
14
|
-var $num;
|
14
|
+var $num,
|
|
|
15
|
+ $chosed;
|
15
|
|
16
|
|
16
|
// var tpl;
|
17
|
// var tpl;
|
17
|
|
18
|
|
|
@@ -64,41 +65,69 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { |
|
@@ -64,41 +65,69 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { |
64
|
var $this = $(this),
|
65
|
var $this = $(this),
|
65
|
$that = $(e.target).closest('.chose-items'),
|
66
|
$that = $(e.target).closest('.chose-items'),
|
66
|
numArray,
|
67
|
numArray,
|
67
|
- index;
|
68
|
+ index,
|
|
|
69
|
+ i;
|
|
|
70
|
+
|
|
|
71
|
+ var $siblingBlock = $this.closest('.block-list').siblings(':first'),
|
|
|
72
|
+ currentNumArray = $this.data('numstr').split('/');
|
68
|
|
73
|
|
69
|
- if ($this.hasClass('chosed')) {
|
|
|
70
|
- $this.parent().find('.block').removeClass('chosed');
|
|
|
71
|
- $that.find('.num .left-num').html('');
|
|
|
72
|
- } else if ($this.hasClass('disable')) {
|
|
|
73
|
- $this.css('background-color', '#000');
|
|
|
74
|
- return;
|
|
|
75
|
- } else if (!$this.hasClass('chosed')) {
|
|
|
76
|
$this.siblings('.chosed').removeClass('chosed');
|
74
|
$this.siblings('.chosed').removeClass('chosed');
|
77
|
- $this.addClass('chosed');
|
75
|
+ $this.toggleClass('chosed');
|
78
|
index = $this.index();
|
76
|
index = $this.index();
|
79
|
-
|
77
|
+ $chosed = $('.block-list>ul>li.chosed');
|
80
|
|
78
|
|
81
|
//根据颜色切换图片
|
79
|
//根据颜色切换图片
|
82
|
if ($this.closest('.block-list').hasClass('color-list')) {
|
80
|
if ($this.closest('.block-list').hasClass('color-list')) {
|
83
|
$('.chose-panel .basic-info').find('.thumb').addClass('hide').eq(index).removeClass('hide');
|
81
|
$('.chose-panel .basic-info').find('.thumb').addClass('hide').eq(index).removeClass('hide');
|
84
|
}
|
82
|
}
|
85
|
|
83
|
|
86
|
- //剩余的商品数
|
|
|
87
|
- if ($that.find('.color-list ul>li').hasClass('chosed') && $that.find('.size-list ul>li').hasClass('chosed')) {
|
|
|
88
|
- numArray = $this.closest('.block-list').siblings(':first').find('.chosed').data('numstr').split('/');
|
|
|
89
|
- $that.find('.num .left-num').html('剩余' + numArray[index] + '件');
|
|
|
90
|
- } else {
|
|
|
91
|
- $that.find('.num .left-num').html('');
|
84
|
+ if ($chosed.length === 0) {
|
|
|
85
|
+ $this.closest('ul>li').each(function() {
|
|
|
86
|
+ $(this).removeClass('zero-stock');
|
|
|
87
|
+ if (0 === $(this).data('num') - 0) {
|
|
|
88
|
+ $(this).addClass('zero-stock');
|
92
|
}
|
89
|
}
|
|
|
90
|
+ });
|
93
|
|
91
|
|
94
|
- //点击切换
|
92
|
+ $siblingBlock.find('ul>li').each(function() {
|
|
|
93
|
+ $(this).removeClass('zero-stock');
|
|
|
94
|
+ if (0 === $(this).data('num') - 0) {
|
|
|
95
|
+ $(this).addClass('zero-stock');
|
|
|
96
|
+ }
|
|
|
97
|
+ });
|
|
|
98
|
+ } else if ($chosed.length === 1 && $this.hasClass('chosed')) {
|
|
|
99
|
+ numArray = $chosed.data('numstr').split('/');
|
|
|
100
|
+ $siblingBlock.find('.block').removeClass('zero-stock');
|
|
|
101
|
+ for (i = 0; i < numArray.length; i++) {
|
|
|
102
|
+ if (0 === numArray[i] - 0) {
|
|
|
103
|
+ $siblingBlock.find('.block').eq(i).addClass('zero-stock');
|
|
|
104
|
+ }
|
|
|
105
|
+ }
|
|
|
106
|
+ } else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
|
|
|
107
|
+ $siblingBlock.find('ul>li').each(function() {
|
|
|
108
|
+ $(this).removeClass('zero-stock');
|
|
|
109
|
+ if (0 === $(this).data('num') - 0) {
|
|
|
110
|
+ $(this).addClass('zero-stock');
|
|
|
111
|
+ }
|
|
|
112
|
+ });
|
|
|
113
|
+ $that.find('.num .left-num').html('');
|
|
|
114
|
+ } else if ($chosed.length === 2) {
|
|
|
115
|
+ $siblingBlock.find('.block').removeClass('zero-stock');
|
|
|
116
|
+ for (i = 0; i < currentNumArray.length; i++) {
|
|
|
117
|
+ if (0 === currentNumArray[i] - 0) {
|
|
|
118
|
+ $siblingBlock.find('.block').eq(i).addClass('zero-stock');
|
|
|
119
|
+ }
|
|
|
120
|
+ }
|
|
|
121
|
+ numArray = $siblingBlock.find('.chosed').data('numstr').split('/');
|
|
|
122
|
+ $that.find('.num .left-num').html('剩余' + numArray[index] + '件');
|
95
|
}
|
123
|
}
|
96
|
|
124
|
|
97
|
}).on('touchstart', '.btn-minus', function() {
|
125
|
}).on('touchstart', '.btn-minus', function() {
|
98
|
- var num = +$num.val();
|
126
|
+ var num = +$num.val(),
|
|
|
127
|
+ $chosed = $('.block-list>ul>li.chosed');
|
99
|
|
128
|
|
100
|
//若颜色和尺码没有被同时选中,则不能点击
|
129
|
//若颜色和尺码没有被同时选中,则不能点击
|
101
|
- if ($('.block-list>ul>li.chosed').length < 2) {
|
130
|
+ if ($chosed.length < 2) {
|
102
|
return;
|
131
|
return;
|
103
|
}
|
132
|
}
|
104
|
|
133
|
|