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

    function OEBlack() {
        this.api_url = WAP_APPFILE+'&c=friendblack';
        
        this.id = '';
        this.wake();
        
    }
    OEBlack.prototype = {
        //触发
        wake:function() {
            var _this = this;
            
            //删除
            $(document).on("click", "[f='but_del_black']", function(){
                _this.id = $(this).attr("data-id");
                OEUI.confirm({
                    title: '温馨提示',
                    text: '确定要移除吗？',
                    confirm: function () {
                        _this.submitDel();
                    }
                });
            });
        },
        
        //删除
        submitDel:function() {
            var _this = this;
            var loading = null;
            var timer = setTimeout(function () {
                loading = OEUI.showLoading({
                    type:2
                });
            }, 200);
            
            $.ajax({
                type: "POST",
                url: _this.api_url,
                cache: false,
                data:{
                    a:'del', id:_this.id
                },
                dataType: "json",
                success: function($data) {
                    var $json = eval($data);
                    var $response = $json.response;
                    var $result = $json.result;
                    
                    clearTimeout(timer);
                    loading && loading.hideLoading();
                    timer = null;
                    
                    if ($response == "1") { 
                        OEUI.toast({
                            type: 'bottom',
                            text: '移除成功'
                        });
                        $("#list_"+_this.id).remove();
                    }
                    else {
                        if ($result.length == 0 || $result == '') {
                            $result = '移除失败，请检查';
                        }
                        OEUI.toast({
                            type: 'bottom',
                            text: $result
                        }); 
                    }
                },
                error: function() {
                    clearTimeout(timer);
                    loading && loading.hideLoading();
                    timer = null;
                    OEUI.toast({
                        type: 'bottom',
                        text: '网络繁忙，请稍后再试！'
                    });
                }
            });
                
        }
    }
    new OEBlack();

});