|
@@ -10,53 +10,42 @@ |
|
@@ -10,53 +10,42 @@ |
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,
|
|
|
19
|
+ $imgsThumb,
|
21
|
|
20
|
|
22
|
// re = /\d+/,
|
21
|
// re = /\d+/,
|
|
|
22
|
+
|
|
|
23
|
+ $leftNum,
|
23
|
leftNum,
|
24
|
leftNum,
|
24
|
confirming,
|
25
|
confirming,
|
25
|
- hasChooseColor = false,
|
|
|
26
|
- hasChooseSize = false,
|
|
|
27
|
curColorIndex,
|
26
|
curColorIndex,
|
28
|
curSizeIndex,
|
27
|
curSizeIndex,
|
29
|
$curSizeRow,
|
28
|
$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
|
-});
|
29
|
+ hasChooseColor,
|
|
|
30
|
+ hasChooseSize,
|
|
|
31
|
+ $curSizeBlock,
|
|
|
32
|
+ $sizeRowList,
|
|
|
33
|
+ cbFn,
|
|
|
34
|
+ $allChoseItems,
|
|
|
35
|
+ $yohoPage = $('.yoho-page');
|
43
|
|
36
|
|
44
|
//初始化购物车面板显示
|
37
|
//初始化购物车面板显示
|
45
|
function init() {
|
38
|
function init() {
|
46
|
-
|
|
|
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
|
-
|
39
|
+ var $firstRow;
|
|
|
40
|
+
|
|
|
41
|
+ hasChooseColor = false;
|
|
|
42
|
+ hasChooseSize = false;
|
|
|
43
|
+ $curSizeBlock = null;
|
|
|
44
|
+ $imgsThumb = $('.chose-panel').find('.thumb'),
|
|
|
45
|
+ $allChoseItems = $('.chose-items'),
|
|
|
46
|
+ $sizeRowList = $('.size-list ul'),
|
|
|
47
|
+ $leftNum = $('#left-num'),
|
|
|
48
|
+ $firstRow = $sizeRowList.eq(0);
|
60
|
$firstRow.toggleClass('hide');
|
49
|
$firstRow.toggleClass('hide');
|
61
|
$curSizeRow = $firstRow;
|
50
|
$curSizeRow = $firstRow;
|
62
|
}
|
51
|
}
|
|
@@ -75,34 +64,64 @@ function checkColorSizeNum() { |
|
@@ -75,34 +64,64 @@ function checkColorSizeNum() { |
75
|
return true;
|
64
|
return true;
|
76
|
}
|
65
|
}
|
77
|
|
66
|
|
78
|
-init();
|
|
|
79
|
-
|
|
|
80
|
-function show(data) {
|
|
|
81
|
- if (data) {
|
|
|
82
|
- $chosePanel.html(panelTmpl(data));
|
67
|
+function show(html, cb) {
|
|
|
68
|
+ if (html) {
|
|
|
69
|
+ $chosePanel.html(html);
|
83
|
init();
|
70
|
init();
|
84
|
}
|
71
|
}
|
85
|
$('.chose-panel').show();
|
72
|
$('.chose-panel').show();
|
86
|
-
|
|
|
87
|
- $('body').css('overflow', 'hidden');
|
|
|
88
|
$num = $('#good-num');
|
73
|
$num = $('#good-num');
|
|
|
74
|
+ cbFn = cb;
|
89
|
}
|
75
|
}
|
90
|
|
76
|
|
91
|
-////显示当前Panel
|
|
|
92
|
-//function show() {
|
|
|
93
|
-// $('.chose-panel').show();
|
|
|
94
|
-//
|
|
|
95
|
-// $('body').css('overflow', 'hidden');
|
|
|
96
|
-// $num = $('#good-num');
|
|
|
97
|
-//}
|
|
|
98
|
-
|
|
|
99
|
//隐藏当前Panel
|
77
|
//隐藏当前Panel
|
100
|
function hide() {
|
78
|
function hide() {
|
101
|
$('.chose-panel').hide();
|
79
|
$('.chose-panel').hide();
|
102
|
- $('body').css('overflow', 'auto');
|
80
|
+ cbFn = null;
|
|
|
81
|
+}
|
|
|
82
|
+
|
|
|
83
|
+//修改加入购物车的文字和背景
|
|
|
84
|
+function updateConformButtonClassAndText() {
|
|
|
85
|
+ $chosed = $allChoseItems.find('.chosed');
|
|
|
86
|
+ if (2 === $chosed.closest('.zero-stock').length) {
|
|
|
87
|
+ $('#chose-btn-sure').css('background-color', '#c0c0c0').html('已售罄');
|
|
|
88
|
+ } else {
|
|
|
89
|
+ $('#chose-btn-sure').css('background-color', '#eb0313').html('确定');
|
|
|
90
|
+ }
|
|
|
91
|
+}
|
|
|
92
|
+
|
|
|
93
|
+//重置颜色块的库存为0的样式
|
|
|
94
|
+function resetColorZeroStock($siblingBlock) {
|
|
|
95
|
+ var numArray = ($curSizeBlock.data('numstr') + '').split('/'),
|
|
|
96
|
+ i;
|
|
|
97
|
+
|
|
|
98
|
+ if (!hasChooseSize) {
|
|
|
99
|
+ $siblingBlock.find('ul>li').each(function() {
|
|
|
100
|
+ $(this).removeClass('zero-stock');
|
|
|
101
|
+ if ('0' === $(this).data('num')) {
|
|
|
102
|
+ $(this).addClass('zero-stock');
|
|
|
103
|
+ }
|
|
|
104
|
+ });
|
|
|
105
|
+
|
|
|
106
|
+ } else {
|
|
|
107
|
+ for (i = 0; i < numArray.length; i++) {
|
|
|
108
|
+ if ('0' === numArray[i]) {
|
|
|
109
|
+ $siblingBlock.find('.block').eq(i).addClass('zero-stock');
|
|
|
110
|
+ }
|
|
|
111
|
+ }
|
|
|
112
|
+ }
|
|
|
113
|
+}
|
|
|
114
|
+
|
|
|
115
|
+// 选择了颜色切换商品图片
|
|
|
116
|
+function changeGoodImgWhenClickColor() {
|
|
|
117
|
+ if (hasChooseColor && curColorIndex) {
|
|
|
118
|
+ $imgsThumb.addClass('hide').eq(curColorIndex).removeClass('hide');
|
|
|
119
|
+ }
|
103
|
}
|
120
|
}
|
104
|
|
121
|
|
105
|
-$('.yoho-page').on('touchstart', '.chose-panel', function(e) {
|
122
|
+init();
|
|
|
123
|
+
|
|
|
124
|
+$yohoPage.on('touchstart', '.chose-panel', function(e) {
|
106
|
var $cur = $(e.target);
|
125
|
var $cur = $(e.target);
|
107
|
|
126
|
|
108
|
if ($cur.closest('.main').length > 0) {
|
127
|
if ($cur.closest('.main').length > 0) {
|
|
@@ -113,12 +132,11 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { |
|
@@ -113,12 +132,11 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { |
113
|
hide();
|
132
|
hide();
|
114
|
});
|
133
|
});
|
115
|
|
134
|
|
116
|
-$('.color-list').on('touchstart', '.block', function(e) {
|
135
|
+$yohoPage.on('touchstart', '.color-list .block', function(e) {
|
117
|
var $this = $(this),
|
136
|
var $this = $(this),
|
118
|
- $that = $(e.target).closest('.chose-items'),
|
|
|
119
|
index,
|
137
|
index,
|
120
|
- curSelectedSizeBlock,
|
|
|
121
|
- $sizeChosed,
|
138
|
+ curSizeBlock,
|
|
|
139
|
+ $preSiblingBlock,
|
122
|
scindex,
|
140
|
scindex,
|
123
|
curGoodNum;
|
141
|
curGoodNum;
|
124
|
|
142
|
|
|
@@ -127,50 +145,46 @@ $('.color-list').on('touchstart', '.block', function(e) { |
|
@@ -127,50 +145,46 @@ $('.color-list').on('touchstart', '.block', function(e) { |
127
|
$this.siblings('.chosed').removeClass('chosed');
|
145
|
$this.siblings('.chosed').removeClass('chosed');
|
128
|
index = $this.index();
|
146
|
index = $this.index();
|
129
|
|
147
|
|
130
|
- $sizeChosed = $siblingBlock.find('.chosed');
|
|
|
131
|
- scindex = $sizeChosed.index();
|
148
|
+ $preSiblingBlock = $siblingBlock.find('.chosed');
|
|
|
149
|
+ scindex = $preSiblingBlock.index();
|
132
|
$curSizeRow = $sizeRowList.eq(index);
|
150
|
$curSizeRow = $sizeRowList.eq(index);
|
133
|
|
151
|
|
134
|
// 当前颜色已经是选中状态,再点击时
|
152
|
// 当前颜色已经是选中状态,再点击时
|
135
|
if ($this.hasClass('chosed')) {
|
153
|
if ($this.hasClass('chosed')) {
|
136
|
|
154
|
|
137
|
//颜色原来已经是勾选时,要清空剩余件数的提示
|
155
|
//颜色原来已经是勾选时,要清空剩余件数的提示
|
138
|
- $that.find('.num .left-num').html('');
|
|
|
139
|
- $('#left-num').val(0);
|
156
|
+ $allChoseItems.find('.num .left-num').html('');
|
|
|
157
|
+ $leftNum.val(0);
|
140
|
hasChooseColor = false;
|
158
|
hasChooseColor = false;
|
141
|
|
159
|
|
142
|
// 当前颜色不是选中状态,选中时
|
160
|
// 当前颜色不是选中状态,选中时
|
143
|
} else {
|
161
|
} else {
|
144
|
hasChooseColor = true;
|
162
|
hasChooseColor = true;
|
145
|
|
163
|
|
146
|
- //根据颜色切换图片
|
|
|
147
|
- if ($this.closest('.block-list').hasClass('color-list')) {
|
|
|
148
|
- $('.chose-panel').find('.thumb').addClass('hide').eq(index).removeClass('hide');
|
|
|
149
|
- }
|
|
|
150
|
-
|
|
|
151
|
//把当前选中颜色对应的尺码那一行显示出来
|
164
|
//把当前选中颜色对应的尺码那一行显示出来
|
152
|
$sizeRowList.addClass('hide');
|
165
|
$sizeRowList.addClass('hide');
|
153
|
$curSizeRow.removeClass('hide').addClass('show');
|
166
|
$curSizeRow.removeClass('hide').addClass('show');
|
154
|
|
167
|
|
155
|
// 之前选中的尺码去掉勾选样式
|
168
|
// 之前选中的尺码去掉勾选样式
|
156
|
- if ($sizeChosed.length > 0) {
|
|
|
157
|
- $sizeChosed.removeClass('chosed');
|
|
|
158
|
- curSelectedSizeBlock = $curSizeRow.children().get(scindex);
|
169
|
+ if ($preSiblingBlock.length > 0) {
|
|
|
170
|
+ $preSiblingBlock.removeClass('chosed');
|
|
|
171
|
+
|
159
|
}
|
172
|
}
|
160
|
|
173
|
|
|
|
174
|
+ curSizeBlock = $curSizeRow.children().get(scindex);
|
|
|
175
|
+
|
161
|
// 当前选中颜色对应的尺码行,其对应的尺码加上勾选样式 (前提是要判断下这个尺码是否存在)
|
176
|
// 当前选中颜色对应的尺码行,其对应的尺码加上勾选样式 (前提是要判断下这个尺码是否存在)
|
162
|
- if (curSelectedSizeBlock) {
|
|
|
163
|
- curGoodNum = $(curSelectedSizeBlock).data('num');
|
|
|
164
|
- $(curSelectedSizeBlock).addClass('chosed');
|
177
|
+ if (curSizeBlock) {
|
|
|
178
|
+ curGoodNum = $(curSizeBlock).data('num');
|
|
|
179
|
+ $(curSizeBlock).addClass('chosed');
|
165
|
|
180
|
|
166
|
//如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式
|
181
|
//如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式
|
167
|
if (curGoodNum > 0) {
|
182
|
if (curGoodNum > 0) {
|
168
|
- $that.find('.num .left-num').html('剩余' + curGoodNum + '件');
|
|
|
169
|
- $('#left-num').val(curGoodNum);
|
183
|
+ $allChoseItems.find('.num .left-num').html('剩余' + curGoodNum + '件');
|
|
|
184
|
+ $leftNum.val(curGoodNum);
|
170
|
} else {
|
185
|
} else {
|
171
|
- $(curSelectedSizeBlock).removeClass('zero-stock').addClass('zero-stock');
|
|
|
172
|
- $that.find('.num .left-num').html('');
|
|
|
173
|
- $('#left-num').val(0);
|
186
|
+ $allChoseItems.find('.num .left-num').html('');
|
|
|
187
|
+ $leftNum.val(0);
|
174
|
}
|
188
|
}
|
175
|
}
|
189
|
}
|
176
|
}
|
190
|
}
|
|
@@ -180,106 +194,31 @@ $('.color-list').on('touchstart', '.block', function(e) { |
|
@@ -180,106 +194,31 @@ $('.color-list').on('touchstart', '.block', function(e) { |
180
|
curColorIndex = index;
|
194
|
curColorIndex = index;
|
181
|
|
195
|
|
182
|
// 设置按钮的样式和文字
|
196
|
// 设置按钮的样式和文字
|
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
|
- }**/
|
197
|
+ updateConformButtonClassAndText();
|
252
|
|
198
|
|
|
|
199
|
+ // 修改颜色时修改商品图片
|
|
|
200
|
+ changeGoodImgWhenClickColor();
|
253
|
});
|
201
|
});
|
254
|
|
202
|
|
255
|
-$('.size-list').on('touchstart', '.block', function(e) {
|
203
|
+$yohoPage.on('touchstart', '.size-list .block', function(e) {
|
256
|
var $this = $(this),
|
204
|
var $this = $(this),
|
257
|
- $that = $(e.target).closest('.chose-items'),
|
|
|
258
|
index,
|
205
|
index,
|
259
|
- $colorChosed,
|
|
|
260
|
curGoodNum;
|
206
|
curGoodNum;
|
261
|
|
207
|
|
262
|
var $siblingBlock = $this.closest('.block-list').siblings(':first');
|
208
|
var $siblingBlock = $this.closest('.block-list').siblings(':first');
|
263
|
|
209
|
|
264
|
$this.siblings('.chosed').removeClass('chosed');
|
210
|
$this.siblings('.chosed').removeClass('chosed');
|
265
|
index = $this.index();
|
211
|
index = $this.index();
|
266
|
-
|
|
|
267
|
- $colorChosed = $siblingBlock.find('.chosed');
|
|
|
268
|
$curSizeRow = $sizeRowList.eq(index);
|
212
|
$curSizeRow = $sizeRowList.eq(index);
|
269
|
|
213
|
|
270
|
// 当前尺码已经是选中状态,再点击时
|
214
|
// 当前尺码已经是选中状态,再点击时
|
271
|
if ($this.hasClass('chosed')) {
|
215
|
if ($this.hasClass('chosed')) {
|
272
|
|
216
|
|
273
|
//尺码原来已经是勾选时,要清空剩余件数的提示
|
217
|
//尺码原来已经是勾选时,要清空剩余件数的提示
|
274
|
- $that.find('.num .left-num').html('');
|
218
|
+ $allChoseItems.find('.num .left-num').html('');
|
275
|
$('#left-num').val(0);
|
219
|
$('#left-num').val(0);
|
276
|
hasChooseSize = false;
|
220
|
hasChooseSize = false;
|
277
|
|
221
|
|
278
|
- // 去掉已经选中颜色的 数量为0的样式
|
|
|
279
|
- if ($colorChosed.length > 0) {
|
|
|
280
|
- $colorChosed.removeClass('zero-stock').addClass('zero-stock');
|
|
|
281
|
- }
|
|
|
282
|
-
|
|
|
283
|
// 当前尺码不是选中状态,选中时
|
222
|
// 当前尺码不是选中状态,选中时
|
284
|
} else {
|
223
|
} else {
|
285
|
hasChooseSize = true;
|
224
|
hasChooseSize = true;
|
|
@@ -291,15 +230,15 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
@@ -291,15 +230,15 @@ $('.size-list').on('touchstart', '.block', function(e) { |
291
|
$curSizeBlock.removeClass('chosed');
|
230
|
$curSizeBlock.removeClass('chosed');
|
292
|
}
|
231
|
}
|
293
|
|
232
|
|
294
|
- // 如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式, 否则显示剩余件数
|
233
|
+ // 如果当前有尺码被选中,且数量等于0, 否则显示剩余件数
|
295
|
if (curGoodNum > 0 && hasChooseColor) {
|
234
|
if (curGoodNum > 0 && hasChooseColor) {
|
296
|
- $that.find('.num .left-num').html('剩余' + curGoodNum + '件');
|
235
|
+ $allChoseItems.find('.num .left-num').html('剩余' + curGoodNum + '件');
|
297
|
$('#left-num').val(curGoodNum);
|
236
|
$('#left-num').val(curGoodNum);
|
298
|
} else {
|
237
|
} else {
|
299
|
- $colorChosed.removeClass('zero-stock').addClass('zero-stock');
|
|
|
300
|
- $that.find('.num .left-num').html('');
|
238
|
+ $allChoseItems.find('.num .left-num').html('');
|
301
|
$('#left-num').val(0);
|
239
|
$('#left-num').val(0);
|
302
|
}
|
240
|
}
|
|
|
241
|
+
|
303
|
}
|
242
|
}
|
304
|
|
243
|
|
305
|
$this.toggleClass('chosed');
|
244
|
$this.toggleClass('chosed');
|
|
@@ -307,83 +246,15 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
@@ -307,83 +246,15 @@ $('.size-list').on('touchstart', '.block', function(e) { |
307
|
$curSizeBlock = $this;
|
246
|
$curSizeBlock = $this;
|
308
|
|
247
|
|
309
|
// 设置按钮的样式和文字
|
248
|
// 设置按钮的样式和文字
|
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
|
- }
|
249
|
+ updateConformButtonClassAndText();
|
318
|
|
250
|
|
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('确定');
|
|
|
357
|
-
|
|
|
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
|
- }**/
|
251
|
+ // 重置颜色块的样式
|
|
|
252
|
+ resetColorZeroStock($siblingBlock);
|
382
|
|
253
|
|
383
|
});
|
254
|
});
|
384
|
|
255
|
|
385
|
-$('.btn-minus').on('touchstart', function() {
|
|
|
386
|
- var num = $num.val();
|
256
|
+$yohoPage.on('touchstart', '.btn-minus', function() {
|
|
|
257
|
+ var num = parseInt($num.val(), 10);
|
387
|
|
258
|
|
388
|
leftNum = $('#left-num').val();
|
259
|
leftNum = $('#left-num').val();
|
389
|
|
260
|
|
|
@@ -396,10 +267,8 @@ $('.btn-minus').on('touchstart', function() { |
|
@@ -396,10 +267,8 @@ $('.btn-minus').on('touchstart', function() { |
396
|
}
|
267
|
}
|
397
|
|
268
|
|
398
|
$num.val(num - 1);
|
269
|
$num.val(num - 1);
|
399
|
-});
|
|
|
400
|
-
|
|
|
401
|
-$('.btn-plus').on('touchstart', function() {
|
|
|
402
|
- var num = $num.val();
|
270
|
+}).on('touchstart', '.btn-plus', function() {
|
|
|
271
|
+ var num = parseInt($num.val(), 10);
|
403
|
|
272
|
|
404
|
leftNum = $('#left-num').val();
|
273
|
leftNum = $('#left-num').val();
|
405
|
|
274
|
|
|
@@ -414,9 +283,7 @@ $('.btn-plus').on('touchstart', function() { |
|
@@ -414,9 +283,7 @@ $('.btn-plus').on('touchstart', function() { |
414
|
|
283
|
|
415
|
//TODO:库存数验证
|
284
|
//TODO:库存数验证
|
416
|
$num.val(num + 1);
|
285
|
$num.val(num + 1);
|
417
|
-});
|
|
|
418
|
-
|
|
|
419
|
-$('#chose-btn-sure').on('touchstart', function() {
|
286
|
+}).on('touchstart', '#chose-btn-sure', function() {
|
420
|
|
287
|
|
421
|
var productSku,
|
288
|
var productSku,
|
422
|
buyNumber = $('#good-num').val() - 0,
|
289
|
buyNumber = $('#good-num').val() - 0,
|
|
@@ -426,10 +293,12 @@ $('#chose-btn-sure').on('touchstart', function() { |
|
@@ -426,10 +293,12 @@ $('#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
|
}
|
432
|
|
300
|
|
|
|
301
|
+ //TODO status change
|
433
|
if ($('#chose-btn-sure').html() === '已售罄') {
|
302
|
if ($('#chose-btn-sure').html() === '已售罄') {
|
434
|
return;
|
303
|
return;
|
435
|
}
|
304
|
}
|
|
@@ -464,10 +333,13 @@ $('#chose-btn-sure').on('touchstart', function() { |
|
@@ -464,10 +333,13 @@ $('#chose-btn-sure').on('touchstart', function() { |
464
|
}).done(function(res) {
|
333
|
}).done(function(res) {
|
465
|
loading.hideLoadingMask();
|
334
|
loading.hideLoadingMask();
|
466
|
if (res.code === 200) {
|
335
|
if (res.code === 200) {
|
467
|
- $('.num-tag').html(numInCart + buyNumber);
|
|
|
468
|
- $('.num-tag').removeClass('hide');
|
336
|
+ $('.num-tag').html(numInCart + buyNumber).removeClass('hide');
|
469
|
confirming = false;
|
337
|
confirming = false;
|
470
|
hide();
|
338
|
hide();
|
|
|
339
|
+
|
|
|
340
|
+ if (cbFn) {
|
|
|
341
|
+ cbFn(res.location);
|
|
|
342
|
+ }
|
471
|
}
|
343
|
}
|
472
|
if (res.message) {
|
344
|
if (res.message) {
|
473
|
tip.show(res.message);
|
345
|
tip.show(res.message);
|