/**
 * [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 2019/09/10 by OE $
*/
/* 通用弹窗..for LAYUI */

$(function(){
    
    //jd登录框 弹出 iframe
	$(document).on("click", "[f='pop2_jdlogin']", function(){
		$width = $(this).attr("data-width");
		if (typeof($width) == "undefined") {
			$width = 420;
		}
		$height = $(this).attr("data-height");
		if (typeof($height) == "undefined") {
			$height = 522;
		}
		if (_CONNET_LOGIN == 1) {
			$height = 522;
		}
		_jdLogin2($width, $height);
	
	});
    $(document).on("click", "[f='pop_jdlogin']", function(){
		$width = $(this).attr("data-width");
		if (typeof($width) == "undefined") {
			$width = 420;
		}
		$height = $(this).attr("data-height");
		if (typeof($height) == "undefined") {
			$height = 456;
		}
		if (_CONNET_LOGIN == 1) {
			$height = 522;
		}
		_jdLogin2($width, $height);
	
	});
    
    //jd聊天框 弹出 iframe
    $(document).on("click", "[f='pop_jdchat']", function(){
        $touid = $(this).attr("data-touid");
        if (typeof($touid) == "undefined") {
            $touid = "";
            layer.msg("请指定聊天会员");
            return false;
        }
        $_login_status = $(this).attr("data-loginstatus");
        if (typeof($_login_status) == "undefined") {
            $_login_status = "1";
        }
        if ($_login_status == "0") {
            _jdLogin2();
            return false;
        }
        
		$width = $(this).attr("data-width");
		if (typeof($width) == "undefined") {
			$width = 680;
		}
		$height = $(this).attr("data-height");
		if (typeof($height) == "undefined") {
			$height = 560;
		}
        
		_jdChat($touid, $width, $height);
	});
    //jd聊天框 弹出 iframe 兼容v4版本标签
    $(document).on("click", "[f='pop_send_msg']", function(){
        $touid = $(this).attr("data-touid");
        if (typeof($touid) == "undefined") {
            $touid = "";
            layer.msg("请指定聊天会员");
            return false;
        }
        $_login_status = $(this).attr("data-loginstatus");
        if (typeof($_login_status) == "undefined") {
            $_login_status = "1";
        }
        if ($_login_status == "0") {
            _jdLogin2();
            return false;
        }
        
		$width = $(this).attr("data-width");
		if (typeof($width) == "undefined") {
			$width = 600;
		}
		$height = $(this).attr("data-height");
		if (typeof($height) == "undefined") {
			$height = 500;
		}
		_jdChat($touid, $width, $height);
	});
    

    //留言反馈 弹出 iframe 8.05.04
    $(document).on("click", "[f='pop2_guestbook']", function(){
        $width = $(this).attr("data-width");
        if (typeof($width) == "undefined") {
            $width = 800;
        }
        $height = $(this).attr("data-height");
        if (typeof($height) == "undefined") {
            $height = 550;
        }
        layer.open({
            title:'留言反馈',
            type: 2,
            area: [''+$width+'px', ''+$height+'px'],
            shadeClose: true,
            scrollbar: false,
            content: _ROOT_PATH+"index.php?c=index&a=guestbook&r="+get_rndnum(8)
        });
    });
    //选择留言分类 8.05.04
    $(document).on("click", "[f='but_sel_bookcat']", function(){
        $_catid = $(this).attr("data-catid");
        $("[f='but_sel_bookcat']").removeClass("current");
        $(this).addClass("current");
        $("#book_catid").val($_catid);
    });
    //上传留言图片 8.05.04
    $(document).on("change", "#upload_book_img", function(){
        $book_imgnum = parseInt($("#book_imgnum").val());
        if (book_imgnum > 6) {
            layer.msg("最多能上传6张图片");
            return false;
        }
        $obj = $("#book_label_img"+$book_imgnum);
        $obj.show();
        $url = _ROOT_PATH+"index.php?c=index&a=upload&forbidcom=1&forbidwater=1&module=upload";
        $.ajaxFileUpload({
            "url": $url,
            "secureuri": false,
            "fileElementId": "upload_book_img",
            "dataType": "json",
            "data": {
                uploadpart: "upload_book_img"
            },
            async: this.async,
            beforeSend: function ($xmlobj) {},
            complete: function ($data) {},
            success: function ($data) {
                $json = eval($data);
                $response = $json.response;
                $result = $json.result;
                $imgthumb = $json.thumbimg;
                $imgurl = $json.uploadimg;
                $attid = $json.attid;
                if (typeof($attid) == "undefined") {
                    $attid = "";
                }
                if ($response == "1") {
                    $("#book_img"+$book_imgnum).val($imgurl);
                    $("#book_imgnum").val($book_imgnum+1);
                    $obj.find("img").attr("src", _ROOT_PATH+$imgurl).show();
                    _oeloveFileSynYun($attid); //同步云存储
                }
                else {
                    $obj.hide();
                    if ($result.length > 0 ) {
                        layer.msg($result);
                    }
                    else {
                        layer.msg("上传失败，请检查图片。");
                    }
                }

            },
            error: function ($data, e, b) {
                if ($obj_loading.length > 0) {
                    $obj_loading.hide();
                }
                layer.msg("系统繁忙，请稍后再试！");
            }
        }); 
    });
    //保存留言...
    layui.use('form', function(){
        $form = layui.form;
        
        $form.on('submit(bookform)', function(data){
            $obj_id = data.elem.getAttribute("id");
            if (!$("#"+$obj_id).hasClass("forbid_submit")) {

                $book_catid = $("#book_catid").val();
                $book_title = $("#book_title").val();
                $book_content = $("#book_content").val();
                $book_img1 = $("#book_img1").val();
                $book_img2 = $("#book_img2").val();
                $book_img3 = $("#book_img3").val();
                $book_img4 = $("#book_img4").val();
                $book_img5 = $("#book_img5").val();
                $book_img6 = $("#book_img6").val();
                $book_email = $("#book_email").val();
                if ($book_catid.length == 0) {
                    layer.msg("请选择留言分类");
                    return false;
                }
                if ($book_title.length == 0) {
                    layer.msg("请填写留言标题");
                    return false;
                }
                if ($book_content.length == 0) {
                    layer.msg("请填写留言内容");
                    return false;
                }
                if ($book_email.length == 0) {
                    layer.msg("请填写邮箱");
                    return false;
                }

                $("#"+$obj_id).addClass("forbid_submit");
                $("#"+$obj_id).find("span").show();
                
                $.ajax({
                    type: "POST",
                    url: _ROOT_PATH + "index.php?c=index",
                    cache: false,
                    data: {
                        a:"saveguestbook", catid:$book_catid, title:$book_title, content:$book_content, 
                        email:$book_email, img1:$book_img1, img2:$book_img2, img3:$book_img3, img4:$book_img4, img5:$book_img5, img6:$book_img6,
                        r:get_rndnum(8)
                    },
                    dataType: "json",
                    success: function($data) {
                        $json = eval($data);
                        $response = $json.response;
                        $result = $json.result;
                        if ($response == "1") {                           
                            layer.msg("留言成功，请等待客服处理！");
                            setTimeout(function(){
                                parent.layer.closeAll();
                            }, 500); 
                        }
                        else {
                            if ($result.length > 0) {
                                layer.msg($result);
                            }
                            else {
                                layer.msg("留言失败");
                            }
                            $("#"+$obj_id).removeClass("forbid_submit");
                            $("#"+$obj_id).find("span").hide();
                        }
                    },
                    error: function() {
                        layer.msg("系统繁忙，请稍后再试");
                        $("#"+$obj_id).removeClass("forbid_submit");
                        $("#"+$obj_id).find("span").hide();
                    }
                });
                return false;
            
            }
            return false;
        });

    });
    
    
    //jd举报投诉 弹出 iframe
	$(document).on("click", "[f='pop_jubao']", function(){
		$width = $(this).attr("data-width");
		if (typeof($width) == "undefined") {
			$width = 600;
		}
		$height = $(this).attr("data-height");
		if (typeof($height) == "undefined") {
			$height = 450;
		}
        $uid = $(this).attr("data-uid");
        layer.open({
            title:"举报投诉",
            type: 2,
            area: [''+$width+'px', ''+$height+'px'],
            shadeClose: true,
            resize: false,
            scrollbar: false,
            content: _ROOT_PATH+"index.php?c=jubao&homeuid="+$uid+"&r="+get_rndnum(8)
        });
	});
    //上传举报图片
    $(document).on("change", "#upload_jubao_img", function(){
        $("#jubao_img_label").show();
        $url = _ROOT_PATH+"index.php?c=index&a=upload&forbidcom=1&forbidwater=1&module=upload";
        $.ajaxFileUpload({
            "url": $url,
            "secureuri": false,
            "fileElementId": "upload_jubao_img",
            "dataType": "json",
            "data": {
                uploadpart: "upload_jubao_img"
            },
            async: this.async,
            beforeSend: function ($xmlobj) {},
            complete: function ($data) {},
            success: function ($data) {
                $json = eval($data);
                $response = $json.response;
                $result = $json.result;
                $imgthumb = $json.thumbimg;
                $imgurl = $json.uploadimg;
                $attid = $json.attid;
                if (typeof($attid) == "undefined") {
                    $attid = "";
                }
                if ($response == "1") {
                    $("#jubao_img_label").find("img").attr("src", _ROOT_PATH+$imgurl).show();
                    _oeloveFileSynYun($attid); //同步云存储
                }
                else {
                     $("#jubao_img_label").hide();
                    if ($result.length > 0 ) {
                        layer.msg($result);
                    }
                    else {
                        layer.msg("上传失败，请检查图片。");
                    }
                }

            },
            error: function ($data, e, b) {
                $("#jubao_img_label").hide();
                layer.msg("系统繁忙，请稍后再试！");
            }
        }); 
    });
    
    
    //保存投诉、举报 ajax
    layui.use('form', function(){
        $form = layui.form;
        
        $form.on('submit(jubaoform)', function(data){
            $obj_id = data.elem.getAttribute("id");
            if (!$("#"+$obj_id).hasClass("forbid_submit")) {

                $jubao_homeuid = $("#jubao_homeuid").val();
                $jubao_blacktype = $("#jubao_blacktype").val();
                $jubao_judes = $("#jubao_judes").val();
                $jubao_juimg = $("#jubao_juimg").val();
                $jubao_jumobile = $("#jubao_jumobile").val();
                $jubao_juemail = $("#jubao_juemail").val();
        
                if ($jubao_homeuid.length == 0) {
                    layer.msg("举报对象UID错误");
                    return false;
                }
                if ($jubao_blacktype.length == 0) {
                    layer.msg("请选择举报类型");
                    return false;
                }
                if ($jubao_judes.length == 0) {
                    layer.msg("请填写举证描述");
                    return false;
                }
                if ($jubao_jumobile.length == 0) {
                    layer.msg("请填写举报人手机");
                    return false;
                }
                
                $("#"+$obj_id).addClass("forbid_submit");
                $("#"+$obj_id).find("span").show();
                
                $.ajax({
                    type: "POST",
                    url: _ROOT_PATH + "index.php?c=jubao",
                    cache: false,
                    data: {
                        a:"savejubao", homeuid:$jubao_homeuid, blacktype:$jubao_blacktype, judes:$jubao_judes, 
                        juimg:$jubao_juimg, jumobile:$jubao_jumobile, juemail:$jubao_juemail, r:get_rndnum(8)
                    },
                    dataType: "json",
                    success: function($data) {
                        $json = eval($data);
                        $response = $json.response;
                        $result = $json.result;
                        if ($response == "1") {                           
                            layer.msg("举报/投诉提交成功，请等待审核！");
                            setTimeout(function(){
                                parent.layer.closeAll();
                            }, 500); 
                        }
                        else {
                            if ($result.length > 0) {
                                layer.msg($result);
                            }
                            else {
                                layer.msg("提交失败");
                            }
                            $("#"+$obj_id).removeClass("forbid_submit");
                            $("#"+$obj_id).find("span").hide();
                        }
                    },
                    error: function() {
                        layer.msg("系统繁忙，请稍后再试");
                        $("#"+$obj_id).removeClass("forbid_submit");
                        $("#"+$obj_id).find("span").hide();
                    }
                });
                return false;
            
            }
            return false;
        });

    });
    

	//关闭消息提醒
	$(document).on("click", "[f='but_close_infowin']", function(){
		_closeInfoWinData();
	});
    
    //iframe 弹出关注公众号窗 8.08.28
    $(document).on("click", "[f='pop_jdwxcode']", function(){
        $width = $(this).attr("data-width");
		if (typeof($width) == "undefined") {
			$width = 320;
		}
		$height = $(this).attr("data-height");
		if (typeof($height) == "undefined") {
			$height = 350;
		}
        _jdWxcode($width, $height);
    });
   
});


