favorite.js 1.07 KB
/**
 * 品牌或店铺收藏
 * @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 $banner = $(this).parents('.brand-banner');
    var shopId = $banner.data('shop');
    var brandId = $banner.data('brand');
    var type = $banner.data('type');
    var isAdd = $(this).hasClass('coled');

    if (type === 'shop') {
        _favShop(shopId, isAdd);
    } else if (type === 'brand') {
        _favBrand(brandId, isAdd);
    } else {
        _favBrand(brandId, isAdd);
    }
});