<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>领淘报表系统</title>
<%@include file="/views/common.jsp"%>
<style>
  .layui-input-block{
  	   margin-left: 10px;
  }
  .layui-form-item {
  		margin-top:20px;
  }
  .btn_groups{
  		width:200px;
  		margin:auto
  }
</style>
</head>

<body>
	<div class="layui-input-block layui-form">
		<form class="layui-form" action="" method="post">
			<div class="layui-form-item">
				<label class="layui-form-label">更新日期</label>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" id="addTime" name="addTime"
						placeholder="yyyy-MM-dd" readonly="readonly" lay-verify="required" >
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">主体内容</label>
					<textarea id="content" name="content" lay-verify="content" style="display: none;"></textarea>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block btn_groups">
					<button class="layui-btn" lay-submit="" lay-filter="formSub">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</div>
		</form>
	</div>
	<script type="text/javascript">
		layui.use([ 'form', 'laydate','layedit' ], function() {
			var form = layui.form;
			var laydate = layui.laydate;
			var layedit = layui.layedit;
			var $ = layui.$;
			
			layedit.set({
				uploadImage: {
					url: '${path}/uploadconimage', //接口url
					type: 'post' //默认post
				}
			});
			//建立编辑器
			var content = layedit.build('content', {
				height: 330 //设置编辑器高度
			});
			form.verify({
		    	content: function(value) {
		   	 		return layedit.sync(content);
		    	}
		    });	 
			
			
			//日期时间选择器
			laydate.render({
			   elem: '#addTime',
			   type: 'datetime'
			});
			
			//监听提交
			form.on('submit(formSub)', function(data) {
				$.ajax({
					url : '${path}/addLog',
					dataType : 'json',
					//data:$("form").serialize(),
					data : {
						// 后台无法直接解析字符串，需要转化
						'addTimeStr': $("#addTime").val(),
						'content'   : $("#content").val()
					},
					type : 'post',
					success : function(data) {
						console.log(data)
						if (data.code == 200) {
							layer.msg('录入成功！',{icon:6,offset:"auto",time:1000});//提示框
						}else  {
							layer.msg('录入失败！',{icon:5,offset:"auto",time:1000});//提示框
						}
						setTimeout(function(){
							var index = parent.layer.getFrameIndex(window.name);
							parent.layer.close(index);//关闭弹出层
							parent.layui.table.reload('logAll');//重新加载父页面表格
						}, 1100);
					}
				});
				return false;
			});
		});
	</script>
</body>
</html>