$(function() {
	$("#submitBtn").click(function(){
		var uname = $("#uname").val();
		var name = $("#name").val();
		var status=$("#status").val();
		var roleIds = $("#txtGroupsSelect").val(); // 角色编号
		var email = $("#email").val();
		var phone = $("#phone").val();
		var pwd = $.trim($("#pwd").val());
		if(pwd==''){ // 设置默认密码
			pwd = uname+"123";
		}
		if(uname==''||email==''||name==''||phone==''||pwd==''){
			layer.msg('账户用户名等不能为空！',{icon: 5});
			return false;
		}

		var secpwd=$.md5(pwd);// 密码加密
		var params ={
				uname:uname,
				name:name,
				pwd:secpwd,
				status:status,
				roleIds:roleIds,
				email:email,
				phone:phone
		};
		
		var _URL = HttpRest+"user/create.shtml"; // 请求添加用户路径
		$.ajax({
			type: 'post', 
			url: _URL, 
			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(data.msg,{icon: 5});
				}
			}
		});
	});

});
