var name = '';
var regionCode = '';
var token = '';
var nextName = '';
var nextCode = '';
var httpStr = '';
$().ready(function() {
   var qs = parseQueryString(window.location.href);
   name = qs.name;
   regionCode = qs.code;
   token = qs.token;
   httpStr = qs.httpStr;
   cituInfoData();
   goBack();
   goNextStep();
})
//初始
function init () {
	$(".typeListRight").css('background','#D7D7D7')
					   .find('.disc').css('background','#FFFFFF');
	$(".typeListRight").eq(0).css('background','#5D7DFF')
					   .find('.disc').css('background','#5D7DFF');
					   
    $(".nextStep").css({'background':'#5D7DFF','box-shadow':' 0 0 6px 0 rgba(93, 125, 255, 0.7)','-webkit-box-shadow':' 0 0 6px 0 rgba(93, 125, 255, 0.7)'});
	$(".nextStep").removeAttr('disabled');
	nextCode = $(".typeListRight").eq(0).parent().attr('data-code');
	nextName = $(".typeListRight").eq(0).parent().attr('data-nextname');
}
//点击进行公积金类型选择
function selectionTypes () {
	$(".typeListRight").click(function () {
		$(".typeListRight").css('background','#D7D7D7')
						   .find('.disc').css('background','#FFFFFF');
		$(this).css('background','#5D7DFF')
						   .find('.disc').css('background','#5D7DFF');
		nextCode = $(this).parent().attr('data-code');
		nextName = $(this).parent().attr('data-nextname');
	})
}
//nav返回上一页
function goBack () {
	$("nav i").click(function () {
		history.go(-1)
	})
}

//公积金类型数据
function cituInfoData () {
	$.ajax({
		type:"POST",
		url: "/api/city/listinfo",
		data:{
			'region': name
		},
		success: function (res) {
			console.log(res)
			if(res.errno == 0 && res.rst.city){
				var list = res.rst.city.list;
				var html = '';
				if(list.length > 0){
					for(var i = 0 ; i < list.length ; i++){
						html += `<div class="typeList" data-code="${list[i].region_code}" data-nextname="${list[i].region}">
									<div class="typeListLeft">
										<h4>${list[i].region}</h4>
										<p>${list[i].parent_region}</p>
									</div>
									<div class="typeListRight">
										<div class="hollowCircle">
											<div class="disc"></div>
										</div>
									</div>
								</div>`
					}
					$(".list").html(html);
					init();
					selectionTypes();
				}
			}else{
					$(".nextStep").css({'background':'#CCCCCC','box-shadow':'none'});
					$(".nextStep").attr('disabled','disabled');
				}
		}
	});
}

//下一步
function goNextStep () {
	$(".nextStep").click(function () {
		console.log('ffff')
		console.log(httpStr)
		window.location.href = httpStr + '&name=' + nextName + '&code=' + nextCode + '&token=' + token
	})
}
