brand.js 1.65 KB
/**
 * 品牌页面
 * @auhtor: bikai<kai.bi@yoho.cn>
 * @date: 2016/1/21
 */

var $ = require('yoho-jquery');

var $brandFavor = $('#brand-favor'),
    $shopFavor = $('#shop-favor'),
    shopId = $shopFavor.data('id'),
    id = $brandFavor.data('id'),
    isFavorite = $shopFavor.find('i').hasClass('coled');

/**
 * 品牌收藏
 */
$brandFavor.on('click', function() {
    $.ajax({
        type: 'post',
        url: '/product/index/favoriteBrand',
        data: {
            brandId: id
        }
    }).then(function(res) {
        if (res.code === 200) {
            $brandFavor.find('i').toggleClass('coled');
        } else if (res.code === 403) {
            location.href = '//www.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href);
        }
    });
});

/**
 * 店铺收藏
 */
$shopFavor.on('click', function() {
    $.ajax({
        type: 'post',
        url: '/product/index/favoriteShop',
        data: {
            isFavorite: isFavorite ? 0 : 1,
            shopId: shopId
        }
    }).then(function(res) {
        if (res.code === 200) {
            $shopFavor.find('i').toggleClass('coled');
        } else if (res.code === 403) {
            location.href = '//www.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href);
        }
    });
});

// 页面进入更新收藏状态
$.ajax({
    type: 'POST',
    url: '/product/index/isFavoriteBrand',
    data: {
        brandId: id
    }
}).then(function(data) {
    if (data.code === 200) {

        // 已收藏
        $brandFavor.find('i').addClass('coled');
    } else if (data.code === 404) {

        // 未收藏
        $brandFavor.find('i').removeClass('coled');
    }
});