|
@@ -26,19 +26,19 @@ let $yohoPage = $('.yoho-page'), |
|
@@ -26,19 +26,19 @@ let $yohoPage = $('.yoho-page'), |
26
|
$choseArea,
|
26
|
$choseArea,
|
27
|
$goodNum,
|
27
|
$goodNum,
|
28
|
$btnMinus,
|
28
|
$btnMinus,
|
29
|
- $thumbImg;
|
29
|
+ $thumbImg,
|
|
|
30
|
+ $choseBtnSure,
|
|
|
31
|
+ $noChoose,
|
|
|
32
|
+ $chooseInfo;
|
30
|
|
33
|
|
31
|
class ChosePanel {
|
34
|
class ChosePanel {
|
32
|
constructor() {
|
35
|
constructor() {
|
33
|
- this.setting = {
|
|
|
34
|
- buttonText: '确认'
|
|
|
35
|
- };
|
36
|
+ this.C_ID = window._ChannelVary[window.cookie('_Channel')];
|
36
|
this._regEvents();
|
37
|
this._regEvents();
|
37
|
}
|
38
|
}
|
38
|
show(opt) {
|
39
|
show(opt) {
|
39
|
if (opt && opt.data) {
|
40
|
if (opt && opt.data) {
|
40
|
this.data = opt.data;
|
41
|
this.data = opt.data;
|
41
|
- this.disableNum = opt.disableNum;
|
|
|
42
|
this.maxBuyNum = opt.data.cartInfo.limit || 0; // 0表示不限制购买
|
42
|
this.maxBuyNum = opt.data.cartInfo.limit || 0; // 0表示不限制购买
|
43
|
this.skus = this.data.cartInfo.skus || [];
|
43
|
this.skus = this.data.cartInfo.skus || [];
|
44
|
this.props = this.data.cartInfo.props || [];
|
44
|
this.props = this.data.cartInfo.props || [];
|
|
@@ -48,10 +48,16 @@ class ChosePanel { |
|
@@ -48,10 +48,16 @@ class ChosePanel { |
48
|
limitCode: opt.data.cartInfo.limitProductCode ? true : false, // 限购
|
48
|
limitCode: opt.data.cartInfo.limitProductCode ? true : false, // 限购
|
49
|
limit: opt.data.cartInfo.limit ? true : false, // 限制购买数量
|
49
|
limit: opt.data.cartInfo.limit ? true : false, // 限制购买数量
|
50
|
soonSoldOut: $('.soon-sold-out-tag').length ? true : false, // 即将售罄
|
50
|
soonSoldOut: $('.soon-sold-out-tag').length ? true : false, // 即将售罄
|
51
|
- seckill: $('.seckill-time').length ? true : false // 秒杀
|
51
|
+ seckill: $('.seckill-time').length ? true : false, // 秒杀
|
|
|
52
|
+ disableNum: opt.disableNum // 禁用编辑
|
52
|
};
|
53
|
};
|
53
|
- this.buttonText = opt.buttonText || this._getButtonText();
|
|
|
54
|
this.buyNum = this.minBuyNum = this._defaultBuyNum();
|
54
|
this.buyNum = this.minBuyNum = this._defaultBuyNum();
|
|
|
55
|
+ this.setting = {
|
|
|
56
|
+ disableNum: opt.disableNum,
|
|
|
57
|
+ noChoseText: `请选择${this.props.map(prop => prop.name).join('、')}`,
|
|
|
58
|
+ buttonText: opt.buttonText || this._getButtonText(),
|
|
|
59
|
+ buyNum: this.buyNum
|
|
|
60
|
+ };
|
55
|
}
|
61
|
}
|
56
|
|
62
|
|
57
|
if (!this.data) {
|
63
|
if (!this.data) {
|
|
@@ -74,18 +80,14 @@ class ChosePanel { |
|
@@ -74,18 +80,14 @@ class ChosePanel { |
74
|
_render() {
|
80
|
_render() {
|
75
|
let html;
|
81
|
let html;
|
76
|
|
82
|
|
77
|
- html = panelT(Object.assign(this.data, {
|
|
|
78
|
- buttonText: this.buttonText,
|
|
|
79
|
- buyNum: this.buyNum,
|
|
|
80
|
- disableNum: this.disableNum
|
|
|
81
|
- }));
|
83
|
+ html = panelT(Object.assign(this.data, this.setting));
|
82
|
if ($chosePanel.length) {
|
84
|
if ($chosePanel.length) {
|
83
|
$chosePanel.replaceWith(html);
|
85
|
$chosePanel.replaceWith(html);
|
84
|
} else {
|
86
|
} else {
|
85
|
$yohoPage.append(html);
|
87
|
$yohoPage.append(html);
|
86
|
}
|
88
|
}
|
87
|
|
89
|
|
88
|
- this.setVariable();
|
90
|
+ this._setVariable();
|
89
|
this._initStatus();
|
91
|
this._initStatus();
|
90
|
innerScroll.disableScroll($choseArea);
|
92
|
innerScroll.disableScroll($choseArea);
|
91
|
}
|
93
|
}
|
|
@@ -93,7 +95,7 @@ class ChosePanel { |
|
@@ -93,7 +95,7 @@ class ChosePanel { |
93
|
if (this.modes.tickets || this.modes.limitCode || this.modes.seckill) {
|
95
|
if (this.modes.tickets || this.modes.limitCode || this.modes.seckill) {
|
94
|
return '立即购买';
|
96
|
return '立即购买';
|
95
|
}
|
97
|
}
|
96
|
- return '确定';
|
98
|
+ return '加入购物车';
|
97
|
}
|
99
|
}
|
98
|
_defaultBuyNum() {
|
100
|
_defaultBuyNum() {
|
99
|
return this.modes.discount && this.data.discountBuy.num || 1;
|
101
|
return this.modes.discount && this.data.discountBuy.num || 1;
|
|
@@ -119,25 +121,28 @@ class ChosePanel { |
|
@@ -119,25 +121,28 @@ class ChosePanel { |
119
|
}
|
121
|
}
|
120
|
});
|
122
|
});
|
121
|
}
|
123
|
}
|
122
|
- setVariable() {
|
124
|
+ _setVariable() {
|
123
|
$chosePanel = $('.chose-panel');
|
125
|
$chosePanel = $('.chose-panel');
|
124
|
$choseArea = $('.chose-panel .main .chose-items');
|
126
|
$choseArea = $('.chose-panel .main .chose-items');
|
125
|
$goodNum = $('#good-num');
|
127
|
$goodNum = $('#good-num');
|
126
|
$btnMinus = $('.btn-minus');
|
128
|
$btnMinus = $('.btn-minus');
|
127
|
$thumbImg = $('.thumb-img');
|
129
|
$thumbImg = $('.thumb-img');
|
|
|
130
|
+ $choseBtnSure = $('#chose-btn-sure');
|
|
|
131
|
+ $noChoose = $('.not-choose');
|
|
|
132
|
+ $chooseInfo = $('.choosed-info');
|
128
|
}
|
133
|
}
|
129
|
_regEvents() {
|
134
|
_regEvents() {
|
130
|
$yohoPage.on('touchstart', '.chose-panel', (e) => {
|
135
|
$yohoPage.on('touchstart', '.chose-panel', (e) => {
|
131
|
return this._closeClick(e);
|
136
|
return this._closeClick(e);
|
132
|
});
|
137
|
});
|
133
|
$yohoPage.on('touchstart', '.block', (e) => {
|
138
|
$yohoPage.on('touchstart', '.block', (e) => {
|
134
|
- return this._blockClick(e);
|
139
|
+ this._blockClick(e);
|
135
|
});
|
140
|
});
|
136
|
$yohoPage.on('touchstart', '.btn-plus,.btn-minus', (e) => {
|
141
|
$yohoPage.on('touchstart', '.btn-plus,.btn-minus', (e) => {
|
137
|
- return this._numClick(e);
|
142
|
+ this._numClick(e);
|
138
|
});
|
143
|
});
|
139
|
$yohoPage.on('touchstart', '.thumb', (e) => {
|
144
|
$yohoPage.on('touchstart', '.thumb', (e) => {
|
140
|
- return this._thumbClick(e);
|
145
|
+ this._thumbClick(e);
|
141
|
});
|
146
|
});
|
142
|
$yohoPage.on('touchstart', '#chose-btn-sure', (e) => {
|
147
|
$yohoPage.on('touchstart', '#chose-btn-sure', (e) => {
|
143
|
return this._choseBtnSureClick(e);
|
148
|
return this._choseBtnSureClick(e);
|
|
@@ -165,7 +170,7 @@ class ChosePanel { |
|
@@ -165,7 +170,7 @@ class ChosePanel { |
165
|
_numClick(e) {
|
170
|
_numClick(e) {
|
166
|
let buyNum;
|
171
|
let buyNum;
|
167
|
|
172
|
|
168
|
- if ($(e.currentTarget).hasClass('disabled')) {
|
173
|
+ if (this.modes.disableNum) {
|
169
|
return;
|
174
|
return;
|
170
|
}
|
175
|
}
|
171
|
buyNum = $(e.currentTarget).hasClass('btn-minus') ? this.buyNum - 1 : this.buyNum + 1;
|
176
|
buyNum = $(e.currentTarget).hasClass('btn-minus') ? this.buyNum - 1 : this.buyNum + 1;
|
|
@@ -192,11 +197,19 @@ class ChosePanel { |
|
@@ -192,11 +197,19 @@ class ChosePanel { |
192
|
let selectSku = this._checkSku(this.buyNum);
|
197
|
let selectSku = this._checkSku(this.buyNum);
|
193
|
|
198
|
|
194
|
if (selectSku) {
|
199
|
if (selectSku) {
|
195
|
- this._resolve(selectSku);
|
200
|
+ this._resolve({
|
|
|
201
|
+ sku: selectSku,
|
|
|
202
|
+ buyNum: this.buyNum,
|
|
|
203
|
+ modes: this.modes
|
|
|
204
|
+ });
|
196
|
this.close();
|
205
|
this.close();
|
|
|
206
|
+ return false;
|
197
|
}
|
207
|
}
|
198
|
}
|
208
|
}
|
199
|
_checkSku(buyNum) {
|
209
|
_checkSku(buyNum) {
|
|
|
210
|
+ if ($('.block.chosed.zero-stock').length) {
|
|
|
211
|
+ return false;
|
|
|
212
|
+ }
|
200
|
let validSelects = this.props
|
213
|
let validSelects = this.props
|
201
|
.filter(prop => !$(`.block[data-prop-id="${prop.type}"]`).hasClass('chosed'))
|
214
|
.filter(prop => !$(`.block[data-prop-id="${prop.type}"]`).hasClass('chosed'))
|
202
|
.map(prop => {
|
215
|
.map(prop => {
|
|
@@ -226,6 +239,10 @@ class ChosePanel { |
|
@@ -226,6 +239,10 @@ class ChosePanel { |
226
|
tip.show(`每人只可购买${this.maxBuyNum}张当日门票`);
|
239
|
tip.show(`每人只可购买${this.maxBuyNum}张当日门票`);
|
227
|
return false;
|
240
|
return false;
|
228
|
}
|
241
|
}
|
|
|
242
|
+ if (this.modes.limit && buyNum > this.maxBuyNum) {
|
|
|
243
|
+ tip.show('您选择数量大于限购数量~');
|
|
|
244
|
+ return false;
|
|
|
245
|
+ }
|
229
|
if (buyNum > selectSku.storage) {
|
246
|
if (buyNum > selectSku.storage) {
|
230
|
tip.show('您选择的数量超过了最大库存量~');
|
247
|
tip.show('您选择的数量超过了最大库存量~');
|
231
|
return false;
|
248
|
return false;
|
|
@@ -258,6 +275,27 @@ class ChosePanel { |
|
@@ -258,6 +275,27 @@ class ChosePanel { |
258
|
});
|
275
|
});
|
259
|
});
|
276
|
});
|
260
|
}
|
277
|
}
|
|
|
278
|
+ if (window._yas && window._yas.sendCustomInfo && chosed) {
|
|
|
279
|
+ if (propId === 'color') {
|
|
|
280
|
+ window._yas.sendCustomInfo({
|
|
|
281
|
+ op: 'YB_GDS_COLOR_C',
|
|
|
282
|
+ param: JSON.stringify({
|
|
|
283
|
+ C_ID: this.C_ID,
|
|
|
284
|
+ PRD_ID: this.data.cartInfo.productId,
|
|
|
285
|
+ COLOR: $selectBlock.text()
|
|
|
286
|
+ })
|
|
|
287
|
+ }, true);
|
|
|
288
|
+ } else if (propId === 'size') {
|
|
|
289
|
+ window._yas.sendCustomInfo({
|
|
|
290
|
+ op: 'YB_GDS_SIZE_C',
|
|
|
291
|
+ param: JSON.stringify({
|
|
|
292
|
+ C_ID: this.C_ID,
|
|
|
293
|
+ PRD_ID: this.data.cartInfo.productId,
|
|
|
294
|
+ SIZE: $selectBlock.text()
|
|
|
295
|
+ })
|
|
|
296
|
+ }, true);
|
|
|
297
|
+ }
|
|
|
298
|
+ }
|
261
|
|
299
|
|
262
|
this._initBlockStatus();
|
300
|
this._initBlockStatus();
|
263
|
}
|
301
|
}
|
|
@@ -266,9 +304,9 @@ class ChosePanel { |
|
@@ -266,9 +304,9 @@ class ChosePanel { |
266
|
|
304
|
|
267
|
// 设置底部按钮文字
|
305
|
// 设置底部按钮文字
|
268
|
if ($('.block.chosed.zero-stock').length) {
|
306
|
if ($('.block.chosed.zero-stock').length) {
|
269
|
- $('#chose-btn-sure').css('background-color', '#c0c0c0').text('已售罄');
|
307
|
+ $choseBtnSure.css('background-color', '#c0c0c0').text('已售罄');
|
270
|
} else {
|
308
|
} else {
|
271
|
- $('#chose-btn-sure').css('background-color', '#eb0313').text(this.buttonText);
|
309
|
+ $choseBtnSure.css('background-color', '#eb0313').text(this.setting.buttonText);
|
272
|
}
|
310
|
}
|
273
|
|
311
|
|
274
|
// 设置默认购买数量
|
312
|
// 设置默认购买数量
|
|
@@ -301,12 +339,12 @@ class ChosePanel { |
|
@@ -301,12 +339,12 @@ class ChosePanel { |
301
|
}));
|
339
|
}));
|
302
|
|
340
|
|
303
|
if (valueList.length) {
|
341
|
if (valueList.length) {
|
304
|
- $('.not-choose').addClass('hide');
|
|
|
305
|
- $('.choosed-info').removeClass('hide');
|
|
|
306
|
- $('.choosed-info').text(`已选:${valueList.join('、')}`);
|
342
|
+ $noChoose.addClass('hide');
|
|
|
343
|
+ $chooseInfo.removeClass('hide');
|
|
|
344
|
+ $chooseInfo.text(`已选:${valueList.join('、')}`);
|
307
|
} else {
|
345
|
} else {
|
308
|
- $('.not-choose').removeClass('hide');
|
|
|
309
|
- $('.choosed-info').addClass('hide');
|
346
|
+ $noChoose.removeClass('hide');
|
|
|
347
|
+ $chooseInfo.addClass('hide');
|
310
|
}
|
348
|
}
|
311
|
|
349
|
|
312
|
if (selectSku) {
|
350
|
if (selectSku) {
|
|
@@ -326,6 +364,7 @@ class ChosePanel { |
|
@@ -326,6 +364,7 @@ class ChosePanel { |
326
|
$chosePanel.find('.left-num').text(numText);
|
364
|
$chosePanel.find('.left-num').text(numText);
|
327
|
$chosePanel.find('.size-info').text(selectSku.sizeInfo).removeClass('hide');
|
365
|
$chosePanel.find('.size-info').text(selectSku.sizeInfo).removeClass('hide');
|
328
|
} else {
|
366
|
} else {
|
|
|
367
|
+ $chosePanel.find('.left-num').text('');
|
329
|
$chosePanel.find('.size-info').text('').addClass('hide');
|
368
|
$chosePanel.find('.size-info').text('').addClass('hide');
|
330
|
}
|
369
|
}
|
331
|
}
|
370
|
}
|