
var token = '';
var city_name = '';
var returnUrl = '';
var code = '';
var goUrl = "";
var httpStr = "";
var qs = parseQueryString(window.location.href);


$().ready(function() {
    if (qs.returnUrl) {
        returnUrl = qs.returnUrl;
    }
	if (qs.httpStr) {
        httpStr = qs.httpStr;
    }
	if (qs.name) {
        city_name = qs.name;
    }
	if (qs.code) {
        code = qs.code;
    }
    if (qs.token) {
        token = qs.token;
    } 
    goBack()
    cituInfoData()
});
//nav返回上一页
function goBack () {
	$("nav i").click(function () {
		window.location.href = httpStr + "&name=" + city_name + "&code=" + code + "&token=" + token;
	})
}

//各城市对应注册地址
function goZhuce () {
	tips.find(function(item,index) {
		if(item.region == city_name){
			if(item.URL.register){
				goUrl=item.URL.register;
//				window.location.href = goUrl;
    			window.webkit.messageHandlers.OutPushMessageHandler.postMessage({'name':city_name,'url':goUrl});
				
			}else{
				goUrl=item.URL.web;
//				window.location.href = goUrl;
    			window.webkit.messageHandlers.OutPushMessageHandler.postMessage({'name':city_name,'url':goUrl});
			}
		}
	})
}
//帮助文案
function cituInfoData () {
	$.ajax({
		type:"POST",
		url: "/api/city/listinfo",
		data:{
			'region': qs.name
		},
		dataType:'json',
		success: function (res) {
			console.log(res)
			if(res.errno == 0 && res.rst.city && res.rst.city.city){
				var data = res.rst.city.city;
				if(data.help_info && data.help_info != ""){
					$(".container").html(data.help_info);
					$(".container").find("p").css({
						"line-height":'0.2rem',
						"font-size":"0.14rem",
						"color":"#666666"
					}).find("span").css({
						"line-height":"0.26rem",
						"font-size":"0.14rem",
						"color":"#666666",
						"font-family": "微软雅黑"
					})
					$(".container strong").css({"color":"#333333","font-weight":"bold","font-size":"0.16rem"})
					$(".container strong span").css({"color":"#333333","font-weight":"bold","font-size":"0.16rem"})
					$(".container strong").find("span").css({"color":"#333333"})
					$(".goGjj").html(`<div class="ljqw">前往<em>${city_name}</em>公积金官网注册  <span onclick="goZhuce()">立即前往 >></span>
            </div>`)
				}else{
					$(".container").html(`<h3 class="title">如何获取查询密码/公积金帐号</h3>
	    	<p class="goOfficialNetwork">如果您还未在最新版，<i>${city_name}</i>公积金官网主注册并设置相关信息；<span onclick="goZhuce()">立即前往 >></span></p>
	    	<p class="goOfficialNetwork">注册完成后即可使用APP查询。</p>`)
				}
			}else{
				showMsg(res.err)
			}
		}
	});
}
/**
 * [showMsg 提示各种错误信息,3s后消失]
 */
function showMsg(msg) {
    var msgBox = $('.alert-info');
    msgBox.children('p').text(msg);
    msgBox.show();

    setTimeout(function() {
        msgBox.hide();
    }, 3000);
}