list-common.js 1.8 KB
/**
 * 星潮教室-列表公共部分
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/6/7
*/

var $ = require('yoho-jquery'),
    tip = require('../plugin/tip');

require('../common');

// 星搭配收藏请求
$(document).on('click', '.collection', function() {
    var $that = $(this),
        $icon = $that.find('.collected-ico');

    var type;

    if ($icon.hasClass('collected')) {
        type = 'del';
    } else {
        type = 'fav';
    }


    $.ajax({
        type: 'POST',
        url: '/guang/star/setFavorite',
        data: {
            articleId: $that.parents('li').attr('articleId'),
            type: type
        },
        success: function(data) {
            var code = data.code;

            if (code === 200) {
                if ($icon.hasClass('collected')) {
                    $icon.removeClass('collected');
                } else {
                    $icon.addClass('collected');
                }

            }

            if (code === 401) {
                if ($('#collocation-link').length <= 0) {
                    $('body').append('<a href=\'' + data.data + '\' style="display:none;" id="collocation-link">' +
                    '<span class="collocation-link"></span></a>');
                }

                $('.collocation-link').click();
            }
        },
        error: function() {
            tip.show('网络断开连接了~');
        }
    });
});

// 分享成功
window.successShare = function() {
    $.ajax({
        type: 'POST',
        url: '/guang/starclass/forward',
        success: function(data) {
            var code = data.code;

            if (code === 200 && data.data > 0) {
                tip.show('分享成功,亲密度+10');
            }
        },
        error: function() {
            tip.show('网络断开连接了~');
        }
    });
};