Authored by 陈峰

商品详情页尺码选择集成

... ... @@ -527,11 +527,6 @@ let getNewProductAsyncData = (data) => {
discount: _.get(bundleData, 'bundleInfo.discount', '')
};
}
finalResult.discountBuy = {
num: 36,
promotionPhrase: 'xxx',
discount: '0.7'
};
return finalResult;
});
});
... ...
... ... @@ -16,7 +16,7 @@
<span class="market-price">{{salePrice}}</span> {{else}}
<span class="sale-price no-price">{{salePrice}}</span> {{/ isY}} {{/if}}
</p>
<p class="not-choose">请选择颜色、尺码</p>
<p class="not-choose">{{@root.noChoseText}}</p>
<p class="choosed-info hide"></p>
<p class="size-info hide"></p>
</div>
... ...
... ... @@ -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');
}
}
... ...
let $ = require('yoho-jquery'),
tip = require('plugin/tip');
let functions = {
/**
* 添加门票
*/
addTickets(productSku, buyNumber) {
var data = {
productSku: productSku,
buyNumber: buyNumber
};
// 校验电子票
$.ajax({
url: '/cart/index/checkTickets',
dataType: 'json',
data: data,
type: 'post',
success: function(addRestult) {
if (addRestult.code !== 200) {
if (addRestult.code === 401) {
window.location.href = '//m.yohobuy.com/signin.html?refer=' + window.location.href;
}
tip.show(addRestult.message);
} else {
$('#productSku').val(productSku);
$('#buyNumber').val(buyNumber);
$('#buyNowForm').submit();
}
},
error: function() {
tip.show('网络异常~');
}
});
},
/**
* 添加限购商品
*/
addLimitCode(limitProductCode, sku, skn, buyNum) {
let url = $('#limitProductPay').val() + '?limitproductcode=' + limitProductCode + '&sku=' +
sku + '&skn=' + skn + '&buy_number=' + buyNum;
// 调用接口判断商品是否可以购买
$.ajax({
url: url
}).then(function(res) {
// 如果有错,则商品不可购买,执行页面刷新,否则跳到结算页面
if (res.error) {
tip.show(res.message);
setTimeout(function() {
location.reload();
}, 2000);
} else {
location.href = url;
}
}).fail(function() {
tip.show('网络异常!');
setTimeout(function() {
location.reload();
}, 2000);
});
},
/**
* 添加到购物车
*/
addToCart(sku, skn, buyNum) {
$.ajax({
method: 'POST',
url: '/cart/index/add',
data: {
productSku: sku,
new_product_skn: skn,
buyNumber: buyNum
}
}).done(function(res) {
var cartNum;
if (res.code === 200) {
cartNum = res.data.goods_count;
if (cartNum > 99) {
cartNum = '99+';
}
$('.num-tag').html(cartNum).removeClass('hide');
}
if (res.message) {
tip.show(res.message);
}
}).fail(function() {
tip.show('网络出了点问题~');
}).always(function() {
});
}
};
module.exports = functions;
... ...
require('product/detail/detail.page.css');
let $ = require('yoho-jquery');
let $ = require('yoho-jquery'),
tip = require('../plugin/tip');
let productId = $('#productId').val();
let goodsId = $('#goodsId').val();
let productSkn = $('#productSkn').val();
... ... @@ -17,6 +18,8 @@ require('./detail/desc');
// 为你优选
require('./detail/recommend-for-you-product-desc');
let detailFuns = require('./detail/functions');
window.rePosFooter && window.rePosFooter();
setTimeout(() => {
... ... @@ -83,8 +86,6 @@ setTimeout(() => {
$('#placeholder-infodata').replaceWith(infoDataHbs(data));
if (data.isDepositAdvance === 'Y') {
// 定金预售商品
let tip = require('../plugin/tip');
setTimeout(function() {
$('#addtoCart').text('立即购买').off('touchstart').on('touchstart', function() {
... ... @@ -153,15 +154,24 @@ setTimeout(() => {
let productCode = $('#limitProductCode').val();
$('.cart-bar').hide();
// productCode && chosePanel.setLimitGoodModeWithSknId(productCode, productSkn);
chosePanel.show({
data: data,
buttonText: '加入购物车'
}).then(() => {
console.log('choice')
disableNum: productCode
}).then((result) => {
$('.cart-bar').show();
if (result && result.sku) {
if (result.modes.tickets) {
detailFuns.addTickets(result.sku.skuId, result.buyNum);
return;
}
if (result.modes.limitCode) {
detailFuns.addLimitCode(productCode, result.sku.skuId, productSkn, result.buyNum);
return;
}
detailFuns.addToCart(result.sku.skuId, productSkn, result.buyNum);
}
}, () => {
$('.cart-bar').show();
console.log('cancel')
});
// 统计代码:用于统计用户加入购物车的动作
... ... @@ -377,4 +387,4 @@ setTimeout(() => {
});
// 加载详情页的返回顶部按钮并注册事件-end
}(productSkn, productId, brandId));
}(productSkn, productId, brandId));
\ No newline at end of file
... ...