var currentSort = {'保费从高到低':{2:1},'保费从低到高':{2:0},'积分从高到低':{3:1},'积分从低到高':{3:0}};
$(document).ready(function() {
	$('.guarantee-order-tab>div').click(function(event) {
		var _this = $(this);
		var target = _this.attr('data-target');
		var $layout = $('.modal-layout[data-target='+target+']'); 
		$layout.siblings('.modal-layout').addClass('hide').find('.guarantee-modal-list').slideUp('600');
		$layout.toggleClass('hide');
		$layout.find('.guarantee-modal-list').slideToggle('600');
		var $item = $layout.find('.guarantee-modal-list li');
		$item.on('click',function(){
			var _this = $(this);
			$layout.addClass('hide');
			$layout.find('.modal-wrapper').removeClass('animated');
			$layout.find('.guarantee-modal-list').slideToggle('600');
			$item.off('click');
			loadCompanys(_this.text());
		})
	});
	clickStatistics(baseUrl,'Model_ssdb','Page_order_filter_wx',postDataDefaultErrorCallback);
	$('.search-NrCompany-btn').click(function(event) {
		$('#searchNrCompanyForm').submit();
	});
});

//加载公司列表
function loadCompanys(text){
	$('#companyList').html('');
	var url = baseUrl + '/B/android';
	var parameters = {'actionCode':'B501','obFields':currentSort[text]};
	var keys = ['courtId','rows','stage','targetAmount','bdCode'];
	var key = null;
	for(var i=0;i<keys.length;i++){
		key = keys[i];
		parameters[key] = $('#param_' + key).val();
	}
	var tmp = $('#param_bdCode1').val();
	if(tmp.length > 0){
		parameters['bdCode1'] = tmp;
	}
	tmp = $('#param_bdCode2').val();
	if(tmp.length > 0){
		parameters['bdCode2'] = tmp;
	}
	postData(url, JSON.stringify(parameters), loadCompanysSuccess, postDataDefaultErrorCallback);
}

//加载公司列表成功回调
function loadCompanysSuccess(data){
	if(data.success){
		var companys = data.infos;
		var html = '';
		var company = null;
		for(var i=0;i<companys.length;i++){
			company = companys[i];
			var liH='';
			var himg='';
			if(company.sort>0){
				himg='<img src="'+baseUrl+'/static/weixin/ssdb/images/icon_list_top.png" class="mar-t-35  br-t" style="width: 100%;height: 100%;left: 0;">'
				liH='<li class="pad-l-20 pad-tb-15  bg-white">'
			}else{
				liH='<li class="mar-t-35 pad-l-20 pad-tb-15 br-tb bg-white">'
			}
			var jfText0='';
			var jfText1='';
			var jfText2='';
			if(company.sort>0){
				jfText0='<span class=" br1 br-ff6600 br-radius5 text-center  search-state1 fs-12 mar-l-15 colorff6600"><span style="padding: 0.15rem;">'+company.text0+'</span></span>'
			}
			if(company.sort>0){
				jfText1='<span class=" br1 br-ff6600 br-radius5 text-center  search-state1 fs-12 mar-l-15 colorff6600"><span style="padding: 0.15rem;">'+company.text1+'</span></span>'
			}
			if(company.sort>0){
				jfText2='<span class=" br1 br-ff6600 br-radius5 text-center  search-state1 fs-12 mar-l-15 colorff6600"><span style="padding: 0.15rem;">'+company.text2+'</span></span>'
			}
			html +=himg
				+
				liH
					+ '<div class="pad-r-20 pad-b-15 ub ub-ac ub-pj guarantee-qualificate-item-top">'
						+ '<div class="fc-dgrey ub-f1">'
							+ '<p><span class="mar-r-10 fc-black">保费：' + company.premium + '</span>' + company.rat + ''+jfText0+'</p>'
							+ '<p>积分：' + company.score + ''+jfText1+'</p>'
							+ '<p>出函：' + company.timeDesc + ''+jfText2+'</p>'
							+ '<p>配送：提供' + company.sendType + '</p>'
						+ '</div>'
						+ '<a href="'+baseUrl+'/web/ssdb/toApply?company_id='+company.id+'&searchId='+searchId+'" class=" btn btn-sm btn-brblue guarantee-qualificate-apply-btn">申请</a>'
					+ '</div>'
					+ '<div class="pad-t-15 pad-r-20 ub ub-ac fc-dgrey guarantee-qualificate-item-bottom">'
						+ '<img src="' + company.path + '">'
						+ '<div class="ub-f1 mar-l-50">'
							+ '<p class="text-overflow">' + company.name + '</p>'
						+ '</div>'
					+ '</div>'
				+ '</li>'
		}
		$('#companyList').html(html);
	}else{
		showMsg(data.message);
	}
}
