/**
 * 新增服务项基础信息
 */
$(document).ready(function(){
	var XXPLcount = 0;
	
	var servicePackId = $("#servicePackId").val();
	var servicePackBasicsId = $("#servicePackBasicsId").val();
	var h_isDeposit = $("#h_isDeposit").val();
	if(h_isDeposit == '1'){
		$("#deposit").show();
	}
	// 初始化加载
	if(servicePackBasicsId == 'undefined' || servicePackBasicsId == null || servicePackBasicsId == ""){
		$.ajax({
			type:'POST',
			url:'../servicePack/queryServiceList',
			dataType: 'json',//返回值类型 一般设置为json
			success: function (data)  //服务器成功响应处理函数
			{
				$("#servicePackId").empty();
				var subs = data.list;// 获取data中list的数组
				var _array = [];
				_array.push("--请选择--");
				for ( var i = 0; i < subs.length; i++) {
					_array.push("<option value='" + subs[i].id + "'>"+ subs[i].name + "</option>");
					$("#servicePackId").html(_array.join(""));
				}
				$("#servicePackId").html(_array.join(""));
			}
		});
	}
	//新增服务项
	$("#addServicePackBasics").click(function(){
		var name = $("#name").val();
		var isDeposit = $("input[name='isDeposit']:checked").val();
		var servicePackId = $("#servicePackId").val();
		var deposit = $("#deposit").val();
		
		if(servicePackId == null || servicePackId == ""){
			layer.alert("请选择服务项！");
			$("#name").focus();
			return;
		}
		if(name == null || name == ""){
			layer.alert("请填写服务项名称！");
			$("#name").focus();
			return;
		}
		if(isDeposit == null || isDeposit == ""){
			layer.alert("请选择是否需要押金！");
			return;
		}
		if(isDeposit == '1' && (deposit == null || deposit == "")){
			layer.alert("请填写押金金额！");
			$("#deposit").focus();
			return;
		}
		$.ajax({
			type : 'POST',
			url : '../servicePackBasics/addServicePackBasics',
			data:{"id":servicePackBasicsId,"name":name,"servicePackId":servicePackId,"deposit":deposit,"isDeposit":isDeposit},
			dataType : 'json',// 返回值类型 一般设置为json
			success : function(data) // 服务器成功响应处理函数
			{
				if(data.code == '0'){
					alert(data.msg);
					window.location.href="../servicePackBasics/list";
				}else{
					alert(data.msg);
				}
			}
		});
	});
	
	//取消返回
	$("#back").click(function(){
		window.location.href="../servicePackBasics/list";
	});
	
})

function queryServiceList(){
	$.ajax({
		type:'POST',
		url:'../servicePack/queryServiceList',
		dataType: 'json',//返回值类型 一般设置为json
		success: function (data)  //服务器成功响应处理函数
		{
			$("#servicePackId").empty();
			var subs = data.list;// 获取data中list的数组
			var _array = [];
			_array.push("--请选择--");
			for ( var i = 0; i < subs.length; i++) {
				_array.push("<option value='" + subs[i].id + "'>"+ subs[i].name + "</option>");
				$("#servicePackId").html(_array.join(""));
			}
			$("#servicePackId").html(_array.join(""));
		}
	});
}

//押金显示与隐藏
function showDeposit(){
	var isDeposit = $("input[name='isDeposit']:checked").val();
	if(isDeposit=='0'){
		$("#s_deposit").hide();
	}
	if(isDeposit=='1'){
		$("#s_deposit").show();
	}
}


