<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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;
  }
  .btn_groups{
  		width:200px;
  		margin:auto
  }
</style>
</head>

<body>
	<div class="layui-input-block layui-form">
		<form class="layui-form" action="" method="post" lay-filter="articleForm">
			<div class="layui-form-item">
				<input id="id" type="hidden"name="id" />
				<label class="layui-form-label">文章标题</label>
				<div class="layui-input-inline">
					<input type="text" name="title" lay-verify="required"
					placeholder="请输入文章标题" class="layui-input" id="titleUp">
				</div>
			</div>
			<input type="hidden" class="layui-input" id="TYPE">
			<div class="layui-form-item">
				<label class="layui-form-label">文章类型</label>
				<div class="layui-input-inline">
					<select name="type" lay-verify="required" id="typeUp" lay-filter="type">
						<option value="">请选择</option>
						<option value="1">1</option>
						<option value="2">2</option>
						<option value="3">3</option>
					</select>
				</div>
			</div>
			<input type="hidden" class="layui-input" id="CONTENT">
			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label">主体内容</label>
				<textarea id="contentUp" 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: '../uploadconimage', //接口url
					type: 'post' //默认post
				}
			});
			//建立编辑器
			var content = layedit.build('contentUp', {
				height: 330 //设置编辑器高度
			});
			form.verify({
		    	content: function(value) {
		   	 		return layedit.sync(content);
		    	}
		    });	 
			console.log($("#TYPE").val())
			console.log($("#CONTENT").val())
			layui.form.render();
			//监听提交
			form.on('submit(formSub)', function(data) {
				$.ajax({
					url : '../updateArticle',
					dataType : 'json',
					data : {
						'id'  		: $("#id").val(),
						'title'  	: $("#titleUp").val(),
						'type'  	: $("#typeUp").val(),
						'content' 	: $("#contentUp").val()
					},
					type : 'post',
					success : function(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('articleAll');//重新加载父页面表格
						}, 1100);
					}
				});
				return false;
			});
		});
	</script>
</body>
</html>