/**
 * 融资要素
 */

//获取融资要素
function getRzysInfo(orderId){
	var url = contextPath + '/ssrz/ssrzOrder/getRzys';
	var parameters = {"orderId":orderId};
	postData(url, parameters, getRzysInfoCallback, errorCallbackDefault);
}

function getRzysInfoCallback(data){
	if(data.success){
		var obj = {'mod-rzys-moneyPc':'moneyPc','mod-rzys-ratioFc':'ratioFc','mod-rzys-termPc':'termPc','mod-rzys-conditionDk':'conditionDk','mod-rzys-orderId':'orderId'};
		for(var o in obj){
			$('#' + o).val(data[obj[o]]);
		}
		$('#modal-rzys').modal('toggle');
	}else{
		showMsg(data.message);
	}
}

function rzysClear(){
	var ids = ['mod-rzys-moneyPc','mod-rzys-ratioFc','mod-rzys-termPc','mod-rzys-conditionDk','mod-rzys-orderId'];
	for(var i in ids){
		$('#' + ids[i]).val('');
	}
}

function rzySubmit(){
	var url = contextPath + '/ssrz/ssrzOrder/saveRzys';
	var moneyPc = $('#mod-rzys-moneyPc').val();
	if(isNotBlank(moneyPc)){
		if(isNotDouble(moneyPc)){
			alert('融资金额只能为浮点数');
			return;
		}
	}
	var ratioFc = $('#mod-rzys-ratioFc').val();
	if(isNotBlank(ratioFc)){
		if(isNotDouble(ratioFc)){
			alert('分成比例只能为浮点数');
			return;
		}
	}
	var termPc = $('#mod-rzys-termPc').val();
	if(isNotBlank(termPc)){
		if(isNotNaturalNumber(termPc)){
			alert('打款条件只能为自然数');
			return;
		}
	}
	var conditionDk = $('#mod-rzys-conditionDk').val();
	var parameters = {"orderId":$('#mod-rzys-orderId').val(),"moneyPc":moneyPc,"ratioFc":ratioFc,"termPc":termPc,"conditionDk":conditionDk};
	postData(url, parameters, rzySubmitCallback, errorCallbackDefault);
}

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