<%@ 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;
}
.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">
			<input type="hidden" id="type" name="type" value="售前客服必备技能">
			<input type="hidden" id="idUpdate_content" name="id"/>
			<input type="hidden" id="proTypeUpdateInput_content"/>
			<input type="hidden" id="kindUpdateInput_content"/>
			<br>
			<div class="layui-form-item">
				<label class="layui-form-label">品种：</label>
				<div class="layui-input-inline edge">
					<select id="proTypeUpdate_content" name="proType" lay-search lay-filter="proType" class="proType">
						<option></option>
					</select>
				</div>
				<label class="layui-form-label">种类：</label>
				<div class="layui-input-inline edge">
					<select id="kindUpdate_content" name="kind" lay-search lay-filter="kind" class="kind">
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">主体内容</label>
					<textarea id="contentUpdate_content" name="content" lay-verify="content" style="display: none;"></textarea>
				</div>
			</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 src="${path}/js/getTrainProType.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('contentUpdate_content', {
				height: 420 //设置编辑器高度
			});
			form.verify({
		    	content: function(value) {
		   	 		return layedit.sync(content);
		    	}
		    });	 
			layui.form.render();
			
			//一访问页面就调用
			$.ajax({
				url:"/quote_price/getCustomerTrainProTypes",
				type : "GET",
				dataType : "json",
				data:{
					type:$("#type").val()
				},
				success : function(result) {
					var data = result.list
					$.each(data,function(index,item){
						$('.proType').append(new Option(item.proType,item.proType));//往下拉菜单里添加元素
					});
					//把input的值给下拉框，再渲染。做到动态下拉框回显
					$("#proTypeUpdate_content").val($("#proTypeUpdateInput_content").val());
					layui.form.render("select");
				}
			});
			$.ajax({
				url:"/quote_price/getCustomerTrainKindLabelsByProType",
				type : "GET",
				dataType : "json",
				data:{
					proType	:$("#proTypeUpdateInput_content").val(),
					type	:$("#type").val(),
					needPage:"0"
				},
				success : function(result) {
					var data = result.list
					$.each(data,function(index,item){
						$('.kind').append(new Option(item.kindLabel,item.kindLabel));//往下拉菜单里添加元素
					});
					//把input的值给下拉框，再渲染。做到动态下拉框回显
					$("#kindUpdate_content").val($("#kindUpdateInput_content").val());
					layui.form.render("select");
				}
			});
			
			// 下拉框联动
			form.on('select(proType)', function(data) {
				$('.kind').empty();
				$('.kind').append(new Option("",""));
			    form.render("select");
				$.ajax({
					url:"/quote_price/getCustomerTrainKindLabelsByProType",
					type : "GET",
					dataType : "json",
					data:{
						proType	:data.value,
						type	:$("#type").val(),
						needPage:"0"
					},
					success : function(result) {
						var data = result.list
						$.each(data,function(index,item){
							$('.kind').append(new Option(item.kindLabel,item.kindLabel));//往下拉菜单里添加元素
						});
						//把input的值给下拉框，再渲染。做到动态下拉框回显
						$("#kindUpdate_content").val($("#kindUpdateInput_content").val());
						layui.form.render("select");
					}
				});
			});
			
			//监听提交
			form.on('submit(formSub)', function(data) {
				$.ajax({
					url : '${path}/updateCustomerTrainContent',
					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>