/**
 * [OElove] (C)2010-2099 oelove.com biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 *  Last update 2020/04/01 by CL 
*/


$(function(){

    //...的操作
	$(document).on("click", "[f='but_hudong']", function(){
        layer.closeAll();
		if ($("#hudong_data").css("display") == "block") {
			$("#hudong_data").slideUp(100);
		}
		else {
			$("#hudong_data").slideDown(100);
		}
	});
    
    $(document).on("mouseover", "[f='but_hudong']", function(){
        layer.tips('点击更多操作', '#but_hudong', {
            tips: [2, '#333'],
            time: 3000
        });
    });
    
	//发送加好友申请
	$(document).on("click", "[f='but_add_friend']", function(){
        var _id = $(this).attr("data-id");
        $.ajax({
            type: "POST",
            url: _ROOT_PATH + "index.php?c=home",
            cache: false,
            data: {a:"apply", id:_id, datatype:"json", r:get_rndnum(8)},
            dataType: "json",
            success: function(data) {
                var json = eval(data);
                var response = json.response;
                var result = json.result;
                if (response == "1") {
                    $("[f='but_add_friend']").addClass("current");
                    $("[f='but_add_friend']").html("<i></i>已发申请");
                    $("[f='but_add_friend']").attr("f", "");
                    layer.msg("已发送申请，请等待对方回应");
                }
                else {
                    
                    //加群 9.09.10
                    if (result == "20") {
                        //跳到着陆页
                        window.location.href = _ROOT_PATH+"index.php?c=qzform&a=land&uid="+_id;
                        return false;
                    }
                    else {
                        if (result.length > 0) {
                            layer.msg(result);
                        }
                        else {
                            layer.msg("操作失败");
                        }
                    }
                    
                }
            },
            error: function() {
                layer.msg("系统繁忙，请稍后再试");
            }
        });
	});
    
    //加入关注/取消关注
    $(document).on("click", "[f='but_add_listen']", function(){
        var _id = $(this).attr("data-id");
        var _ac = $(this).attr("data-ac");
        if (typeof(_ac) == "undefined") {
            _ac = "add";
        }
        
        if (_ac == "add") {
            var _url = _ROOT_PATH + "index.php?c=home&a=addlisten";
        }
        else {
            var _url = _ROOT_PATH + "index.php?c=home&a=dellisten";
        }
        $.ajax({
            type: "POST",
            url: _url,
            cache: false,
            data: {id:_id, datatype:"json", r:get_rndnum(8)},
            dataType: "json",
            success: function(data) {
                var json = eval(data);
                var response = json.response;
                var result = json.result;
                if (response == "1") {
                    if (_ac == "add") {
                        layer.msg("已喜欢");
                        $("[f='but_add_listen']").addClass("current");
                        $("[f='but_add_listen']").html("<i class='icon_2'></i><font color='#999'>已喜欢</font>");
                        $("[f='but_add_listen']").attr("data-ac", "del");
                    }
                    else {
                        layer.msg("取消成功");
                        $("[f='but_add_listen']").removeClass("current");
                        $("[f='but_add_listen']").html("<i class='icon_2'></i>喜欢");
                        $("[f='but_add_listen']").attr("data-ac", "add");
                    }
                }
                else {
                    if (result.length > 0) {
                        layer.msg(result);
                    }
                    else {
                        layer.msg("操作失败");
                    }
                }
            },
            error: function() {
                layer.msg("系统繁忙，请稍后再试");
            }
        });
            
    });

	//诚信查询 iframe
    $(document).on("click", "[f='but_view_rpzy']", function(){
        var home_uid = $(this).attr("data-uid");
        var width = $(this).attr("data-width");
        if (typeof(width) == "undefined") {
            width = 400; //9.04.23
        }
        var height = $(this).attr("data-height");
        if (typeof(height) == "undefined") {
            height = 400;
        }
        layer.open({
            title:"诚信查询",
            type: 2,
            area: [''+width+'px', ''+height+'px'],
            shadeClose: true,
            resize: false,
            scrollbar: false,
            content: _ROOT_PATH+"index.php?c=home&a=viewcredit&id="+home_uid+"&r="+get_rndnum(8)
        });
    });
    
    //委托红娘
    $(document).on("click", "[f='but_add_hn_serv']", function(){
        var _type = $(this).attr("data-type");
        if (typeof(_type) == "undefined") {
            _type = "3";
        }
        var _relid = $(this).attr("data-relid");
        if (_relid.length == 0) {
            layer.msg("委托关联信息不能为空");
			return false;
        }
        var demand = "进一步了解";

        var obj_id = $(this).attr("id");
        $("#"+obj_id).attr("f", "");
        
		$.ajax({
			type: "POST",
			url: _ROOT_PATH + "index.php?c=lineserv",
			cache: false,
			data: {
				a:"saveentrust", linetype:_type, relid:_relid, demand:demand, r:get_rndnum(8)
			},
			dataType: "json",
			success: function(data) {
				var json = eval(data);
				var response = json.response;
				var result = json.result;
				if (response == "1") {
                    layer.msg("委托申请成功，请等待审核！");
                    $("#"+obj_id).addClass("current");
				}
				else {
					if (result.length > 0) {
						layer.msg(result);
					}
					else {
						layer.msg("申请失败");
					}
                    $("#"+obj_id).attr("f", "but_add_hn_serv");
				}
			},
			error: function() {
				layer.msg("系统繁忙，请稍后再试");
                $("#"+obj_id).attr("f", "but_add_hn_serv");
			}
		});
        
    });
    
    
    //查看某项-登录帐号未设置提示
    $(document).on("click", "[f='but_open_profile_tips']", function(){
        
        layer.confirm("对不起，你当前资料项未设置<br />无法查看会员的信息，请先编辑。", {
            title: "温馨提示",
            btn: ['去编辑', '知道了']
        }, 
        
        function(){
            //点击确定
            window.location.href = _ROOT_PATH+"index.php?m=user&c=profile&nofollow=1";
        }, 
        
        function(){
            //点击知道了.
        }
        
        );
        
    });
    
    //已设置保密...
    $(document).on("click", "[f='but_secret_tips']", function(){
        layer.tips('该会员联系方式已设置保密<br />你可以通过私信跟TA取得联系。', '#but_view_contact', {
            tips: [1, '#333'],
            time: 3000
        });
        
    });
    
    //查看联系方式
    $(document).on("click", "[f='but_view_contact']", function(){
        var _uid = $(this).attr("data-id");
        var width = $(this).attr("data-width");
        if (typeof(width) == "undefined") {
            width = 500;
        }
        var height = $(this).attr("data-height");
        if (typeof(height) == "undefined") {
            height = 500;
        }
        
        $.ajax({
			type: "POST",
			url: _ROOT_PATH + "index.php?c=view",
			cache: false,
			data: {
				a:"contact", id:_uid, r:get_rndnum(8)
			},
			dataType: "json",
			success: function(data) {
				var json = eval(data);
				var response = json.response;
				var result = json.result;
				if (response == "1") {
                    _viewContact(_uid, width, height);
				}
				else if (response == '2') {
                    //没有权限
                    _tipsNoPower(_uid);                    
				}
                else if (response == '3') {
                    //需支付
                    _tipsPayView(_uid, result);
                }
                else if (response == '4') {
                    _tipsNoDayViews(_uid);
                }
                else if (response == '12') {
                    _tipsShowKefu(); //9.04.25
                }
                else {
                    //加群 9.09.10
                    if (result == "20") {
                        //跳到着陆页
                        window.location.href = _ROOT_PATH+"index.php?c=qzform&a=land&uid="+_uid;
                        return false;
                    }
                    else {
                        if (result.length == 0) {
                            layer.msg("查看失败，请检查权限");
                        }
                        else {
                            layer.msg(result);
                        }
                    }
                }
			},
			error: function() {
				layer.msg("系统繁忙，请稍后再试");
			}
		});

    });

    //没有权限提醒 8.07.03
    $(document).on("click", "[f='but_nopower_tips']", function(){
        var _uid = $(this).attr("data-id");
        _tipsNoPower(_uid);        
    });

    //屏蔽会员... 9.04.23
    $(document).on("click", "[f='but_do_black']", function(){
        var login_status = $(this).attr("data-loginstatus");
        if (typeof(login_status) == "undefined") {
            login_status = 0;
        }
        if (login_status  == "0") {
            _jdLogin2();
            return false;
        }
        var type = $(this).attr("data-type");
        if (typeof(type) == "undefined") {
            type = "add";
        }
        var homeuid = $(this).attr("data-homeuid");
        
        if (type == "add") {
            layer.confirm("将TA屏蔽后，TA不能再对你发起任何互动，TA将进入你的黑名单", {
                    title: "温馨提示",
                    btn: ['确认', '取消']
                }, 
            
                function(){
                    //点击确定
                    _doBlackUser(homeuid, type);
                }, 
            
                function(){
                    //点击取消.
                }
            
            );
        }
        else {
            _doBlackUser(homeuid, type);
        }
        
    });
    
});

