...
|
...
|
@@ -15,7 +15,8 @@ var $cartnewTips = $('.cartnew-tips'), |
|
|
CART_ITEM_FAV_URL = '/cart/index/fav',
|
|
|
selColorWinTpl = require('hbs/cart/select-color-panel.hbs'),
|
|
|
giftsWinTpl = require('hbs/cart/cart-gifts-win-tpl.hbs'),
|
|
|
productInfoTpl = require('hbs/cart/cart-product-info-tpl.hbs');
|
|
|
productInfoTpl = require('hbs/cart/cart-product-info-tpl.hbs'),
|
|
|
$goodsSelWin = $('#Y_goodsSelectWin');
|
|
|
|
|
|
// 关闭温馨提示
|
|
|
$cartnewTips.find('.btn_close').click(function() {
|
...
|
...
|
@@ -386,194 +387,19 @@ function getProductByPromotionId(promotionId) { |
|
|
});
|
|
|
}
|
|
|
|
|
|
function bindGiftWinAction($el) {
|
|
|
|
|
|
$el.on('click', '.slide-img .img-list .img-item', function() {
|
|
|
|
|
|
var id = $(this).data('id');
|
|
|
var skn = $(this).data('skn');
|
|
|
|
|
|
getProductInfo(id, skn).then(res => {
|
|
|
$el.find('.product-detail-info').empty().append(productInfoTpl(res));
|
|
|
});
|
|
|
});
|
|
|
|
|
|
$el.on('click', '.piclist li', function() {
|
|
|
var $this = $(this);
|
|
|
var idx = $(this).index();
|
|
|
|
|
|
$el.find('.detail-bigpic:not(.none) .piclist li').removeClass('active');
|
|
|
$this.addClass('active');
|
|
|
$el.find('.detail-bigpic:not(.none) .bigpic').hide().eq(idx).show();
|
|
|
});
|
|
|
|
|
|
$el.on('click', '.pre, .next', function() {
|
|
|
var $this = $(this);
|
|
|
var $detailBigpic = $this.closest('.detail-bigpic');
|
|
|
var curIndex = Number($detailBigpic.data('_index') || 0);
|
|
|
var $lis = $this.siblings('.con').find('li');
|
|
|
|
|
|
if ($this.hasClass('next')) {
|
|
|
if (curIndex >= $lis.length - 1) {
|
|
|
return false;
|
|
|
}
|
|
|
curIndex++;
|
|
|
} else {
|
|
|
if (curIndex < 1) {
|
|
|
return false;
|
|
|
}
|
|
|
curIndex--;
|
|
|
}
|
|
|
|
|
|
$detailBigpic.data('_index', curIndex);
|
|
|
|
|
|
$lis.removeClass('active').eq(curIndex).addClass('active');
|
|
|
$detailBigpic.find('.bigpic').hide().eq(curIndex).show();
|
|
|
});
|
|
|
|
|
|
$el.on('click', '[data-role=colors] .color', function() {
|
|
|
|
|
|
var $this = $(this);
|
|
|
var idx = $this.index();
|
|
|
var $detail = $this.closest('.detail-goods');
|
|
|
var $sizes = $detail.find('[data-role=sizes] .size-row');
|
|
|
var $detailBigpic = $detail.find('.detail-bigpic');
|
|
|
var $curSize = $sizes.eq(idx);
|
|
|
var $curDetailBig = $detailBigpic.eq(idx);
|
|
|
var bigPicIndex = 0; // 默认显示大图中的第一个图
|
|
|
|
|
|
$curDetailBig.data('_index', bigPicIndex);
|
|
|
|
|
|
$this.siblings('.color').find('p').removeClass('active');
|
|
|
$this.find('p').addClass('active');
|
|
|
|
|
|
$sizes.addClass('none');
|
|
|
$curSize.removeClass('none');
|
|
|
|
|
|
if ($curSize.find('span').length < 2) {
|
|
|
$curSize.find('span:first').addClass('active');
|
|
|
}
|
|
|
|
|
|
$detailBigpic.addClass('none');
|
|
|
$curDetailBig.removeClass('active');
|
|
|
|
|
|
$curDetailBig.find('.bigpic').hide();
|
|
|
$curDetailBig.find('.bigpic').eq(bigPicIndex).show();
|
|
|
|
|
|
$curDetailBig.find('.con li').removeClass('active');
|
|
|
$curDetailBig.find('.con li').eq(bigPicIndex).addClass('active');
|
|
|
|
|
|
$sizes.eq(idx).find('span').each(function() {
|
|
|
if ($(this).hasClass('null-atcivec')) {
|
|
|
$el.find('.addcart').addClass('none');
|
|
|
$el.find('.btn_sellout').removeClass('none');
|
|
|
} else {
|
|
|
$el.find('.addcart').removeClass('none');
|
|
|
$el.find('.btn_sellout').addClass('none');
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
$el.on('click', '[data-role=sizes] .size-row span', function() {
|
|
|
|
|
|
var $this = $(this);
|
|
|
var idx = $this.index();
|
|
|
var shopNumAll = $this.data('num');
|
|
|
|
|
|
$this.siblings('span').removeClass('active');
|
|
|
$this.addClass('active');
|
|
|
|
|
|
if (shopNumAll > 0) {
|
|
|
$el.find('.addcart').removeClass('none');
|
|
|
$el.find('.btn_sellout').addClass('none');
|
|
|
} else {
|
|
|
$el.find('.addcart').addClass('none');
|
|
|
$el.find('.btn_sellout').removeClass('none');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$el.on('click', '.cut, .add', function() {
|
|
|
|
|
|
var $this = $(this);
|
|
|
var $pinfo = $this.closest('.product-detail-info');
|
|
|
|
|
|
// var count = $this.hasClass('minus') ? 'decreaseNum' : 'increaseNum';
|
|
|
var promotionId = $pinfo.data('promotionid');
|
|
|
var $num = $el.find('#num');
|
|
|
var shopNum = Number($num.val() || 1);
|
|
|
|
|
|
if (promotionId) {
|
|
|
if ($this.hasClass('cut')) {
|
|
|
new Alert('-_-,已经是最后一件,不能再减了!').show();
|
|
|
} else {
|
|
|
new Alert('最多只能购买一件,您好像购买的太多了!').show();
|
|
|
}
|
|
|
} else {
|
|
|
if ($this.hasClass('add')) {
|
|
|
shopNum++;
|
|
|
} else {
|
|
|
shopNum--;
|
|
|
}
|
|
|
if (shopNum < 1) {
|
|
|
new Alert('-_-,已经是最后一件,不能在减了!').show();
|
|
|
shopNum = 1;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
$num.val(shopNum);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
$el.on('click', '.addcart', function() {
|
|
|
|
|
|
var $this = $(this);
|
|
|
var $curSize = $el.find('[data-role=sizes] .size-row:not(.none) .active');
|
|
|
var $num = $el.find('#num');
|
|
|
var allNum = $curSize.data('num');
|
|
|
var sku = $curSize.data('sku');
|
|
|
var promotionId = $this.closest('.product-detail-info').data('promotionid') || 0;
|
|
|
var isSwap = $this.closest('.product-detail-info').data('swap');
|
|
|
|
|
|
if ($curSize.length <= 0) {
|
|
|
new Alert('请选择尺码').show();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if ($num.val() > allNum) {
|
|
|
new Alert('库存不足,目前还有' + allNum + '个库存').show();
|
|
|
} else {
|
|
|
/* if (Number($('#addToCart').val()) === 1) {
|
|
|
addcart(dataJSON);
|
|
|
} else {
|
|
|
new Alert('该商品无法加入购物车').show();
|
|
|
}*/
|
|
|
|
|
|
// 替换促销商品
|
|
|
if (isSwap) {
|
|
|
updateCartGiftItem(promotionId, newSkn, sku);
|
|
|
} else {
|
|
|
addcart({
|
|
|
productSku: sku,
|
|
|
buyNumber: $num.val(),
|
|
|
promotionId: promotionId
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function renderAndShowGiftWin(plist) {
|
|
|
|
|
|
var d = new Dialog({
|
|
|
$goodsSelWin.find('.content').empty().html(giftsWinTpl(plist));
|
|
|
$goodsSelWin.show();
|
|
|
|
|
|
/* var d = new Dialog({
|
|
|
content: giftsWinTpl(plist),
|
|
|
className: 'cart-togetherGoods'
|
|
|
});
|
|
|
|
|
|
d.show();
|
|
|
d.show();*/
|
|
|
|
|
|
bindGiftWinAction(d.$el);
|
|
|
// bindGiftWinAction(d.$el);
|
|
|
}
|
|
|
|
|
|
var Cart = {
|
...
|
...
|
@@ -1002,3 +828,194 @@ $('.shop-cart').on('click', giftBtn.join(','), function() { |
|
|
$('.shop-cart').on('click', '[data-role="cart-gift-win"] .close', function() {
|
|
|
$(this).closest('[data-role="cart-gift-win"]').hide();
|
|
|
});*/
|
|
|
|
|
|
|
|
|
var GoodsWinAction = {
|
|
|
closeWin: function() {
|
|
|
// console.log($goodsSelWin);
|
|
|
$goodsSelWin.hide();
|
|
|
},
|
|
|
changeGoods: function() {
|
|
|
|
|
|
var $this = $(this);
|
|
|
var id = $this.data('id');
|
|
|
var skn = $this.data('skn');
|
|
|
|
|
|
$this.sibling('li').removeClass('active');
|
|
|
$this.addClass('active');
|
|
|
|
|
|
getProductInfo(id, skn).then(res => {
|
|
|
$goodsSelWin.find('.product-detail-info').empty().append(productInfoTpl(res));
|
|
|
});
|
|
|
},
|
|
|
selThumb: function() {
|
|
|
var $this = $(this);
|
|
|
var idx = $(this).index();
|
|
|
|
|
|
$goodsSelWin.find('.detail-bigpic:not(.none) .piclist li').removeClass('active');
|
|
|
$this.addClass('active');
|
|
|
$goodsSelWin.find('.detail-bigpic:not(.none) .bigpic').hide().eq(idx).show();
|
|
|
},
|
|
|
selThumbPrevNext: function() {
|
|
|
var $this = $(this);
|
|
|
var $detailBigpic = $this.closest('.detail-bigpic');
|
|
|
var curIndex = Number($detailBigpic.data('_index') || 0);
|
|
|
var $lis = $this.siblings('.con').find('li');
|
|
|
|
|
|
if ($this.hasClass('next')) {
|
|
|
if (curIndex >= $lis.length - 1) {
|
|
|
return false;
|
|
|
}
|
|
|
curIndex++;
|
|
|
} else {
|
|
|
if (curIndex < 1) {
|
|
|
return false;
|
|
|
}
|
|
|
curIndex--;
|
|
|
}
|
|
|
|
|
|
$detailBigpic.data('_index', curIndex);
|
|
|
|
|
|
$lis.removeClass('active').eq(curIndex).addClass('active');
|
|
|
$detailBigpic.find('.bigpic').hide().eq(curIndex).show();
|
|
|
},
|
|
|
selColor: function() {
|
|
|
|
|
|
var $this = $(this);
|
|
|
var idx = $this.index();
|
|
|
var $detail = $this.closest('.detail-goods');
|
|
|
var $sizes = $detail.find('[data-role=sizes] .size-row');
|
|
|
var $detailBigpic = $detail.find('.detail-bigpic');
|
|
|
var $curSize = $sizes.eq(idx);
|
|
|
var $curDetailBig = $detailBigpic.eq(idx);
|
|
|
var bigPicIndex = 0; // 默认显示大图中的第一个图
|
|
|
|
|
|
$curDetailBig.data('_index', bigPicIndex);
|
|
|
|
|
|
$this.siblings('.color').find('p').removeClass('active');
|
|
|
$this.find('p').addClass('active');
|
|
|
|
|
|
$sizes.addClass('none');
|
|
|
$curSize.removeClass('none');
|
|
|
|
|
|
if ($curSize.find('span').length < 2) {
|
|
|
$curSize.find('span:first').addClass('active');
|
|
|
}
|
|
|
|
|
|
$detailBigpic.addClass('none');
|
|
|
$curDetailBig.removeClass('none');
|
|
|
|
|
|
$curDetailBig.find('.bigpic').hide();
|
|
|
$curDetailBig.find('.bigpic').eq(bigPicIndex).show();
|
|
|
|
|
|
$curDetailBig.find('.con li').removeClass('active');
|
|
|
$curDetailBig.find('.con li').eq(bigPicIndex).addClass('active');
|
|
|
|
|
|
$sizes.eq(idx).find('span').each(function() {
|
|
|
if ($(this).hasClass('null-atcivec')) {
|
|
|
$goodsSelWin.find('.addcart').addClass('none');
|
|
|
$goodsSelWin.find('.btn_sellout').removeClass('none');
|
|
|
} else {
|
|
|
$goodsSelWin.find('.addcart').removeClass('none');
|
|
|
$goodsSelWin.find('.btn_sellout').addClass('none');
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
selSize: function() {
|
|
|
|
|
|
var $this = $(this);
|
|
|
|
|
|
// var idx = $this.index();
|
|
|
var shopNumAll = $this.data('num');
|
|
|
|
|
|
$this.siblings('span').removeClass('active');
|
|
|
$this.addClass('active');
|
|
|
|
|
|
if (shopNumAll > 0) {
|
|
|
$goodsSelWin.find('.addcart').removeClass('none');
|
|
|
$goodsSelWin.find('.btn_sellout').addClass('none');
|
|
|
} else {
|
|
|
$goodsSelWin.find('.addcart').addClass('none');
|
|
|
$goodsSelWin.find('.btn_sellout').removeClass('none');
|
|
|
}
|
|
|
},
|
|
|
changeNum: function() {
|
|
|
|
|
|
var $this = $(this);
|
|
|
var $pinfo = $this.closest('.product-detail-info');
|
|
|
|
|
|
// var count = $this.hasClass('minus') ? 'decreaseNum' : 'increaseNum';
|
|
|
var promotionId = $pinfo.data('promotionid');
|
|
|
var $num = $goodsSelWin.find('#num');
|
|
|
var shopNum = Number($num.val() || 1);
|
|
|
|
|
|
if (promotionId) {
|
|
|
if ($this.hasClass('cut')) {
|
|
|
new Alert('-_-,已经是最后一件,不能再减了!').show();
|
|
|
} else {
|
|
|
new Alert('最多只能购买一件,您好像购买的太多了!').show();
|
|
|
}
|
|
|
} else {
|
|
|
if ($this.hasClass('add')) {
|
|
|
shopNum++;
|
|
|
} else {
|
|
|
shopNum--;
|
|
|
}
|
|
|
if (shopNum < 1) {
|
|
|
new Alert('-_-,已经是最后一件,不能在减了!').show();
|
|
|
shopNum = 1;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
$num.val(shopNum);
|
|
|
}
|
|
|
|
|
|
},
|
|
|
add2Cart: function() {
|
|
|
|
|
|
var $this = $(this);
|
|
|
var $curSize = $goodsSelWin.find('[data-role=sizes] .size-row:not(.none) .active');
|
|
|
var $num = $goodsSelWin.find('#num');
|
|
|
var allNum = $curSize.data('num');
|
|
|
var sku = $curSize.data('sku');
|
|
|
var promotionId = $this.closest('.product-detail-info').data('promotionid') || 0;
|
|
|
var isSwap = $this.closest('.product-detail-info').data('swap');
|
|
|
|
|
|
if ($curSize.length <= 0) {
|
|
|
new Alert('请选择尺码').show();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if ($num.val() > allNum) {
|
|
|
new Alert('库存不足,目前还有' + allNum + '个库存').show();
|
|
|
} else {
|
|
|
/* if (Number($('#addToCart').val()) === 1) {
|
|
|
addcart(dataJSON);
|
|
|
} else {
|
|
|
new Alert('该商品无法加入购物车').show();
|
|
|
}*/
|
|
|
|
|
|
// 替换促销商品
|
|
|
if (isSwap) {
|
|
|
updateCartGiftItem(promotionId, newSkn, sku);
|
|
|
} else {
|
|
|
addcart({
|
|
|
productSku: sku,
|
|
|
buyNumber: $num.val(),
|
|
|
promotionId: promotionId
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/** 弹窗事件绑定 **/
|
|
|
$goodsSelWin.on('click', '.close', GoodsWinAction.closeWin);
|
|
|
$goodsSelWin.on('click', '.slide-img .img-list .img-item', GoodsWinAction.changeGoods);
|
|
|
$goodsSelWin.on('click', '.piclist li', GoodsWinAction.selThumb);
|
|
|
$goodsSelWin.on('click', '.pre, .next', GoodsWinAction.selThumbPrevNext);
|
|
|
$goodsSelWin.on('click', '[data-role=colors] .color', GoodsWinAction.selColor);
|
|
|
$goodsSelWin.on('click', '[data-role=sizes] .size-row span', GoodsWinAction.selSize);
|
|
|
$goodsSelWin.on('click', '.cut, .add', GoodsWinAction.changeNum);
|
|
|
$goodsSelWin.on('click', '.addcart', GoodsWinAction.add2Cart); |
...
|
...
|
|