//jdlogin iframe
function _jdLogin2($width, $height) {
    if (typeof($width) == "undefined") {
        $width = 420;
    }
    if (typeof($height) == "undefined") {
        $height = 456;
    }
    
    if (_CONNET_LOGIN == 1) {
        $height = 522;
    }
    layer.open({
        title:false,
        type: 2,
        area: [''+$width+'px', ''+$height+'px'],
        shadeClose: true,
        resize: false,
        scrollbar: false,
        content: [_ROOT_PATH+'index.php?c=passport&a=jdlogin&r='+get_rndnum(8), 'no']
    });
}

//jdchat iframe 8.05.08
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) {
            $json = eval($data);
            $response = $json.response;
            $result = $json.result;
            if ($response == "1") {
                layer.open({
                    title:"发私信...",
                    type: 2,
                    area: [''+$width+'px', ''+$height+'px'],
                    shadeClose: false,
                    scrollbar: false,
                    //content: _ROOT_PATH+"index.php?m=user&c=msgchat&sid="+$result+"&r="+get_rndnum(8)
                    content: [_ROOT_PATH+"index.php?m=user&c=msgchat&sid="+$result+"&r="+get_rndnum(8), 'no']
                });  
            }
            
            else if ($response == "2") {
                layer.confirm('你的资料审核中或审核不通过', {
                    icon: 5,
                    title: "温馨提示",
                    btn: ['去修改','知道了']
                }, function(){
                    window.parent.top.location.href = _ROOT_PATH+"index.php?m=user&c=profile";
                }, function(){
                    
                });
            }
            else if ($response == "3") {
                layer.confirm('你的头像未上传或审核不通过', {
                    icon: 5,
                    title: "温馨提示",
                    btn: ['去设置','知道了']
                }, function(){
                    //9.02.25
                    window.parent.top.location.href = _ROOT_PATH+"index.php?m=user";
                }, function(){
                    
                });
            }
            else if ($response == "4") {
                layer.confirm('你的手机还未认证，请先认证', {
                    icon: 5,
                    title: "温馨提示",
                    btn: ['去认证','知道了']
                }, function(){
                    window.parent.top.location.href = _ROOT_PATH+"index.php?m=user&c=rz";
                }, function(){
                    
                });
                return false;
            }
            
            else {
                
                //加群 9.09.10
                if ($result == "20") {
                    //跳到着陆页
                    window.location.href = _ROOT_PATH+"index.php?c=qzform&a=land&uid="+$touid;
                    return false;
                }
                else {
                    //9.04.23 其他提示
                    if ($result.length > 0) {
                        layer.msg($result);
                    }
                    else {
                        layer.msg("系统繁忙，请稍后再试");
                    }
                }
            }
            
        },
        error: function() {

        }
    });
    
    
}