/**
 * //屏蔽会员 9.04.23
 * @param:: int homeuid 会员UID
 * @param:: string type 类型 add/cancel
*/
function _doBlackUser(homeuid, type) {
    $.ajax({
        type: "POST",
        url: _ROOT_PATH + "index.php?c=home",
        cache: false,
        data: {
            a:"doblack", homeuid:homeuid, type:type, r:get_rndnum(8)
        },
        dataType: "json",
        success: function(data) {
            var json = eval(data);
            var response = json.response;
            var result = json.result;
            if (response == "1") {
                if (type == "add") {
                    layer.msg("屏蔽成功");
                }
                else {
                    layer.msg("已取消屏蔽");
                }
                setTimeout(function(){
                    window.location.reload();
                }, 600);
            }
            else {
                if (result.length > 0) {
                    layer.msg(result);
                }
                else {
                    layer.msg("操作失败，请检查");
                }
            }
        },
        error: function() {
            layer.msg("系统繁忙，请稍后再试");
        }
    });
}

//查看... 9.04.10
function _viewContact(uid, width, height) {
    if (typeof(width) == "undefined") {
        width = 500;
    }
    if (typeof(height) == "undefined") {
        height = 500;
    }
    
    layer.open({
        title:"查看联系方式",
        type: 2,
        area: [''+width+'px', ''+height+'px'],
        shadeClose: false,
        resize: false,
        scrollbar: false,
        content: [_ROOT_PATH+'index.php?c=view&a=contact&id='+uid+'&needup=1&r='+get_rndnum(8), 'no']
    });
}

