/**
 * [OElove] (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
 *  Last update 2020-11-11 by OE 
 */
$(function () {
    function TongYong() {
        this.chat();//初始化窗口的聊天数据
    }
    TongYong.prototype = {
        //聊天
        chat: function () {
            //触发打开聊天窗口
            var _this = this;
            $(document).on("click", "[f='pop_jdchat']", function(){
                var touid = $(this).attr("data-touid");
                if (typeof(touid) == "undefined") {
                    touid = "";
                    OEUI.message.msg({text: "请指定聊天会员"});
                    return false;
                }
                if (_LOGIN_STATUS == 0) {
                    _this.jdLogin2();
                    return false;
                }

                var width = $(this).attr("data-width");
                if (typeof(width) == "undefined") {
                    width = 680;
                }
                var height = $(this).attr("data-height");
                if (typeof(height) == "undefined") {
                    height = 560;
                }

                _jdChat(touid, width, height);
            });
            //打开聊天窗
            function _jdChat(touid, width, height) {
                if (typeof(width) == "undefined") {
                    width = 600;
                }
                if (typeof(height) == "undefined") {
                    height = 500;
                }

                //获取sid...
                $.ajax({
                    type: "POST",
                    url: _ROOT_PATH + "index.php?m=user",
                    cache: false,
                    data: {
                        c:"msgchat", a:"setsid", touid:touid, 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.modal.dialog({
                                type: "iframe",
                                title: "发私信...",
                                width: width,
                                height: height,
                                content: _ROOT_PATH+"index.php?m=user&c=msgchat&sid="+result+"&r="+get_rndnum(8)
                            });
                        }
                        else if (response == "2") {
                            OEUI.modal.info({
                                title: "温馨提示",
                                text: "你的资料审核中或审核不通过",
                                confirmText: "去修改",
                                cancelText: "知道了",
                                confirm: function () {
                                    window.parent.top.location.href = _ROOT_PATH+"index.php?m=user&c=profile";
                                }
                            });
                        }
                        else if (response == "3") {
                            OEUI.modal.info({
                                title: "温馨提示",
                                text: "你的头像未上传或审核不通过",
                                confirmText: "去设置",
                                cancelText: "知道了",
                                confirm: function () {
                                    window.parent.top.location.href = _ROOT_PATH+"index.php?m=user";
                                }
                            });
                        }
                        else if (response == "4") {
                            OEUI.modal.info({
                                title: "温馨提示",
                                text: "你的手机还未认证，请先认证",
                                confirmText: "去认证",
                                cancelText: "知道了",
                                confirm: function () {
                                    window.parent.top.location.href = _ROOT_PATH+"index.php?m=user&c=rz";
                                }
                            });
                            return false;
                        }
                        else {
                            //9.04.23 其他提示
                            if (result.length > 0) {
                                OEUI.message.msg({text: result});
                            }
                            else {
                                OEUI.message.msg({text: "系统繁忙，请稍后再试"});
                            }
                        }
                    },
                    error: function() {

                    }
                });
            }
        },
        //打开登录页
        jdLogin2: function (width, height) {
            if (typeof(width) == "undefined") {
                width = 420;
            }
            if (typeof(height) == "undefined") {
                height = 456;
            }

            if (_CONNET_LOGIN == 1) {
                height = 522;
            }
            OEUI.modal.dialog({
                type: "iframe",
                title: "",
                width: width,
                height: height,
                content: _ROOT_PATH+'index.php?c=passport&a=jdlogin&r='+get_rndnum(8)
            });
        }
    };
    new TongYong();
});