<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>

<script type="text/javascript" src="jquery/jquery.min-1.12.3.js"></script>
<script type="text/javascript" src="layer/layer.js"></script>
<script type="text/javascript" src="com/com.js"></script>
<script type="text/javascript" src="layui/layui.js"></script>
<link rel="stylesheet" href="layui/css/layui.css" media="all">
<script type="text/javascript">
	$(function() {
		
		$("#test").click(function() {
			var session  = $("#session").val();
			alert(session);
			var data = {}
			data.pid = session;
			console.log(data);
			AjaxTool.XPost("http://localhost/login", data, function(data) {
				layer.msg(JSON.stringify(data), {
					icon : 1
				});
			}, function(err) {
				layer.msg("err", {
					icon : 2
				});
			});
		});
		$("#save").click(function() {
			AjaxTool.XPostx("user/save", {}, function(data) {
				layer.msg(JSON.stringify(data), {
					icon : 1
				});
			}, function(err) {
				layer.msg("err", {
					icon : 2
				});
			});
		});
		$("#list").click(function() {
			AjaxTool.XPostx("user/list", {}, function(data) {
				layer.msg(JSON.stringify(data), {
					icon : 1
				});
			}, function(err) {
				layer.msg("err", {
					icon : 2
				});
			});
		});
		$("#page").click(function() {
			AjaxTool.XPostx("user/page", {}, function(data) {
				layer.msg(JSON.stringify(data), {
					icon : 1
				});
			}, function(err) {
				layer.msg("err", {
					icon : 2
				});
			});
		});
		var p = {
			"name" : "tom",
			"age" : "18"
		};
		$("#para").click(
				function() {
					AjaxTool.XPostx("user/jsonParameter", JSON.stringify(p),
							function(data) {
								layer.msg(JSON.stringify(data), {
									icon : 1
								});
							}, function(err) {
								layer.msg("err", {
									icon : 2
								});
							});
				});
		$("#detail").click(function() {
			var pv = {
				"id" : "2"
			};
			AjaxTool.XPost("user/detail", pv, function(data) {
				layer.msg(JSON.stringify(data), {
					icon : 1
				});
			}, function(err) {
				layer.msg("err", {
					icon : 2
				});
			});
		});
		$("#mail").click(function() {
			var pv = {
				"id" : "2"
			};
			AjaxTool.XPost("user/mail", pv, function(data) {
				layer.msg(JSON.stringify(data), {
					icon : 1
				});
			}, function(err) {
				layer.msg("err", {
					icon : 2
				});
			});
		});

		$("#importData").click(function() {
			layer.open({
				type : 2,
				title : '导入数据',
				maxmin : true,
				shadeClose : true, //点击遮罩关闭层
				area : [ '800px', '520px' ],
				content : 'excel/exportUi?type=2'
			});
		});

		$("#selectUserDialog")
				.click(
						function() {
							/*layer
									.open({
										type : 2
										,
										area : [ '900px', '700px' ],
										title : '选择员工',
										shade : 0.6 //遮罩透明度 
										,
										btn : [ '保存', '取消' ],
										maxmin : true //允许全屏最小化 
										,
										anim : 1 //0-6的动画形式，-1不开启 
										,
										content : 'http://localhost/apprsetting/selectUserDialogUi',
										yes : function(index, layero) {
										var backJsonData = $(".layui-layer-content iframe")[0].contentWindow.callBackData();
										layer.msg("单选");
										
										},
										cancel : function() {
											
										}
									});*/
									
									CommTool.selectUserDialog(function(data){
										//data-选择的人员数据，json数组
										layer.msg(JSON.stringify(data));
									}
									,true//true-允许多选，false-只能单选
									,'http://localhost');//ctx

						});

	});
</script>
</head>
<body>
	<h2>Index!</h2>


	<a href="#" id="selectUserDialog">选择人员</a>

	<br>
	<a href="#" id="test">初始化Session</a>  <input type="text" id="session"></input>
	<br>
	<a href="#" id="save">save 保存对象</a>
	<br>
	<a href="#" id="list">list-关联查询</a>
	<br>
	<a href="#" id="page">分页page</a>
	<br>
	<a href="#" id="para">json参数传递</a>
	<br>
	<a href="#" id="detail">detail-对象明细</a>
	<br>
	<a href="#" id="mail">mail-发送邮件</a>
	<br>



	<p>表单提交</p>
	<form method="post" action="user/saveForm">
		name:<input name="name" type="text"> <br> age:<input
			name="age" type="text"> <br> <input type="submit"
			value="submit" />
	</form>

	<!-- <form action="user/upload" method="post"  enctype="multipart/form-data" >
	<input type="file" name= "file"></input>
	<input type="text" name="num"></input>
	<input type="submit" value="上传">
