<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>领淘报表系统</title>
<link href="../../static/layui/css/layui.css" rel="stylesheet">
<script src="../../static/js/jquery.min.js"></script>
<script src="../../static/layui/layui.js"></script>
<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 id="usename" type="text"name="usename" /> -->
					<input type="text" name="title" lay-verify="required" style="width:500px"
					placeholder="请输入文章标题" class="layui-input" id="title">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">文章类型</label>
				<div class="layui-input-inline">
					<select name="type" lay-verify="required" id="type" lay-filter="type">
						<option value="">请选择</option>
						<option value="1">文学类</option>
						<option value="2">科学类</option>
						<option value="3">玄学类</option>
					</select>
				</div>
				<label class="layui-form-label">文章状态</label>
				<div class="layui-input-inline">
					<select name="status" lay-verify="required" id="status" lay-filter="status">
						<option value="1">发布</option>
						<option value="2">待发布</option>
					</select>
				</div>
			</div>
			<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>
		</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: '<%=basePath%>/uploadconimage', //接口url
					type: 'post' //默认post
				}
			});
			//建立编辑器
			var content = layedit.build('content', {
				height: 330 //设置编辑器高度
			});
			form.verify({
		    	content: function(value) {
		   	 		return layedit.sync(content);
		    	}
		    });	  
			//监听提交
			form.on('submit(formSub)', function(data) {
				$.ajax({
					url : '../addArticle',
					dataType : 'json',
					data:$("form").serialize(),
					/* data : {
						'title'  	: $("#title").val(),
						'type'  	: $("#type").val(),
						'content' 	: $("#content").val()
					}, */
					type : 'post',
					success : function(data) {
						console.log($("#content").val())
						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('articleAll');//重新加载父页面表格
						}, 1100);
					}
				});
				return false;
			});
		});
	</script>
</body>
</html>