/**
 * [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 OEMsgContact() {
        this.api_url = WAP_APPFILE+'&c=msgcontact';
        
        this.id = '';
        this.wake();
        
    }
    OEMsgContact.prototype = {
        //触发
        wake:function() {
            var _this = this;
            
            //删除
            $(document).on("click", "[f='but_del_contact']", 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:'remove', 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 OEMsgContact();

});