/**
 * [OElove] (C)2010-2099 OElove.com
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 *  Last update 2020-11-11 by OE
*/
$(function(){
    function FriendApply() {
        this.del();
        this.agree();
        this.refuse();
    }
    FriendApply.prototype = {
        //删除
        del: function () {
            $(document).on("click", "[f='but_del']", function(){
                var id = $(this).attr("data-id");
                OEUI.modal.info({
                    title: "温馨提示",
                    text: "确定要删除吗？",
                    confirm: function () {
                        //点击确定
                        $.ajax({
                            type: "POST",
                            url: _OE_FILE + "&c=friendapply",
                            cache: false,
                            data: {
                                a:"delete", 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") {
                                    OEUI.message.msg({text: "删除成功"});
                                    $("#list_"+id).remove();
                                }
                                else {
                                    if (result.length > 0) {
                                        OEUI.message.msg({text: result})
                                    }
                                    else {
                                        OEUI.message.msg({text: "删除失败"})
                                    }
                                }
                            },
                            error: function() {
                                OEUI.message.msg({text: "系统繁忙，请稍后再试"})
                            }
                        });
                    }
                });
            });
        },
        //同意
        agree: function () {
            $(document).on("click", "[f='but_agree']", function(){
                var id = $(this).attr("data-id");
                $.ajax({
                    type: "POST",
                    url: _OE_FILE + "&c=friendapply",
                    cache: false,
                    data: {
                        a:"agree", 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") {
                            OEUI.message.msg({text: "操作成功"})
                            setTimeout(function(){
                                window.location.reload();
                            }, 500);

                        }
                        else {
                            if (result.length > 0) {
                                OEUI.message.msg({text: result})
                            }
                            else {
                                OEUI.message.msg({text: "操作失败"})
                            }
                        }
                    },
                    error: function() {
                        OEUI.message.msg({text: "系统繁忙，请稍后再试"})
                    }
                });


            });
        },
        //拒绝
        refuse: function () {
            $(document).on("click", "[f='but_refuse']", function(){
                var id = $(this).attr("data-id");
                $.ajax({
                    type: "POST",
                    url: _OE_FILE + "&c=friendapply",
                    cache: false,
                    data: {
                        a:"refuse", 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") {
                            OEUI.message.msg({text: "操作成功"})
                            setTimeout(function(){
                                window.location.reload();
                            }, 500);
                        }
                        else {
                            if (result.length > 0) {
                                OEUI.message.msg({text: result})
                            }
                            else {
                                OEUI.message.msg({text: "操作失败"})
                            }
                        }
                    },
                    error: function() {
                        OEUI.message.msg({text: "系统繁忙，请稍后再试"})
                    }
                });

            });
        }
    };
    new FriendApply();
});


