<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>就医指南</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <link rel="icon" th:href="@{image/sgl.png}" sizes="32x32">
    <script th:src="@{/layui/layui.js}"></script>
    <script th:src="@{/layui/jquery-3.4.1.min.js}"></script>
    <script th:src="@{/js/common.js}"></script>
    <script th:src="@{/js/rules.js}"></script>
	<script th:src="@{/ueditor/ueditor.config.js}"></script>
	<script th:src="@{/ueditor/ueditor.all.min.js}"></script>
	<script th:src="@{/ueditor/lang/zh-cn/zh-cn.js}"></script>
	<script th:src="@{/js/compressor.min.js}"></script>
    <link rel="stylesheet" th:href="@{/css/common.css}">
</head>
<style>
.btn:hover{color: #555;}
.layui-table-view {margin: 0;}
.layui-tab-card{box-shadow:none;border-radius: 0px;}
.layui-tab{margin:0;}
.layui-tab-content{padding:0;}
.layui-form-radio{margin:0;}
.tdBackground-color{background-color:#ff0000;}
</style>

<body class="layui-layout-body">

	<div class="toolbar">           	
    	<div class="layui-inline">
			<span>标题：</span>
            <input type="text" id="select_name" placeholder="名称关键字" autocomplete="off" class="layui-input formWidth" />
        </div>
        <div class="layui-inline">
			<button class="layui-btn layui-btn-sm" data-type="search" id="search"><i class="layui-icon">&#xe615;</i>查询</button>
		</div>
		<div class="layui-inline">
			<button class="layui-btn layui-btn-sm layui-btn-normal" data-type="add" id="add"><i class="layui-icon">&#xe654;</i>添加</button>
   		</div>
    </div>
    	
	<table id="demo" lay-filter="test"></table>	
	   
	<!-- 表格操作栏 --> 		
	<script type="text/html" id="barDemo">
  		<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
		<a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>
	</script>

	
	<!-- 增加和修改 -->
	<div id="Hospital" style="display:none;">
		<form id="zjHospital" class="" style="margin-top:20px;">
			<div class="layui-form-item">
				<label class="layui-form-label">标题:</label>
				<div class="layui-input-block">
					<input type="text"  id="name" required lay-verify="required" autocomplete="off" placeholder="请输入标题" class="layui-input" style="width: 230px">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">分类:</label>
				<div class="layui-input-block">
					<select id="type" class="layui-select" >
						<option value="">-请选择-</option>
						<option value="1">预约业务</option>
						<option value="2">费用相关业务</option>
						<option value="3">其它业务</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<script id="editor" type="text/plain" style="width:470px;height:260px;"></script>
			</div>
		</form>
	</div>

</body>   
</html>
<script th:inline="javascript">


</script>
<script>
	//修改、启用禁用
	var content = "";
	var ue = UE.getEditor('editor');
	var element ,
	    table,
	    laydate,
	    layer,
	    form,
	    tree,
		upload;
	var tHeight = $(".toolbar").height()+6;
    layui.use(['element','table','laydate','layer','form','tree','upload'], function(){
		element = layui.element;
	    table = layui.table;
	    laydate = layui.laydate;
	    layer = layui.layer;
	    form = layui.form;
	    tree = layui.tree;
	    upload = layui.upload;
	    //表格加载
		table.render({
			elem: '#demo',
			height: 'full-'+tHeight,
			url: '/hospital/findMedicalGuideList', //数据接口
			title: '用户表',
			page: false ,//开启分页
			limit:999,
			//toolbar: '', //开启工具栏，此处显示默认图标，可以自定义模板
			defaultToolbar: [],	 
			id:'test', 
			cols: [
			 [ //表头
			   {type: 'numbers', title: '序号', width: 30},
			   {field: 'NAME', title: '标题', width:300},
			   {field: 'TYPE', title: '分类', width:300, templet:function(d){
			   		if(d.TYPE == '1'){
			   			return '预约业务';
			   		}else if(d.TYPE == '2'){
			   			return '费用相关业务';
			   		}else if(d.TYPE == '3'){
			   			return '其它业务';
			   		}else{
			   			return '';
			   		}
			   }},
			   {fixed: 'right',title:'操作', align:'center',width:240, toolbar: '#barDemo'}
			 ]
			]
		});
	
		//时间控件
		laydate.render({
	  		elem:'#date', //指定元素
	  		eventElem: '.date-input-icon',
	  		trigger: 'click',
		});
		
		//查询
		$("#search").on('click',function(){
			findMedicalGuideList();
		});

		//新增
		$("#add").on('click',function(){
			UE.getEditor('editor').setContent("");
			$("#name").val("");
			$("#type").val("");
			layer.open({
	            type:1,
	            title:"新增内容",
	            shade:0,
				zIndex:5,
	            area: ['500px', '80%'],
	            offset:'auto',
	            content: $("#Hospital"),
	            btn: ['保存', '取消'],
	            btnAlign: 'c',
	            yes: function (index, layero) {
					var name = $("#name").val();
					if(name == ""){
						layer.msg("请填写标题！");
						return;
					}
					var type = $("#type").val();
					if(type == ""){
						layer.msg("请选择分类！");
						return;
					}
					var content = UE.getEditor('editor').getContent();
	            	var param={};
	            	param.name=name;
	            	param.type=type;
	            	param.content=content;
	            	var url='/hospital/addMedicalGuide';
	            	AjaxPostJson(url,param,function(data){
	            		if (data.errCode == "0") {
							layer.close(index);
							layer.msg('添加成功', {time : 1000});
							findMedicalGuideList();
						} else {
							layer.msg(data.message, {time : 1000});
						}
	            	});
	            },
	            btn2:function(){}
        	});	
		})
		

		table.on('tool(test)', function(obj){
			var data = obj.data;
			if(obj.event === 'edit'){

				content = data.CONTENT;
				$("#name").val(data.NAME);
				$("#type").val(data.TYPE);
				setTimeout("setConten()", 500);
				layer.open({
					type:1,
					title:"修改",
					shade:0,
					zIndex:5,
					area: ['500px', '80%'],
					offset:'auto',
					content: $("#Hospital"),
					btn: ['保存', '取消'],
					btnAlign: 'c',
					yes: function (index, layero) {

						//获取值
						var name = $("#name").val();
						if(name == ""){
							layer.msg("请填写标题！");
							return;
						}
						var type = $("#type").val();
						if(type == ""){
							layer.msg("请选择分类！");
							return;
						}
						var content = UE.getEditor('editor').getContent();
						var param={};
						param.name=name;
						param.type=type;
						param.content=content;
						param.medical_guide_id = data.MEDICAL_GUIDE_ID;
						var url='/hospital/updateMedicalGuide';
						AjaxPostJson(url,param,function(data){
							if (data.errCode == "0") {
								layer.close(index);
								layer.msg('修改成功', {time : 1000});
								findMedicalGuideList();
							} else {
								layer.msg(data.message, {time : 1000});
							}
						});
					},
					btn2:function(){}
				});
			}else if(obj.event === 'delete'){
				layer.confirm('确定要删除吗？', function(index){
					var url="/hospital/deleteMedicalGuide";
					var param={};
					param.medical_guide_id=data.MEDICAL_GUIDE_ID;
					AjaxPostJson(url, param, function(data) {
						if (data.errCode == "0") {
							layer.msg('删除成功', {time : 1000});
							findMedicalGuideList();
						} else {
							layer.msg(data.errMsg, {time : 2000});
						}
					});
				})
			}
		});
        
        $(".downpanel").on("click", ".layui-select-title", function (e) {
            $(".layui-form-select").not($(this).parents(".layui-form-select")).removeClass("layui-form-selected");
            $(this).parents(".downpanel").toggleClass("layui-form-selected");
            layui.stope(e);
        }).on("click", "dl i", function (e) {
            layui.stope(e);
        });
        $(document).on("click", function (e) {
            $(".layui-form-select").removeClass("layui-form-selected");
        });
    });

	function setConten(){
		UE.getEditor('editor').setContent(content);
	}
    
  	function findMedicalGuideList(){
		var name = $("#select_name").val();
		table.reload('test', {
			method: 'get',
			url:'/hospital/findMedicalGuideList',
			where: {
				'name':name
			},
			page: {
				curr: 1
			}
		});
	}
    </script>