favorite.js 990 Bytes
/**
 * 品牌或店铺收藏
 * @author: jiangfeng<jeff.jiang@yoho.cn>
 * @date: 16/7/19
 */

function _favBack(data) {
    if (data && data.code === 200) {
        $('#brand-fav').toggleClass('coled');
    } else if (data && data.data && data.data.refer) {
        location.href = data.data.refer;
    }
}

function _favShop(shopId, isAdd) {
    $.post('/product/shop/togglecollect', {shopId: shopId, type: isAdd ? '' : 'add'}, function(data) {
        _favBack(data);
    });
}

function _favBrand(brandId, isAdd) {
    $.post('/product/brand/togglecollect', {brandId: brandId, type: isAdd ? '' : 'add'}, function(data) {
        _favBack(data);
    });
}

$('#brand-fav').click(function() {
    var shopId = $(this).parents('.brand-banner').data('shop');
    var brandId = $(this).parents('.brand-banner').data('brand');
    var isAdd = $(this).hasClass('coled');

    if (shopId) {
        _favShop(shopId, isAdd);
    } else if (brandId) {
        _favBrand(brandId, isAdd);
    }
});