...
|
...
|
@@ -26,19 +26,19 @@ let $yohoPage = $('.yoho-page'), |
|
|
$choseArea,
|
|
|
$goodNum,
|
|
|
$btnMinus,
|
|
|
$thumbImg;
|
|
|
$thumbImg,
|
|
|
$choseBtnSure,
|
|
|
$noChoose,
|
|
|
$chooseInfo;
|
|
|
|
|
|
class ChosePanel {
|
|
|
constructor() {
|
|
|
this.setting = {
|
|
|
buttonText: '确认'
|
|
|
};
|
|
|
this.C_ID = window._ChannelVary[window.cookie('_Channel')];
|
|
|
this._regEvents();
|
|
|
}
|
|
|
show(opt) {
|
|
|
if (opt && opt.data) {
|
|
|
this.data = opt.data;
|
|
|
this.disableNum = opt.disableNum;
|
|
|
this.maxBuyNum = opt.data.cartInfo.limit || 0; // 0表示不限制购买
|
|
|
this.skus = this.data.cartInfo.skus || [];
|
|
|
this.props = this.data.cartInfo.props || [];
|
...
|
...
|
@@ -48,10 +48,16 @@ class ChosePanel { |
|
|
limitCode: opt.data.cartInfo.limitProductCode ? true : false, // 限购
|
|
|
limit: opt.data.cartInfo.limit ? true : false, // 限制购买数量
|
|
|
soonSoldOut: $('.soon-sold-out-tag').length ? true : false, // 即将售罄
|
|
|
seckill: $('.seckill-time').length ? true : false // 秒杀
|
|
|
seckill: $('.seckill-time').length ? true : false, // 秒杀
|
|
|
disableNum: opt.disableNum // 禁用编辑
|
|
|
};
|
|
|
this.buttonText = opt.buttonText || this._getButtonText();
|
|
|
this.buyNum = this.minBuyNum = this._defaultBuyNum();
|
|
|
this.setting = {
|
|
|
disableNum: opt.disableNum,
|
|
|
noChoseText: `请选择${this.props.map(prop => prop.name).join('、')}`,
|
|
|
buttonText: opt.buttonText || this._getButtonText(),
|
|
|
buyNum: this.buyNum
|
|
|
};
|
|
|
}
|
|
|
|
|
|
if (!this.data) {
|
...
|
...
|
@@ -74,18 +80,14 @@ class ChosePanel { |
|
|
_render() {
|
|
|
let html;
|
|
|
|
|
|
html = panelT(Object.assign(this.data, {
|
|
|
buttonText: this.buttonText,
|
|
|
buyNum: this.buyNum,
|
|
|
disableNum: this.disableNum
|
|
|
}));
|
|
|
html = panelT(Object.assign(this.data, this.setting));
|
|
|
if ($chosePanel.length) {
|
|
|
$chosePanel.replaceWith(html);
|
|
|
} else {
|
|
|
$yohoPage.append(html);
|
|
|
}
|
|
|
|
|
|
this.setVariable();
|
|
|
this._setVariable();
|
|
|
this._initStatus();
|
|
|
innerScroll.disableScroll($choseArea);
|
|
|
}
|
...
|
...
|
@@ -93,7 +95,7 @@ class ChosePanel { |
|
|
if (this.modes.tickets || this.modes.limitCode || this.modes.seckill) {
|
|
|
return '立即购买';
|
|
|
}
|
|
|
return '确定';
|
|
|
return '加入购物车';
|
|
|
}
|
|
|
_defaultBuyNum() {
|
|
|
return this.modes.discount && this.data.discountBuy.num || 1;
|
...
|
...
|
@@ -119,25 +121,28 @@ class ChosePanel { |
|
|
}
|
|
|
});
|
|
|
}
|
|
|
setVariable() {
|
|
|
_setVariable() {
|
|
|
$chosePanel = $('.chose-panel');
|
|
|
$choseArea = $('.chose-panel .main .chose-items');
|
|
|
$goodNum = $('#good-num');
|
|
|
$btnMinus = $('.btn-minus');
|
|
|
$thumbImg = $('.thumb-img');
|
|
|
$choseBtnSure = $('#chose-btn-sure');
|
|
|
$noChoose = $('.not-choose');
|
|
|
$chooseInfo = $('.choosed-info');
|
|
|
}
|
|
|
_regEvents() {
|
|
|
$yohoPage.on('touchstart', '.chose-panel', (e) => {
|
|
|
return this._closeClick(e);
|
|
|
});
|
|
|
$yohoPage.on('touchstart', '.block', (e) => {
|
|
|
return this._blockClick(e);
|
|
|
this._blockClick(e);
|
|
|
});
|
|
|
$yohoPage.on('touchstart', '.btn-plus,.btn-minus', (e) => {
|
|
|
return this._numClick(e);
|
|
|
this._numClick(e);
|
|
|
});
|
|
|
$yohoPage.on('touchstart', '.thumb', (e) => {
|
|
|
return this._thumbClick(e);
|
|
|
this._thumbClick(e);
|
|
|
});
|
|
|
$yohoPage.on('touchstart', '#chose-btn-sure', (e) => {
|
|
|
return this._choseBtnSureClick(e);
|
...
|
...
|
@@ -165,7 +170,7 @@ class ChosePanel { |
|
|
_numClick(e) {
|
|
|
let buyNum;
|
|
|
|
|
|
if ($(e.currentTarget).hasClass('disabled')) {
|
|
|
if (this.modes.disableNum) {
|
|
|
return;
|
|
|
}
|
|
|
buyNum = $(e.currentTarget).hasClass('btn-minus') ? this.buyNum - 1 : this.buyNum + 1;
|
...
|
...
|
@@ -192,11 +197,19 @@ class ChosePanel { |
|
|
let selectSku = this._checkSku(this.buyNum);
|
|
|
|
|
|
if (selectSku) {
|
|
|
this._resolve(selectSku);
|
|
|
this._resolve({
|
|
|
sku: selectSku,
|
|
|
buyNum: this.buyNum,
|
|
|
modes: this.modes
|
|
|
});
|
|
|
this.close();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
_checkSku(buyNum) {
|
|
|
if ($('.block.chosed.zero-stock').length) {
|
|
|
return false;
|
|
|
}
|
|
|
let validSelects = this.props
|
|
|
.filter(prop => !$(`.block[data-prop-id="${prop.type}"]`).hasClass('chosed'))
|
|
|
.map(prop => {
|
...
|
...
|
@@ -226,6 +239,10 @@ class ChosePanel { |
|
|
tip.show(`每人只可购买${this.maxBuyNum}张当日门票`);
|
|
|
return false;
|
|
|
}
|
|
|
if (this.modes.limit && buyNum > this.maxBuyNum) {
|
|
|
tip.show('您选择数量大于限购数量~');
|
|
|
return false;
|
|
|
}
|
|
|
if (buyNum > selectSku.storage) {
|
|
|
tip.show('您选择的数量超过了最大库存量~');
|
|
|
return false;
|
...
|
...
|
@@ -258,6 +275,27 @@ class ChosePanel { |
|
|
});
|
|
|
});
|
|
|
}
|
|
|
if (window._yas && window._yas.sendCustomInfo && chosed) {
|
|
|
if (propId === 'color') {
|
|
|
window._yas.sendCustomInfo({
|
|
|
op: 'YB_GDS_COLOR_C',
|
|
|
param: JSON.stringify({
|
|
|
C_ID: this.C_ID,
|
|
|
PRD_ID: this.data.cartInfo.productId,
|
|
|
COLOR: $selectBlock.text()
|
|
|
})
|
|
|
}, true);
|
|
|
} else if (propId === 'size') {
|
|
|
window._yas.sendCustomInfo({
|
|
|
op: 'YB_GDS_SIZE_C',
|
|
|
param: JSON.stringify({
|
|
|
C_ID: this.C_ID,
|
|
|
PRD_ID: this.data.cartInfo.productId,
|
|
|
SIZE: $selectBlock.text()
|
|
|
})
|
|
|
}, true);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
this._initBlockStatus();
|
|
|
}
|
...
|
...
|
@@ -266,9 +304,9 @@ class ChosePanel { |
|
|
|
|
|
// 设置底部按钮文字
|
|
|
if ($('.block.chosed.zero-stock').length) {
|
|
|
$('#chose-btn-sure').css('background-color', '#c0c0c0').text('已售罄');
|
|
|
$choseBtnSure.css('background-color', '#c0c0c0').text('已售罄');
|
|
|
} else {
|
|
|
$('#chose-btn-sure').css('background-color', '#eb0313').text(this.buttonText);
|
|
|
$choseBtnSure.css('background-color', '#eb0313').text(this.setting.buttonText);
|
|
|
}
|
|
|
|
|
|
// 设置默认购买数量
|
...
|
...
|
@@ -301,12 +339,12 @@ class ChosePanel { |
|
|
}));
|
|
|
|
|
|
if (valueList.length) {
|
|
|
$('.not-choose').addClass('hide');
|
|
|
$('.choosed-info').removeClass('hide');
|
|
|
$('.choosed-info').text(`已选:${valueList.join('、')}`);
|
|
|
$noChoose.addClass('hide');
|
|
|
$chooseInfo.removeClass('hide');
|
|
|
$chooseInfo.text(`已选:${valueList.join('、')}`);
|
|
|
} else {
|
|
|
$('.not-choose').removeClass('hide');
|
|
|
$('.choosed-info').addClass('hide');
|
|
|
$noChoose.removeClass('hide');
|
|
|
$chooseInfo.addClass('hide');
|
|
|
}
|
|
|
|
|
|
if (selectSku) {
|
...
|
...
|
@@ -326,6 +364,7 @@ class ChosePanel { |
|
|
$chosePanel.find('.left-num').text(numText);
|
|
|
$chosePanel.find('.size-info').text(selectSku.sizeInfo).removeClass('hide');
|
|
|
} else {
|
|
|
$chosePanel.find('.left-num').text('');
|
|
|
$chosePanel.find('.size-info').text('').addClass('hide');
|
|
|
}
|
|
|
}
|
...
|
...
|
|