/**
 * 馆藏
 * 热门报告
 * 统计信息
 */
function initStatisticalInfoMuseumHide() {
    $.ajax({
        url: "/geologicalDataJournal/museumHide/statisticalInfo",
        type: "GET",
        async: false,
        success: function (responseData) {
            if (responseData.code == 0) {
                // var statisticalInfo= $.parseJSON(responseData);
                var statisticalInfo = responseData.data;
                $("#manuscript_count").text(statisticalInfo.manuscriptCount);
                $("#file_count").text(statisticalInfo.fileCount);
                $("#visit_count").text(statisticalInfo.visitCount);
                $("#download_count").text(statisticalInfo.downloadCount);
                var liStr = "";
                for (var index = 0; index < statisticalInfo.visitMHCountList.length; index++) {
                    var museumHide = statisticalInfo.visitMHCountList[index];
                    if ((index + 1) % 2 == 0) {
                        liStr += '<li class="hui"><a href="/geologicalDataJournal/museumHide/museumHideIdDetail/' + museumHide.museumHideId + '">' + museumHide.museumHideTitle + '</a> <span>' + museumHide.visitCount + '</span></li>';
                    } else {
                        liStr += '<li class="bai"><a href="/geologicalDataJournal/museumHide/museumHideIdDetail/' + museumHide.museumHideId + '">' + museumHide.museumHideTitle + '</a> <span>' + museumHide.visitCount + '</span></li>';
                    }
                }
                $(".rmsjj ul").append(liStr);
            } else {
                showErrorTip("通知公告信息获取失败!");
            }

            // console.log(statisticalInfo);

        },
        error: function () {
            console.log("系统统计信息获取失败!");
        }
    });
}


function removeSuperscript(target) {
    // target = target.replace(/1/g,"<sup>1</sup>");
    // target = target.replace(/2/g,"<sup>2</sup>");
    // target = target.replace(/3/g,"<sup>3</sup>");
    // target = target.replace(/4/g,"<sup>4</sup>");
    // target = target.replace(/5/g,"<sup>5</sup>");
    // target = target.replace(/6/g,"<sup>*</sup>");

    if (target != undefined) {
        target = target.replace(/[1-9]*/g, "");
    } else {
        target = "";
    }
    return target;
}

/**
 * 将字符串根据分割字符进行分割成数组
 * @param str
 * @param splitStrList 分割
 * @returns {list}
 */
function getListByStr(str, splitStrList) {
    if (isNotEmptyStr(str)) {
        var splitStr = "[";
        if (splitStrList instanceof Array) {
            splitStrList.forEach(function (value, index) {
                if (index != 0) {
                    splitStr += "|"
                }
                splitStr += value
            })

        } else if (typeof splitStrList == "string") {
            splitStr += splitStr
        }
        splitStr += "]"
        var dataList = str.split(new RegExp(splitStr));
        var returnList = [];
        //去除空格，去除空字符串
        dataList.forEach(function (value) {
            if (isNotEmptyStr(value)) {
                returnList.push(value.trim())
            }
        })
        return returnList;
    } else {
        return [];
    }
}


// function switchLanguage(language) {
//
//     window.location.href = "/geologicalDataJournal/home/switchLanguage.htm?lang="+language;
//
// }


/**
 * 初始化语言切换事件
 */
$(function () {
    $(".lang-span").click(function () {
        var lang = $(this).attr("lang")
        switchLanguage(lang)
    })

})

/**
 * 切换语言
 * @param lang
 */
