/**
 * 当事人
 */
function partyDivAdd(data){
	var html = '<div class="form-group mod-caseInfo-party-list" id="partyDiv' + data.cpId + '">';
	html += '<label class="col-sm-2 control-label"></label>';
	html += '<label class="col-sm-6 text-left">' + data.name + '</label>';
	html += '<div class="col-sm-4 text-right">';
	html += '<button class="btn btn-primary btn-white checkbox-inline" type="button" onclick="partyInfoUpdateShow(\'' + data.cpId + '\')">修改</button>';
	html += '<button class="btn btn-primary btn-white checkbox-inline" type="button" onclick="partyInfoDelete(\'' + data.cpId + '\')">删除</button></div>';
	html += '</div>';
	$('#mod-caseInfo-party-list').after(html);
}

function partyInfoClear(){
	var partyIds = ['mod-party-casePersonId','mod-party-caseInfoId','mod-party-orderId','mod-party-name','mod-party-idNum','mod-party-contactInfo','mod-party-trafficType','mod-party-duty'];
	for(var i in partyIds){
		$('#' + partyIds[i]).val('');
	}
}

function partyInfoDelete(cpId){
	var url = contextPath + '/ssrz/ssrzOrder/deleteParty';
	var parameters = {'cpId':cpId};
	$("#partyDiv" + cpId).remove();
	postData(url, parameters, partyInfoDeleteCallback, errorCallbackDefault);
}

function partyInfoDeleteCallback(data){
	if(data.success){
		showMsg('删除成功');
	}else{
		showMsg(data.message);
	}
}

function partyInfoUpdateShow(cpId){
	var url = contextPath + '/ssrz/ssrzOrder/getPartyInfo';
	var parameters = {'cpId':cpId};
	postData(url, parameters, partyInfoUpdateShowCallback, errorCallbackDefault);
}

function partyInfoUpdateShowCallback(data){
	if(data.success){
		partyInfoClear();
		$('#mod-party-caseInfoId').val($('#mod-caseInfo-caseInfoId').val());
		$('#mod-party-casePersonId').val(data.party.casePersonId);
		$('#mod-party-orderId').val($('#mod-caseInfo-orderId').val());
		var obj = {'mod-party-name':'name','mod-party-idNum':'idNum','mod-party-contactInfo':'contactInfo','mod-party-trafficType':'trafficType','mod-party-duty':'duty'};
		for(var o in obj){
			$('#' + o).val(data.party[obj[o]]);
		}
		$('#modal-party').modal('toggle');
	}else{
		showMsg(data.message);
	}
}

function partySubmit(){
	var url = contextPath + '/ssrz/ssrzOrder/saveParty';
	var parameters = {'orderId':$('#mod-party-orderId').val(),'caseInfoId':$('#mod-party-caseInfoId').val(),'casePersonId':$('#mod-party-casePersonId').val()};
	var obj = {'mod-party-name':'name','mod-party-idNum':'idNum','mod-party-contactInfo':'contactInfo','mod-party-trafficType':'trafficType','mod-party-duty':'duty'};
	var count = 0;
	var s = '';
	for(var o in obj){
		s = $('#' + o).val();
		parameters[obj[o]] = s;
		if(s.length > 0){
			count ++;
		}
	}
	if(count > 0){
		postData(url, parameters, partySubmitCallback, errorCallbackDefault);
	}else{
		showMsg('请输入信息');
	}
}

function partySubmitCallback(data){
	if(data.success){
		$('#modal-party').modal('toggle');
		$('#mod-caseInfo-caseInfoId').val(data.caseInfoId);
		$("#partyDiv" + data.cpId).remove();
		partyDivAdd(data);
		showMsg('保存成功');
	}else{
		showMsg(data.message);
	}
}
	