//获取消息提醒...
function _openInfoWinData() {
	if ($("#infowin_box").length > 0) {
		$.ajax({
			type: "POST",
			url: _ROOT_PATH + "index.php?m=user",
			cache: false,
			data: {
				c:"infowin", r:get_rndnum(8)
			},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					if ($result.length > 0) {
						$("#infowin_data").html("");
						$("#infowin_data").html($result);
						$("#infowin_box").slideDown(300);

						setTimeout(function(){
							_closeInfoWinData();
						}, INFOWIN_CLOSETIME*1000);
					}
				}
				setTimeout(function(){
					_openInfoWinData();
				}, INFOWIN_LOOPTIME*1000);
				
			},
			error: function() {

			}
		});
	}
}
//关闭消息窗口
function _closeInfoWinData() {
	if ($("#infowin_box").length > 0) {
		$("#infowin_box").slideUp(300);
	}
}


//微信公众号二维码 iframe 8.08.28
function _jdWxcode($width, $height) {
    if (typeof($width) == "undefined") {
        $width = 300;
    }
    if (typeof($height) == "undefined") {
        $height = 300;
    }
    layer.open({
        title:"关注公众号",
        type: 2,
        area: [''+$width+'px', ''+$height+'px'],
        shadeClose: true,
        resize: false,
        scrollbar: false,
        content: [_ROOT_PATH+'index.php?c=index&a=wxcode&r='+get_rndnum(8), 'no']
    });
}