/**
 * [OElove webapp] (C)2010-2099 oelove.com Inc.biz
 * Email: service@phpcoo.com，phpcoo@qq.com
 * This is not a freeware, use is subject to license terms
 * $ LastTime 2020.05.30 Update by OE/CL $
*/
var _inst_oechat_dialog = null;
$(function(){
    //聊天弹窗
    function OEChatDialog() {
        this.api_url = WAP_APPFILE + "&c=msgchat";
        this.chat_sid = ''; //通信SID
        this.chat_uid = ''; //聊天会员UID
        this._chat_dialog = null;
        this.slide_time = 200;
        
        this.initChat();
        this.wake();
    }
    
    OEChatDialog.prototype = {
        //初始化
        initChat:function() {
            var _this = this;
            
            _this.chat_sid = $("#sid").val();
            _this.chat_uid = $("#chat_uid").val();
            
            setTimeout(function(){
                
                $.ajax({
                    type: "POST",
                    url: _this.api_url,
                    cache: false,
                    data: {
                        a:'initcheck', buid:_this.chat_uid
                    },
                    dataType: "json",
                    success: function($data) {
                        var $json = eval($data);
                        
                        var $response = $json.response;
                        var $result = $json.result;
                        
                        if ($response == '1') {
                            //没有动作
                        }
                        //2020.05.29
                        else if ($response == '2') {

                        }
                        else {
                            //有动作
                            if ($result == '1') {
                                //VIP提示
                                _this.openDialog('vip', '2'); //0.05.30
                            }
                            else if ($result == '2') {
                                //VIP+付费
                                $("#double_tips_1").show();
                                $("#double_tips_2").hide();
                                _this.openDialog('double', '2'); //0.05.30
                            }
                        }
                    },
                    error: function() {
                    
                    }
                });
                
            }, 100);
            
        },
        
        //触发
        wake:function() {
            var _this = this;
            
            //关闭弹窗
            $(document).on("click", "[f='close_chat_dialog']", function(){
                var $url = $(this).attr("data-url");
                if (typeof($url) == 'undefined') {
                    $url = '';
                }
                if ($url != '') {
                    _this._chat_dialog.hide(function(){
                        setTimeout(function(){
                            window.location.href = $url;
                        }, 50);
                    });
                }
                else {
                    _this.closeDialog();
                }
            });
            
            //升级VIP
            $(document).on("click", "[f='but_go_vip']", function(){
                var $forward = _this.api_url+"&sid="+_this.chat_sid+"&nofollow=1";
                _this._chat_dialog.hide(function(){
                    setTimeout(function(){
                        window.location.href = WAP_APPFILE+"&c=vip&from=chat&forward="+encodeURIComponent($forward);
                    }, 50);
                });
            });
            
            //弹窗帮TA或自己解锁
            $(document).on("click", "[f='but_help']", function(){
                $("#double_tips_1").show();
                $("#double_tips_2").hide();
                _this.openDialog('double');
            });
        },
        
        //弹窗提示 0.05.30
        openDialog:function($dialog, $type) {
            $type || ($type = '1');
            var _this = this;
            _this._chat_dialog = OEUI.Dialog({
                el: '#'+$dialog+'_dialog',
                animated: 'zoomIn',
                time:_this.slide_time,
                type: $type
            }); 
        }, 
        //关闭弹窗
        closeDialog:function() {
            var _this = this;
            if (_this._chat_dialog) {
                _this._chat_dialog.hide();
            }
        }
        
    }
    
    _inst_oechat_dialog = new OEChatDialog();
    
});