﻿//获取用户事件
var GetUserEvent = function () {
    $.ajax({
        url: '/UserCenter/ajax/MyAttention_GetUserInfo_ajax.aspx',
        type: 'post',
        datatype: 'json',
        data: { uidlist: _userList.idlist, rand: Math.random() },
        error: function () { return false;  },
        success: function (json) {
            if (json.status == 'succeed') {
                var data = json.data;
                for (var i = 0; i < data.length; i++) {
                    var $fans = $("#fans_" + data[i].uid);
                    var $add = $("#add_" + data[i].uid);
                    var $art = $("#article_" + data[i].uid);
                    var $avator = $("#avator_" + data[i].uid);
                    $fans.html(data[i].myfans);
                    $add.html(data[i].add);
                    $art.html(data[i].art);
                    $avator.attr('src', data[i].avator);
                }
            }
            else {
                return false;
            }
        }
    });
}
//取消关注
var CancelAttention = function (sourceid, sourcetype) {
    var $targetdom = $("#attention_" + sourceid);
    
    var dialog = art.dialog({ id: 'N3610', title: "正在提交请求，请稍等.." });
    $.ajax({
        url: 'ajax/MyAttention_Cannel_ajax.aspx',
        type: 'post',
        datatype: 'json',
        data: { sid: sourceid, t: sourcetype, rand: Math.random() },
        error: function () { dialog.title('操作失败').content('链接服务器超时'); },
        success: function (json) {
            //json = eval('(' + json + ')');
            if (json.status == 'succeed') {
                dialog.title('操作成功').content(json.message);
                $targetdom.remove();
            }
            else {
                dialog.title('操作失败').content(GetErrorDetail(json.errorid));
            }
        }
    });
};
//添加关注
var AddAttention = function (sourceid, sourcetype) {
    var $attbtn = $("#attentionevent");
    var $attstatus = $("#attstatus");

    var dialog = art.dialog({ id: 'N3610', title: "正在提交请求，请稍等.." });
    $.ajax({
        url: '/UserCenter/ajax/MyAttention_Add_ajax.aspx',
        type: 'post',
        datatype: 'json',
        data: { sid: sourceid, t: sourcetype, rand: Math.random() },
        error: function () { dialog.title('操作失败').content('链接服务器超时'); },
        success: function (json) {
            //json = eval('(' + json + ')');
            if (json.status == 'succeed') {
                dialog.title('操作成功').content(json.message);
                $attbtn.html('取消');
                $attbtn.css('color', '#f3a7a9');
                $attstatus.html('√ 已关注');
                $attstatus.css('color', 'red');
            }
            else {
                dialog.title('操作失败').content(GetErrorDetail(json.errorid));
            }
        }
    });
};
//添加关注
var AddAttentionForSalonInfo = function (sourceid, sourcetype) {
    var $attbtn = $("#attentionBtn");
    var $attstatus = $("#attstatus");

    var dialog = art.dialog({ id: 'N3610', title: "正在提交请求，请稍等.." });
    $.ajax({
        url: '/UserCenter/ajax/MyAttention_Add_ajax.aspx',
        type: 'post',
        datatype: 'json',
        data: { sid: sourceid, t: sourcetype, rand: Math.random() },
        error: function () { dialog.title('操作失败').content('链接服务器超时'); },
        success: function (json) {
            if (json.status == 'succeed') {
                dialog.title('操作成功').content(json.message);
                $attbtn.html('取消关注');
                $attstatus.html($attstatus.html()-0+1);
                $attstatus.css('color', 'red');
            }
            else {
                dialog.title('操作失败').content(GetErrorDetail(json.errorid));
            }
        }
    });
};
//取消关注
var CancelAttentionForSalonInfo = function (sourceid, sourcetype) {
    var $attbtn = $("#attentionBtn");
    var $attstatus = $("#attstatus");

    var dialog = art.dialog({ id: 'N3610', title: "正在提交请求，请稍等.." });
    $.ajax({
        url: '/UserCenter/ajax/MyAttention_Cannel_ajax.aspx',
        type: 'post',
        datatype: 'json',
        data: { sid: sourceid, t: sourcetype, rand: Math.random() },
        error: function () { dialog.title('操作失败').content('链接服务器超时'); },
        success: function (json) {
            if (json.status == 'succeed') {
                dialog.title('操作成功').content(json.message);
                $attbtn.html('+ 关注');
                $attstatus.html($attstatus.html() - 1);
                $attstatus.css('color', '#999');
            }
            else {
                dialog.title('操作失败').content(GetErrorDetail(json.errorid));
            }
        }
    });
};
//添加关注
var AddAttentionForIndexDaren = function (sourceid, sourcetype) {
    var $attbtn = $("#daren_" + sourceid);

    var dialog = art.dialog({ id: 'N3610', title: "正在提交请求，请稍等.." });
    $.ajax({
        url: '/UserCenter/ajax/MyAttention_Add_ajax.aspx',
        type: 'post',
        datatype: 'json',
        data: { sid: sourceid, t: sourcetype, rand: Math.random() },
        error: function () { dialog.title('操作失败').content('链接服务器超时'); },
        success: function (json) {
            if (json.status == 'succeed') {
                dialog.title('操作成功').content(json.message);
                $attbtn.html('√ 已关注');
                $attbtn.attr("onclick", "");
                $attbtn.css('color', '#f3a7a9');
            }
            else {
                dialog.title('操作失败').content(GetErrorDetail(json.errorid));
            }
        }
    });
};
//取消关注
var CancelAttentionForDongtai = function (sourceid, sourcetype) {
    var $attbtn = $("#attentionevent");
    var $attstatus = $("#attstatus");

    var dialog = art.dialog({ id: 'N3610', title: "正在提交请求，请稍等.." });
    $.ajax({
        url: 'ajax/MyAttention_Cannel_ajax.aspx',
        type: 'post',
        datatype: 'json',
        data: { sid: sourceid, t: sourcetype, rand: Math.random() },
        error: function () { dialog.title('操作失败').content('链接服务器超时'); },
        success: function (json) {
            //json = eval('(' + json + ')');
            if (json.status == 'succeed') {
                dialog.title('操作成功').content(json.message);
                $attbtn.html('+ 关注');
                $attbtn.css('color', 'red');
                $attstatus.html('未关注');
                $attstatus.css('color', '#999');
            }
            else {
                dialog.title('操作失败').content(GetErrorDetail(json.errorid));
            }
        }
    });
};
//取消关注
var CancelAttentionForFans = function (sourceid, sourcetype) {
    var $targetdom = $("#cancel_" + sourceid);
    var $friend = $("#f_" + sourceid);
    var dialog = art.dialog({ id: 'N3610', title: "正在提交请求，请稍等.." });
    $.ajax({
        url: 'ajax/MyAttention_Cannel_ajax.aspx',
        type: 'post',
        datatype: 'json',
        data: { sid: sourceid, t: sourcetype, rand: Math.random() },
        error: function () { dialog.title('操作失败').content('链接服务器超时'); },
        success: function (json) {
            //json = eval('(' + json + ')');
            if (json.status == 'succeed') {
                dialog.title('操作成功').content(json.message);
                //$targetdom.remove();
                $targetdom.hide(2);
                $friend.attr('src', '/UserCenter/images/pic_45_2.jpg');
            }
            else {
                dialog.title('操作失败').content(GetErrorDetail(json.errorid));
            }
        }
    });
};
var ShowPic = function (src) {
    var dialog = art.dialog({ id: 'N3690', titil: '查看大图', content: '<img src="' + src + '"/>' });
};
//错误事件列表
var GetErrorDetail = function (errid) {
    switch (errid) {
        case '1001':
            return '您还没有登录，请登录后再试';
            break;
        case '1002':
            return '操作失败，您提交的参数有误';
            break;
        case '1003':
            return '操作失败，您提交的参数中有不安全字符';
            break;
        case '1004':
            return '操作失败，取消订单时出现未知错误';
            break;
        case '1005':
            return '操作失败，自己不能关注自己';
            break;
        case '2004':
            return '操作失败，添加关注时出现未知错误';
            break;
        case '3004':
            return '操作失败，添加留言时出现未知错误';
            break;
    }
}
