var $ = null;
var form = null;
var layer = null;
layui.use(["layer", "form"], function(){
    $ = layui.$;
    form = layui.form;
    layer = layui.layer;
    //注销 退出
    $(".head_portrait").on("click", (e) => {
        localStorage.clear(); //清空缓存
        window.location.href="http://116.62.173.33:3033/login?type=manager";
    })
});
//菜单点击监听事件
function clickItem(obj){
    if($(obj).hasClass("layui-nav-itemed")){
        $.each($(".layui-nav-item"), (index, item) => {
            $(item).find("a cite img").attr("src",  "/images/indeHome/" + $(item).attr("title") + ".png");
        });
        $(obj).find("a cite img").attr("src",  "/images/indeHome/" + $(obj).attr("title") + "_click.png");
        //个人信息特殊处理
        if($(obj).find("a cite").text() == "个人信息"){
            iframeClick(obj);
        }
    }else{
        $(obj).find("a cite img").attr("src",  "/images/indeHome/" + $(obj).attr("title") + ".png");
    }
}
//iframe选择
function iframeClick(obj){
    //上一级名称
    var parentName = $(obj).parent().parent().prev().find("cite").text();
    //点击名称
    var thisClickName = $(obj).find("cite").text();
    //路径上参数
    var idVal = $(obj).attr("idVal");
    $(".select_button").removeClass("check_div");
    var flag = false;
    $.each($(".select_button"), (index, item) => {
        if(index > 0){
            if($(item).find("span").html().indexOf(thisClickName) != -1){
                flag = true;
                return false;
            }
        }
    });
    if(flag){
        $(".center_top div[name="+ thisClickName +"]").click();
    } else {
        if(parentName == "报价单"){
            $(".center_top").append("<div onClick='switchMenu(this)' name="+ thisClickName +" src='/page/demandForSingleIndex?idVal="+ idVal +"' class=\"select_button check_div\">\n" +
                "                    <span>"+ thisClickName +"</span>\n" +
                "                    <div class=\"close_button\" onclick='removeThis(this)'><i class=\"layui-icon layui-icon-close\"></i></div>\n" +
                "                </div>");
            $("iframe").attr("src", "/page/demandForSingleIndex?idVal=" + idVal);
        }
        if(thisClickName == "个人信息"){
            $(".center_top").append("<div onClick='switchMenu(this)' name='个人信息' src='/page/personalIndex' class=\"select_button check_div\">\n" +
                "                    <span>"+ thisClickName +"</span>\n" +
                "                    <div class=\"close_button\" onclick='removeThis(this)'><i class=\"layui-icon layui-icon-close\"></i></div>\n" +
                "                </div>");
            $("iframe").attr("src", "/page/personalIndex");
        }
    }


}
//头部菜单切换
function switchMenu(obj){
    $(".select_button").removeClass("check_div");
    $(obj).addClass("check_div")
    var srcVal = $(obj).attr("src");
    $("iframe").attr("src", srcVal);

}
//删除顶部选中菜单
function removeThis(obj){
    window.event.cancelBubble = true;//阻止冒泡
    $(obj).parent().prev().click();
    $(obj).parent().remove();
}