...
|
...
|
@@ -6,25 +6,50 @@ |
|
|
var $ = require('yoho-jquery'),
|
|
|
lazyload = require('yoho-jquery-lazyload');
|
|
|
|
|
|
var $colorText = $('.choose-color .color'),
|
|
|
var $tradeWrapper = $('.trade-wrapper'),
|
|
|
$balanceWrapper = $('.balance-wrapper'),
|
|
|
$colorText = $('.choose-color .color'),
|
|
|
$sizeText = $('.choose-size .size'),
|
|
|
$colorList = $('.color-list'),
|
|
|
$sizeList = $('.size-list'),
|
|
|
$sizeItem = $('.size-list').children();
|
|
|
|
|
|
var $addToBag = $('#add-to-bag');
|
|
|
|
|
|
var SLIDETIME = 200;
|
|
|
|
|
|
lazyload($('img.lazy'));
|
|
|
|
|
|
function getBuyProduct() {
|
|
|
var sku;
|
|
|
|
|
|
$sizeItem.each(function() {
|
|
|
var $this = $(this),
|
|
|
data;
|
|
|
|
|
|
if ($this.hasClass('cur')) {
|
|
|
data = $this.data();
|
|
|
sku = data.sku;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return sku;
|
|
|
}
|
|
|
|
|
|
// 颜色
|
|
|
$colorList.on('click', '.round-color', function() {
|
|
|
var $this = $(this),
|
|
|
data = $this.parent().data();
|
|
|
|
|
|
if (!$this.hasClass('cur')) {
|
|
|
$colorList.removeClass('cur');
|
|
|
$sizeItem.removeClass('cur');
|
|
|
$colorText.text(data.color ? data.color : '');
|
|
|
$this.addClass('cur');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 尺码
|
|
|
$sizeList.on('click', 'li', function() {
|
|
|
var $this = $(this),
|
|
|
data = $this.data();
|
...
|
...
|
@@ -35,3 +60,25 @@ $sizeList.on('click', 'li', function() { |
|
|
$this.addClass('cur');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$addToBag.click(function() {
|
|
|
var sku = getBuyProduct();
|
|
|
|
|
|
if (sku) {
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: '/shopping/cart/add',
|
|
|
data: {
|
|
|
productSku: sku,
|
|
|
buyNumber: 1
|
|
|
}
|
|
|
}).then(function(data) {
|
|
|
if (data.code === 200) {
|
|
|
$tradeWrapper.slideUp(SLIDETIME);
|
|
|
$balanceWrapper.slideDown(SLIDETIME);
|
|
|
|
|
|
// $('#cart-num').text(data.data.goods_count); // 更新数目
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}); |
...
|
...
|
|