//没有权限...
function _tipsNoPower(uid) {
    layer.confirm("你没有权限执行此操作，请先升级会员",
        {
            title: "温馨提示",
            btn: ['去升级', '知道了']
        }, 
        
        function(){
            //升级...
            var back_url = _ROOT_PATH+"index.php?c=home&a=detail&id="+uid;
            window.location.href = _ROOT_PATH+"index.php?m=user&c=vip&fromurl="+encodeURIComponent(back_url);
        }, 
        
        function(){
            //知道了...
        }
    );
  
}

//当天次数已满...
function _tipsNoDayViews(uid) {
    layer.confirm("查看次数已用完<br />请升级VIP或明日再查看", 
        {
            title: "温馨提示",
            btn: ['立即升级', '知道了']
        }, 
        
        function(){
            //升级...
            var back_url = _ROOT_PATH+"index.php?c=home&a=detail&id="+uid;
            window.location.href = _ROOT_PATH+"index.php?m=user&c=vip&fromurl="+encodeURIComponent(back_url);
        }, 
        
        function(){
            //知道了...
        }
    );
}

//支付...
function _tipsPayView(uid, fee) {
    var money_name = $("#moneyname").val();
    if (typeof(money_name) == "undefined") {
        money_name = "金币";
    }
    //9.04.26
    layer.confirm("需要支付 <font color='red'>"+fee+"</font> "+money_name+"才可以查看", 
        {
            title: "温馨提示",
            btn: ['立即支付', '知道了']
        }, 
        
        function(){
            //支付...
            $.ajax({
                type: "POST",
                url: _ROOT_PATH + "index.php?c=view",
                cache: false,
                data: {
                        a:"paycontact", id:uid, r:get_rndnum(8)
                },
                dataType: "json",
                success: function(data) {
                    var json = eval(data);
                    var response = json.response;
                    var result = json.result;
                    if (response == "1") {
                        layer.closeAll();
                        //余额支付...
                        _viewContact(uid);
                    }
                    else if (response == "2") {
                        //在线支付...
                        window.location.href = _ROOT_PATH+"index.php?c=pay&paynum="+result;
                    }
                    else {
                        if (result.length > 0) {
                            layer.msg(result);
                        }
                        else {
                            layer.msg("支付失败，请检查");
                        }
                    }
                },
                error: function() {
                    layer.msg("系统繁忙，请稍后再试");
                }
            });
        }, 
        
        function(){
            //知道了...
        }
    );
}


//发送微信浏览提醒...
function _sendWxVisitTip(uid) {
    $.ajax({
        type: "POST",
        url: _OE_FILE +"?c=home",
        cache: false,
        data: {
            a:"sendwxtip", uid:uid, r:get_rndnum(8)
        },
        dataType: "json",
        success: function(data) {
            var json = eval(data);
            var response = json.response;
            var result = json.result;
            if (response == '1') {

            }
            else {
            }
        },
        error: function() {

        }
    });
}

//显示客服...9.04.25
function _tipsShowKefu() {
    $.ajax({
        type: "POST",
        url: _ROOT_PATH + "index.php?c=ajax",
        cache: false,
        data: {
                a:"kefu", r:get_rndnum(8)
        },
        dataType: "json",
        success: function(data) {
            var json = eval(data);
            var response = json.response;
            var result = json.result;
            if (response == "1") {
                $("#kefu_data").html(result);
                $("#kefu_box").show();
            }
            else {
                layer.msg("该会员已隐藏联系方式，请与网站客服联系");
            }
        },
        error: function() {
            layer.msg("该会员已隐藏联系方式，请与网站客服联系");
        }
    });
}
$(function(){
   $(document).on("click", "[f='but_close_kefu']", function(){
       $("#kefu_box").hide();
   });
});