<%@ 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
}
.edge .layui-edge{
	right:30px;
}
</style>
</head>

<body>
	<div class="layui-input-block layui-form">
		<form class="layui-form" action="" method="post">
			<div class="layui-form-item">
				<input type="hidden" id="type" name="type" value="产品知识">
				<label class="layui-form-label">品种：</label>
				<div class="layui-input-inline edge">
					<select name="proType" lay-filter="proType" lay-search lay-verify="required" class="proType">
						<option></option>
					</select>
				</div>
				<label class="layui-form-label">种类：</label>
				<div class="layui-input-inline edge">
					<select name="kind" lay-filter="kind" lay-search lay-verify="required" class="kind">
					</select>
				</div>
				<label class="layui-form-label">排序</label>
				<div class="layui-input-inline">
					<input type="text" name="sort" placeholder="请输入顺序" class="layui-input" autocomplete="off">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">主体内容</label>
					<textarea id="contentAdd_content" name="content" lay-verify="content" lay-verify="required" 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 src="${path}/js/getTrainData.js" charset="utf-8"></script>
	<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}/imgUpload', //接口url
					type: 'post' //默认post
				}
			});
			//建立编辑器
			var content = layedit.build('contentAdd_content', {
				height: 420 //设置编辑器高度
			});
			// 在线预览
			$(" .layui-layedit .layui-unselect.layui-layedit-tool")
		    .append('<i class="layui-icon layedit-tool-preview" title="预览"  style="font-size:18px"></i>');
			$(document).on('click','.layedit-tool-preview',function(data){
			    parent.layer.open({
			        title: '在线预览',
			        shade: 0.2,
			        move: false,
			        content: layedit.getContent(content),
			        offset: 'rt',
			        area: ['450px',(top.window.innerHeight*0.80).toString()]
			    });
			});
			form.verify({
		    	content: function(value) {
		   	 		return layedit.sync(content);
		    	}
		    });	 
			
			//监听提交
			form.on('submit(formSub)', function(data) {
				$.ajax({
					url : '${path}/addCustomerTrainContent',
					dataType : 'json',
					data:$("form").serialize(),
					type : 'post',
					success : function(data) {
						if (data.code == 200) {
							layer.msg('录入成功！',{icon:6,offset:"auto",time:1000});//提示框
							setTimeout(function(){
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);//关闭弹出层
								parent.layui.table.reload('trainContentAll');//重新加载父页面表格
							}, 1100);
						}else  {
							layer.msg('录入失败！',{icon:5,offset:"auto",time:1000});//提示框
						}
					}
				});
				return false;
			});
		});
	</script>
</body>
</html>