|
|
/**
|
|
|
* 退换货申请
|
|
|
* 商品详情
|
|
|
* @author: yyqing<yanqing.yang@yoho.cn>
|
|
|
* @date: 2016/7/15
|
|
|
*/
|
|
|
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'),
|
|
|
$colorItem = $('.color-list .round-color'),
|
|
|
$sizeList = $('.size-list'),
|
|
|
$sizeItem = $('.size-list').children();
|
|
|
$sizeItem = $('.size-list > li');
|
|
|
|
|
|
var $addToBag = $('#add-to-bag');
|
|
|
|
|
|
var SLIDETIME = 200;
|
|
|
|
|
|
lazyload($('img.lazy'));
|
|
|
|
|
|
$colorList.on('click', '.round-color', function() {
|
|
|
function getBuyProduct() {
|
|
|
var sku;
|
|
|
|
|
|
$sizeItem.each(function() {
|
|
|
var $this = $(this),
|
|
|
data;
|
|
|
|
|
|
if ($this.hasClass('cur')) {
|
|
|
data = $this.data();
|
|
|
sku = data.sku;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return sku;
|
|
|
}
|
|
|
|
|
|
// 颜色
|
|
|
$('.color-list').on('click', '.color-item', function() {
|
|
|
var $this = $(this),
|
|
|
data = $this.parent().data();
|
|
|
index = $this.index(),
|
|
|
data = $this.data();
|
|
|
|
|
|
if (!$this.hasClass('cur')) {
|
|
|
$colorList.removeClass('cur');
|
|
|
$colorItem.removeClass('cur');
|
|
|
$sizeList.not('.hide').addClass('hide');
|
|
|
$sizeList.eq(index).removeClass('hide');
|
|
|
$sizeItem.removeClass('cur');
|
|
|
$colorText.text(data.color ? data.color : '');
|
|
|
$this.addClass('cur');
|
|
|
$this.children().addClass('cur');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$sizeList.on('click', 'li', function() {
|
|
|
// 尺码
|
|
|
$('.size-list').on('click', 'li', function() {
|
|
|
var $this = $(this),
|
|
|
data = $this.data();
|
|
|
|
...
|
...
|
@@ -35,3 +63,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); // 更新数目
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}); |
...
|
...
|
|