Authored by OF1706

加收藏jia

... ... @@ -107,6 +107,9 @@ GoodsWinAction = {
$goodsSelWin.find('.product-detail-info').empty().append(productInfoTpl(res));
});
$('[data-role="fav-count"]').attr('data-id',id);
},
selThumb: function() {
var $this = $(this);
... ... @@ -233,51 +236,72 @@ GoodsWinAction = {
}
},
toFav: function() {
btnFav: function() {
var favBtn = $('[data-role="fav-count"]');
favBtn.find('.favCount').addClass('coled');
favBtn.mouseover(function(){
$(this).html('取消收藏');
}).click(function(){
favBtn.find('.favCount').removeClass('coled');
});
var id = favBtn.attr('data-id');
var pidArray = [id];
if (favBtn.find('.favCount').hasClass('coled')) {
console.log(888);
$(this).mouseenter(function() {
$(this).html('<i class="favCount iconfont">&#xe68f;</i>收藏商品');
}).mouseleave(function(){
$(this).html('<i class="favCount iconfont">&#xe68f;</i>收藏商品');
}).html('<i class="favCount iconfont">&#xe68f;</i>收藏商品');
$.ajax({
type: 'POST',
url: '/cart/cart/checkFav',
data: {
pidList: pidArray.join(',')
}
}).done(function(result) {
$.each(result.data, function(pid, obj) {
if (obj.code !== 200) {
return false;
}
$.ajax({
type: 'POST',
url: '/cart/index/checkFav',
data: {
pidList: JSON.stringify(selectArray)
}
}).then(function(d) {
var yetCollect = '<span class="cart-yetremove-btn">已收藏</span>';
var collect = '<a href="javascript:void(0);" class="cart-remove-btn"><span>移入收藏</span></a>';
$.each(d.data, function(key, val, index) {
$('.pay-wapper .tr').each(function() {
if (Number($(this).data('pid')) === Number(key)) {
if (val) {
$(this).find('.cart-operation').append(yetCollect);
} else {
$(this).find('.cart-operation').append(collect);
}
if (obj) {
favBtn.html('<i class="favCount iconfont">&#xe68f;</i>收藏商品');
}
});
});
return false;
} else {
console.log(999);
$(this).mouseenter(function() {
$(this).html('<i class="favCount iconfont coled">&#xe68f;</i>取消收藏');
}).mouseleave(function(){
$(this).html('<i class="favCount iconfont coled">&#xe68f;</i>已收藏');
}).html('<i class="favCount iconfont coled">&#xe68f;</i>已收藏');
$.ajax({
type: 'POST',
url: '/cart/cart/checkFav',
data: {
pidList: pidArray.join(',')
}
}).done(function(result) {
$.each(result.data, function(pid, obj) {
if (obj.code !== 200) {
return false;
}
if (obj) {
favBtn.html('<i class="favCount iconfont coled">&#xe68f;</i>已收藏');
}
});
});
var $this = $(this);
var $li = $this.closest('li');
var item = {
product_sku: $li.data('sku'),
buy_number: $li.data('num'),
promotion_id: $li.data('promotionid') || 0
};
capi.cartItemDel(item);
}
});
});
},
add2Cart: function() {
... ... @@ -331,7 +355,7 @@ $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', '.btn-favCount', GoodsWinAction.toFav);
$goodsSelWin.on('click', '.btn-favCount', GoodsWinAction.btnFav);
$goodsSelWin.on('click', '.addcart', GoodsWinAction.add2Cart);
... ...