$(function(){

	$("#submitBtn").click(function(){

		var merchId = $("#merchId").val();
		var name = $("#name").val();
		var status = $("#status").val();
		var degree = $("#degree").val();
		var link = $("#link").val();
		var phone= $("#phone").val();
		var info = $("#info").val();
		var uname= $("#uname").val();
		var email= $("#email").val();
		var pwd = $.trim($("#pwd").val());
		
		// 参数校验
		if(merchId==undefined ||merchId==''||merchId=='0'){
			if(uname==''||email==''||pwd==''){
				layer.msg('用户名邮箱密码不能为空！',{icon: 5});
				return;
			}
			if(uname.length<6){
				layer.msg('用户名至少6位数',{icon: 5});
				return;
			}
			if(pwd!=''){
				if(pwd.length<6){
					layer.msg('密码至少6位数',{icon: 5});
					return;
				}
			}
			pwd  = uname +"888888";
			pwd  = $.md5(pwd);
		}
		
		var c = /^[1]\d{10}$/;
		if (!c.test(phone)) {
			layer.msg('请输入正确手机号',{icon: 5});
			return;
		}
		
		var params = {
				merchId:merchId,
				name:name,
				uname:uname,
				email:uname,
				pwd:pwd,
				status:status,
				degree:degree,
				link:link,
				phone:phone,
				info:info
		};

		var	_httpURL = HttpRest+"/ebus/merchant/save.shtml";
		if(merchId==undefined ||merchId==''||merchId=='0'){
			_httpURL = HttpRest+"/ebus/merchant/create.shtml";
		}
		$.ajax({
			url: _httpURL, 
			type: "post", 
			dataType: "json",
			data:$.toJSON(params),   
			contentType:"application/json",
			success: function(data) { 
				if(data.code=='01'){
					layer.confirm('保存成功！是否关闭窗口?', function(index) {
						parent.grid.loadData();
						parent.layer.close(parent.pageii);
						return false;
					});
				}else{
					layer.msg('保存失败！',{icon: 5});
				}
			}
		});
	});

	onloadurl();
});