|
@@ -12,7 +12,25 @@ var $ = require('jquery'); |
|
@@ -12,7 +12,25 @@ var $ = require('jquery'); |
12
|
// var $page = $('.yoho-page');
|
12
|
// var $page = $('.yoho-page');
|
13
|
|
13
|
|
14
|
var $num,
|
14
|
var $num,
|
15
|
- $chosed;
|
15
|
+ $chosed,
|
|
|
16
|
+ re = /\d+/,
|
|
|
17
|
+ leftNum,
|
|
|
18
|
+ $colorList = $('.color-list ul>li'),
|
|
|
19
|
+ $sizeList = $('.size-list ul>li'),
|
|
|
20
|
+ firstColorId = $colorList.eq(0).data('id'),
|
|
|
21
|
+ colorIndex;
|
|
|
22
|
+
|
|
|
23
|
+//初始化购物车面板显示
|
|
|
24
|
+$sizeList.each(function() {
|
|
|
25
|
+ colorIndex = $(this).data('colorid');
|
|
|
26
|
+
|
|
|
27
|
+
|
|
|
28
|
+ if (colorIndex === firstColorId) {
|
|
|
29
|
+ $(this).removeClass('hide');
|
|
|
30
|
+ }
|
|
|
31
|
+});
|
|
|
32
|
+
|
|
|
33
|
+// confirm;
|
16
|
|
34
|
|
17
|
// var tpl;
|
35
|
// var tpl;
|
18
|
|
36
|
|
|
@@ -35,8 +53,11 @@ var $num, |
|
@@ -35,8 +53,11 @@ var $num, |
35
|
// $num = $('#good-num');
|
53
|
// $num = $('#good-num');
|
36
|
// }
|
54
|
// }
|
37
|
|
55
|
|
|
|
56
|
+
|
|
|
57
|
+
|
38
|
function show() {
|
58
|
function show() {
|
39
|
$('.chose-panel').show();
|
59
|
$('.chose-panel').show();
|
|
|
60
|
+
|
40
|
$('body').css('overflow', 'hidden');
|
61
|
$('body').css('overflow', 'hidden');
|
41
|
$num = $('#good-num');
|
62
|
$num = $('#good-num');
|
42
|
}
|
63
|
}
|
|
@@ -58,10 +79,43 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { |
|
@@ -58,10 +79,43 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { |
58
|
remove();
|
79
|
remove();
|
59
|
}).on('touchstart', '#chose-btn-sure', function() {
|
80
|
}).on('touchstart', '#chose-btn-sure', function() {
|
60
|
|
81
|
|
61
|
- //确定
|
|
|
62
|
-}).on('touchstart', '.block', function(e) {
|
82
|
+ // var productSku,
|
|
|
83
|
+ // buyNumber = $('#good-num') - 0;
|
|
|
84
|
+ // promotionId,
|
|
|
85
|
+ // goodsType,
|
|
|
86
|
+ // isEdit;
|
|
|
87
|
+
|
|
|
88
|
+ // //确定
|
|
|
89
|
+ // $chosed = $('.block-list>ul>li.chosed');
|
|
|
90
|
+
|
|
|
91
|
+ // if (2 === $chosed.length && 2 !== $chosed.closest('.zero-stock').length) {
|
|
|
92
|
+
|
|
|
93
|
+ // if (confirm) {
|
|
|
94
|
+ // return false;
|
|
|
95
|
+ // }
|
|
|
96
|
+
|
|
|
97
|
+ // confirm = true;
|
|
|
98
|
+ // loading.showLoadingMask();
|
|
|
99
|
+ // $.ajax({
|
|
|
100
|
+ // method: 'POST',
|
|
|
101
|
+ // url: '/cart/index/add',
|
|
|
102
|
+ // data: {
|
|
|
103
|
+ // product_id: productId,
|
|
|
104
|
+ // content: content
|
|
|
105
|
+ // }
|
|
|
106
|
+ // }).done(function(res) {
|
|
|
107
|
+ // if (res.code === 200) {
|
|
|
108
|
+ // loading.hideLoadingMask();
|
|
|
109
|
+ // confirm = false;
|
|
|
110
|
+ // remove();
|
|
|
111
|
+ // }
|
|
|
112
|
+ // }).fail(function() {
|
|
|
113
|
+ // tip.show('网络出了点问题~');
|
|
|
114
|
+ // confirm = false;
|
|
|
115
|
+ // });
|
|
|
116
|
+ // }
|
63
|
|
117
|
|
64
|
- //尺寸颜色点选
|
118
|
+}).on('touchstart', '.block', function(e) {
|
65
|
var $this = $(this),
|
119
|
var $this = $(this),
|
66
|
$that = $(e.target).closest('.chose-items'),
|
120
|
$that = $(e.target).closest('.chose-items'),
|
67
|
numArray,
|
121
|
numArray,
|
|
@@ -96,6 +150,19 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { |
|
@@ -96,6 +150,19 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { |
96
|
}
|
150
|
}
|
97
|
});
|
151
|
});
|
98
|
} else if ($chosed.length === 1 && $this.hasClass('chosed')) {
|
152
|
} else if ($chosed.length === 1 && $this.hasClass('chosed')) {
|
|
|
153
|
+ if ($this.closest('.block-list').hasClass('color-list')) {
|
|
|
154
|
+
|
|
|
155
|
+ $sizeList.addClass('hide');
|
|
|
156
|
+
|
|
|
157
|
+ //切换尺码信息
|
|
|
158
|
+ $sizeList.each(function() {
|
|
|
159
|
+ colorIndex = $(this).data('colorid');
|
|
|
160
|
+ if (colorIndex === $this.data('id')) {
|
|
|
161
|
+ $(this).removeClass('hide');
|
|
|
162
|
+ }
|
|
|
163
|
+ });
|
|
|
164
|
+ }
|
|
|
165
|
+
|
99
|
numArray = $chosed.data('numstr').split('/');
|
166
|
numArray = $chosed.data('numstr').split('/');
|
100
|
$siblingBlock.find('.block').removeClass('zero-stock');
|
167
|
$siblingBlock.find('.block').removeClass('zero-stock');
|
101
|
for (i = 0; i < numArray.length; i++) {
|
168
|
for (i = 0; i < numArray.length; i++) {
|
|
@@ -104,6 +171,9 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { |
|
@@ -104,6 +171,9 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { |
104
|
}
|
171
|
}
|
105
|
}
|
172
|
}
|
106
|
} else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
|
173
|
} else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
|
|
|
174
|
+ $('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
175
|
+ $('#chose-btn-sure').html('确定');
|
|
|
176
|
+
|
107
|
$siblingBlock.find('ul>li').each(function() {
|
177
|
$siblingBlock.find('ul>li').each(function() {
|
108
|
$(this).removeClass('zero-stock');
|
178
|
$(this).removeClass('zero-stock');
|
109
|
if (0 === $(this).data('num') - 0) {
|
179
|
if (0 === $(this).data('num') - 0) {
|
|
@@ -123,19 +193,23 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { |
|
@@ -123,19 +193,23 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { |
123
|
if (2 === $chosed.closest('.zero-stock').length) {
|
193
|
if (2 === $chosed.closest('.zero-stock').length) {
|
124
|
$('#chose-btn-sure').css('background-color', '#c0c0c0');
|
194
|
$('#chose-btn-sure').css('background-color', '#c0c0c0');
|
125
|
$('#chose-btn-sure').html('已售罄');
|
195
|
$('#chose-btn-sure').html('已售罄');
|
|
|
196
|
+ } else {
|
|
|
197
|
+ $('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
198
|
+ $('#chose-btn-sure').html('确定');
|
126
|
}
|
199
|
}
|
127
|
}
|
200
|
}
|
128
|
|
201
|
|
129
|
}).on('touchstart', '.btn-minus', function() {
|
202
|
}).on('touchstart', '.btn-minus', function() {
|
130
|
var num = +$num.val(),
|
203
|
var num = +$num.val(),
|
131
|
- $chosed = $('.block-list>ul>li.chosed');
|
204
|
+ $chosed = $('.block-list>ul>li.chosed'),
|
|
|
205
|
+ leftNum = re.exec($('.num .left-num').html());
|
132
|
|
206
|
|
133
|
//若颜色和尺码没有被同时选中,则不能点击
|
207
|
//若颜色和尺码没有被同时选中,则不能点击
|
134
|
if ($chosed.length < 2) {
|
208
|
if ($chosed.length < 2) {
|
135
|
return;
|
209
|
return;
|
136
|
}
|
210
|
}
|
137
|
|
211
|
|
138
|
- if (num === 0) {
|
212
|
+ if (num === 1 || 0 === leftNum - 0) {
|
139
|
return;
|
213
|
return;
|
140
|
}
|
214
|
}
|
141
|
|
215
|
|
|
@@ -147,6 +221,10 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { |
|
@@ -147,6 +221,10 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { |
147
|
if ($('.block-list>ul>li.chosed').length < 2) {
|
221
|
if ($('.block-list>ul>li.chosed').length < 2) {
|
148
|
return;
|
222
|
return;
|
149
|
}
|
223
|
}
|
|
|
224
|
+ leftNum = re.exec($('.num .left-num').html());
|
|
|
225
|
+ if (num - 0 === leftNum - 0 || 0 === leftNum - 0) {
|
|
|
226
|
+ return;
|
|
|
227
|
+ }
|
150
|
|
228
|
|
151
|
//TODO:库存数验证
|
229
|
//TODO:库存数验证
|
152
|
$num.val(num + 1);
|
230
|
$num.val(num + 1);
|