function switchLanguage(lang) {

    //如需判断其他类型，则追加参数，后台处理返回是否由对应语言的数据
    var manuscriptDoi = $("#manuscriptDoi").val();

    // window.location.href="/geologicalData/home/switchLanguage.htm?lang="+lang;
    $.ajax({
        url: baseContextPath + lang + "/home/switchLanguage",
        type: "post",
        data: {
            "lang": lang,
            "manuscriptDoi": manuscriptDoi
        },
        success: function (result) {
            // var resultJson = JSON.parse(result);
            if (result.code == 0) {
                //请求成功，则刷新页面，由控制器控制返回的页面

                //获取当前url地址
                var href = window.location.href
                //替换语言标识
                // href=href.substring(0,href.indexOf(baseContextPath.length)+baseContextPath.length+1)
                //     +lang+href.substring(href.indexOf(baseContextPath.length)+baseContextPath.length+3)
                // href = href.substring(0, baseContextPath.length)
                //     + lang + href.substring(baseContextPath.length + 2)

                //请求的url
                var url=href;
                //携带的参数
                var param="";
                //跳转的url
                var toUrl="";
                //若现在的url带参数，则分离参数信息
                if(href.indexOf("?")>=0){
                    url=href.substring(0,href.indexOf("?"))
                    param=href.substring(href.indexOf("?"))
                }

                //判断现在是否有语言标识
                if(url.length>baseContextPath.length){
                    toUrl = url.substring(0, baseContextPath.length)
                        + lang + url.substring(baseContextPath.length + 2)+param;
                }else{
                    toUrl=baseContextPath+lang+param;
                }
                window.open(toUrl, "_self")
            } else {
                if (isNotEmptyStr(result.msg)) {
                    showErrorTip(result.msg)
                } else {
                    layer.msg("语言切换失败", {
                        icon: 5,
                        time: 3000
                    })
                }
            }
        },
        error: function () {
            layer.msg("语言切换失败", {
                icon: 5,
                time: 3000
            })
        }

    })

}

//登录点击事件
function loginClick() {
    var openUrl = getLang() == LANGUAGE_ENGLISH ? UNIFIED_LOGIN_URL_EN : UNIFIED_LOGIN_URL
    window.open(openUrl, "_blank");
}

//注册点击事件
function registerClick() {
    var openUrl = getLang() == LANGUAGE_ENGLISH ? UNIFIED_REGISTER_URL_EN : UNIFIED_REGISTER_URL
    window.open(openUrl, "_blank");
}

//用户中心点击事件
function userInfoClick() {
    var openUrl = getLang() == LANGUAGE_ENGLISH ? UNIFIED_INDEX_URL_EN : UNIFIED_INDEX_URL
    window.open(openUrl, "_blank");
}

//退出
function loginOutClick() {
    window.open(UNIFIED_LOGINOUT_URL, "_self");
}


function loginCheck(fun) {
    if(true)
	{
		fun()
	}
}

function authCheck(fun) {
    $.ajax({
        url: baseContextPath + "/login/checkAuthStatus",
        type: "post",
        success: function (responseData) {
            if (responseData.code == 0) {
                if (responseData.data.loginStatus == true) {
                    if (responseData.data.authStatus == true) {
                        fun()
                    } else {
                        layer.msg("用户未实名", {
                            icon: 5,
                            time: 3000
                        })
                    }

                } else {
                    layer.msg("用户未登录", {
                        icon: 5,
                        time: 3000
                    })
                }
            } else {
                layer.msg("连接失败，请稍后重试", {
                    icon: 5,
                    time: 3000
                })
            }
        },
        error: function () {
            layer.msg("连接失败，请稍后重试", {
                icon: 5,
                time: 3000
            })
        }
    });
}


function superscriptSolution(target) {
    target = target.replace(/1/g, "<sup>1</sup>");
    target = target.replace(/2/g, "<sup>2</sup>");
    target = target.replace(/3/g, "<sup>3</sup>");
    target = target.replace(/4/g, "<sup>4</sup>");
    target = target.replace(/5/g, "<sup>5</sup>");
    target = target.replace(/6/g, "<sup>6</sup>");
    return target;
}

function showErrorTip(msg) {
    layer.msg(msg, {
        icon: 5,
        time: 3000
    })
}

/**
 * 跳转主页搜索
 * @param key
 * @param value
 */
function toSearchPage(key, value) {
    var data = {
        "searchKey": key,
        "searchValue": value
    }
    postForm(contextPath + "page/index", data)
}

function toSearchPageKey(key, this_) {
    var value = $(this_).val()
    if (!isNotEmptyStr(value)) {
        value = $(this_).text()
    }
    var data = {
        "searchKey": key,
        "searchValue": value
    }
    postForm(contextPath + "page/index", data)
}