</form> -->
	<!-- <a href="user/download?path=142145">下载</a> -->

	<button data-method="offset" data-type="auto"
		class="layui-btn layui-btn-normal" id="importData">导入</button>




	<div class="layui-upload" id="up">
		<button type="button" class="layui-btn layui-btn-normal" id="file">选择文件</button>
		<button type="button" class="layui-btn" id="upload">开始上传</button>
	</div>

	<div class="layui-upload">
		<div class="layui-upload-list">
			<table class="layui-table">
				<thead>
					<tr>
						<th>文件名</th>
						<th>大小</th>
						<th>上传时间</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="attachmentList"></tbody>
			</table>
		</div>
	</div>

</body>

<script>
	//获取附件列表   
	var realationId = "110"
/* 	AjaxTool
			.XGet(
					"file/list?relationId=" + realationId,
					null,
					function(data) {
						var $ = layui.jquery
						var list = data.json.data;
						for (var i = 0; i < list.length; i++) {
							var attachmentList = $('#attachmentList');
							var tr = $([
									'<tr id="'+list[i].attachment_id+'" name="id">',
									'<td name="attachmentNewName" hidden>'
											+ list[i].attachment_newname
											+ '</td>',
									'<td>' + list[i].attachment_name + '</td>',
									'<td>' + list[i].attachment_size
											+ 'kb</td>',
									'<td>' + list[i].attachment_createtime
											+ '</td>',
									'<td>',
									'<button class="layui-btn layui-btn-mini layui-btn-danger download">下载</button><button class="layui-btn layui-btn-mini layui-btn-danger delete">删除</button>',
									'</td>', '</tr>' ].join(''));

							//删除
							tr.find('.delete').on(
									'click',
									function() {
										var tr = $(this).parent().parent()
										var id = tr.attr("id");
										AjaxTool.XGet(
												"file/delete?attachmentId="
														+ id, null, function(
														data) {
													// delete files[index]; //删除对应的文件
													tr.remove();
													//uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
												})

									});

							tr
									.find('.download')
									.on(
											'click',
											function() {
												var attachmentNewName = $(this)
														.parent()
														.parent()
														.find(
																"[name='attachmentNewName']")
														.text();
												window.location.href = 'file/download?attachmentNewName='
														+ attachmentNewName;
											});
							attachmentList.append(tr);
						}
					})

	layui
			.use(
					'upload',
					function() {
						var $ = layui.jquery, upload = layui.upload;
						//获取绩效汇总Id   
						var id = "110";
						//选完文件后不自动上传
						upload
								.render({
									elem : '#file',
									url : 'file/upload?relationId=' + id,
									accept : 'file' //普通文件
									,
									auto : false,
									exts : 'zip|rar|7z|doc|docx|png|jpg|txt|xls|xlsx'
									//,multiple: true
									,
									bindAction : '#upload',
									size : 200 //限制文件大小，单位 KB
									,
									done : function(res) {

										var json = JSON
												.parse(res.json.jsonText);
										var attachmentList = $('#attachmentList');

										var tr = $([
												'<tr id="'+json.attachmentId+'" name="id">',
												'<td name="attachmentNewName" hidden>'
														+ json.attachmentNewName
														+ '</td>',
												'<td>' + json.attachmentName
														+ '</td>',
												'<td>' + json.attachmentSize
														+ 'kb</td>',
												'<td>' + json.createTime
														+ '</td>',
												'<td>',
												'<button class="layui-btn layui-btn-mini layui-btn-danger download">下载</button><button class="layui-btn layui-btn-mini layui-btn-danger delete">删除</button>',
												'</td>', '</tr>' ].join(''));

										//删除
										tr.find('.delete').on(
												'click',
												function() {
													// var id = tr.attr("id");   
													var tr = $(this).parent()
															.parent()
													var id = tr.attr("id");

													AjaxTool.XGet(
															"file/delete?attachmentId="
																	+ id, null,
															function(data) {
																// delete files[index]; //删除对应的文件
																tr.remove();

															})

												});

										tr
												.find('.download')
												.on(
														'click',
														function() {
															// var attachmentNewName = tr.find("[name='attachmentNewName']").text();
															var attachmentNewName = $(
																	this)
																	.parent()
																	.parent()
																	.find(
																			"[name='attachmentNewName']")
																	.text();
															window.location.href = 'file/download?attachmentNewName='
																	+ attachmentNewName;
														});
										attachmentList.append(tr);

									}
								});

					}); */
</script>
</html>
