/**
 * 指派代理
 */
var lawyerBObj = {};

function getLawyerBInfo(orderId){
	$('#mod-confirm-orderId').val(orderId);
	var url = contextPath + '/ssrz/ssrzOrder/getLawyerBInfo';
	var parameters = {'orderId':orderId};
	postData(url, parameters, getLawyerBInfoCallback, errorCallbackDefault);
}

function getLawyerBInfoCallback(data){
	if(data.success){
		lawyerBInfoClear();
		var lbs = data.lbs;
		if(isNotBlank(lbs)){
			var l = null;
			var html = "<option selected value='' >手动输入</option>";
			for(var i in lbs){
				l = lbs[i];
				html += "<option value='"+l.id+"'>"+l.name+"</option>";
				lawyerBObj[l.id] = l;
			}
			document.getElementById('mod-confirm-lawyerB').innerHTML = html;
			if(isNotBlank(data.lawyerBid)){
				var o = lawyerBObj[data.lawyerBid];
				if(isNotBlank(o)){
					$('#mod-confirm-lawyerB').val(data.lawyerBid);
					$('#mod-confirm-lawyerBPhone').val(o.phone);
				}
			}
		}
		$('#modal-confirm').modal('toggle');
	}else{
		showMsg(data.message);
	}
}

function lawyerBInfoClear(){
	$('#mod-confirm-lawyerB').empty();
	$('#mod-confirm-lawyerBPhone').val('');
	lawyerBObj = {};
}

function lawyerBOnchange(obj){
	var val = obj.value;
	var t = '';
	if(isNotBlank(val)){
		var o = lawyerBObj[val];
		if(isNotBlank(o)){
			t = o.phone;
		}
	}
	$('#mod-confirm-lawyerBPhone').val(t);
}

function lawyerBSubmit(){
	var url = contextPath + '/ssrz/ssrzOrder/saveLawyerB';
	var bid = $('#mod-confirm-lawyerB').val();
	var phone = $('#mod-confirm-lawyerBPhone').val();
	if(bid.length < 1 && phone.length < 1){
		showMsg('请选择律师或输入电话号码');
		return;
	}
	var parameters = {'orderId':$('#mod-confirm-orderId').val(), 'bid':bid, 'phone':phone};
	postData(url, parameters, lawyerBSubmitCallback, errorCallbackDefault);
}

function lawyerBSubmitCallback(data){
	if(data.success){
		$('#modal-confirm').modal('toggle');
		showMsg('保存成功');
	}else{
		showMsg(data.message);
	}
}
