<!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>
    <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="hospitalName" 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="editHospital" style="display:none;">
		<form id="updateHospital" 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="editHospitalName" required lay-verify="required" autocomplete="off" placeholder="请输入院区名称" class="layui-input formWidthTwo">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">联系电话:</label>
				<div class="layui-input-block">
					<input type="text"  id="editHospitalPhone" required lay-verify="required" autocomplete="off" placeholder="请输入联系电话" class="layui-input formWidthTwo">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">公交:</label>
				<div class="layui-input-block">
					<input type="text"  id="editHospitalBusRoute" required lay-verify="required" autocomplete="off" placeholder="请输入公交" class="layui-input formWidthTwo">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">院区地址:</label>
				<div class="layui-input-block">
					<input type="text"  id="editHospitalAddress" required lay-verify="required" autocomplete="off" placeholder="请输入院区地址" class="layui-input formWidthTwo">
				</div>
			</div>
		</form>
	</div>
	
	<!-- 增加 -->
	<div id="addHospital" style="display:none;">
		<form id="zjHospital" class="" style="margin-top:20px;">
			<div class="layui-form-item">
                <label class="layui-form-label" lay-verify="required">院区名称:</label>
                <div class="layui-input-block">
                    <input type="text"  id="addHospitalName" required lay-verify="required" autocomplete="off" placeholder="请输入院区名称" class="layui-input formWidthTwo">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系电话:</label>
                <div class="layui-input-block">
                    <input type="text"  id="addHospitalPhone" required lay-verify="required" autocomplete="off" placeholder="请输入联系电话" class="layui-input formWidthTwo">
                </div>
            </div>
			<div class="layui-form-item">
				<label class="layui-form-label">公交:</label>
				<div class="layui-input-block">
					<input type="text"  id="addHospitalBusRoute" required lay-verify="required" autocomplete="off" placeholder="请输入公交" class="layui-input formWidthTwo">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">院区地址:</label>
				<div class="layui-input-block">
					<input type="text"  id="addHospitalAddress" required lay-verify="required" autocomplete="off" placeholder="请输入院区地址" class="layui-input formWidthTwo">
				</div>
			</div>
            <!--<div class="layui-form-item">
                <label class="layui-form-label">用户角色:</label>
               	<div class="layui-input-inline">
                <select id="addRoleId" class="layui-select formWidthTwo" >
					<option value="">-请选择-</option>
					<option th:each="role : ${roleList}" th:value="${role.roleId}" th:text="${role.roleName}"></option>
				</select>
				</div>
            </div>-->
		</form>
	</div>

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


</script>
<script>
	var element ,
	    table,
	    laydate,
	    layer,
	    form,
	    tree;
	var tHeight = $(".toolbar").height()+6;
    layui.use(['element','table','laydate','layer','form','tree'], function(){
		element = layui.element;
	    table = layui.table;
	    laydate = layui.laydate;
	    layer = layui.layer;
	    form = layui.form;
	    tree = layui.tree;
	    
	    //表格加载
		table.render({
			elem: '#demo',
			height: 'full-'+tHeight,
			url: '/doctor/findDoctorPageList', //数据接口
			title: '用户表',
			page: false ,//开启分页
			limit:999,
			limits:[20,30,50],
			//toolbar: '', //开启工具栏，此处显示默认图标，可以自定义模板
			defaultToolbar: [],
			id:'test',
			cols: [
			 [ //表头
			   	 {type: 'numbers', title: '序号', width: 30},
			     {field: 'DOCTOR_NAME', title: '医生名称'},
				 {field: 'DOCTOR_IMG', title: '医生头像',templet:function(d){
				 	return '<img src="'+d.DOCTOR_IMG+'">'
					 }},
				 {field: 'HOSPITAL_NAME', title: '院区'},
				 {field: 'DOCTOR_TITLE', title: '职称'},
				 {field: 'OFFICE_NAME', title: '科室'},
				 {field: 'DOCTOR_NAME', title: '标签'},
				 {field: 'DOCTOR_ABOUT', title: '医生简介'}
			   /*{fixed: 'right',title:'操作', align:'center',width:240, toolbar: '#barDemo'}*/
			 ]
			]
		});
	
		//时间控件
		laydate.render({
	  		elem:'#date', //指定元素
	  		eventElem: '.date-input-icon',
	  		trigger: 'click',
		});
		
		//查询
		$("#search").on('click',function(){
			findHospitalPageList();
		});
		
		//新增
		$("#add").on('click',function(){
			$("#addHospitalName").val("");
			$("#addHospitalPhone").val("");
			$("#addHospitalBusRoute").val("");
			$("#addHospitalAddress").val("");
			layer.open({
	            type:1,
	            title:"新增内容",
	            shade:0,
	            area: ['500px', '80%'],
	            offset:'auto',
	            content: $("#addHospital"),
	            btn: ['保存', '取消'],
	            btnAlign: 'c',
	            yes: function (index, layero) {
	            	//获取值
					var hospitalName = $("#addHospitalName").val();
					var hospitalPhone = $("#addHospitalPhone").val();
					var hospitalBusRoute = $("#addHospitalBusRoute").val();
					var hospitalAddress = $("#addHospitalAddress").val();
	            	if(hospitalName=="" || hospitalName==null){
	            		layer.msg('用户名不能为空',{time:1000});
	            		$("#addHospitalName").focus();
	            		return;
	            	}
	            	var param={};
	            	param.hospitalName=hospitalName;
	            	param.hospitalPhone=hospitalPhone;
	            	param.hospitalBusRoute=hospitalBusRoute;
	            	param.hospitalAddress=hospitalAddress;
	            	var url='/hospital/insertHospital';
	            	AjaxPostJson(url,param,function(data){
	            		if (data.errCode == "0") {
							layer.close(index);
							layer.msg('添加成功', {time : 1000});
							findHospitalPageList();
						} else {
							layer.msg(data.message, {time : 1000});
						}
	            	});
	            },
	            btn2:function(){}
        	});	
		})
		
		//修改、启用禁用
		table.on('tool(test)', function(obj){
			var data = obj.data;
			if(obj.event === 'edit'){
				$("#editHospitalName").val(data.HOSPITAL_NAME);
				$("#editHospitalPhone").val(data.HOSPITAL_PHONE);
				$("#editHospitalBusRoute").val(data.HOSPITAL_BUS_ROUTE);
				$("#editHospitalAddress").val(data.HOSPITAL_ADDRESS);
				layer.open({
                    type:1,
                    title:"修改信息",
                    shade:0,
                    area: ['500px', '80%'],
                    offset:'auto',
                    content: $("#editHospital"),
                    btn: ['保存', '取消'],
                    btnAlign: 'c',
                    yes: function (index, layero) {
						var hospitalName = $("#editHospitalName").val();
						var hospitalPhone = $("#editHospitalPhone").val();
						var hospitalBusRoute = $("#editHospitalBusRoute").val();
						var hospitalAddress = $("#editHospitalAddress").val();
						if(hospitalName=="" || hospitalName==null){
							layer.msg('用户名不能为空',{time:1000});
							$("#editHospitalName").focus();
							return;
						}
						var param={};
						param.hospitalName=hospitalName;
						param.hospitalPhone=hospitalPhone;
						param.hospitalBusRoute=hospitalBusRoute;
						param.hospitalAddress=hospitalAddress;
						param.hospitalId = data.HOSPITAL_ID;
						var url='/hospital/updateHospital';
		            	AjaxPostJson(url,param,function(data){
		            		if (data.errCode == "0") {
		            			layer.close(index);
								layer.msg('修改成功', {time : 1000});
								findHospitalPageList();
							} else {
								layer.msg(data.errMsg, {time : 2000});
							}
		            	});
                    	
                    },
                    btn2:function(){
                    	
                    }
                });				
			}else if(obj.event === 'delete'){
				layer.confirm('确定要删除吗？', function(index){
					var url="/hospital/deleteHospitalById";
					var param={};
					param.hospitalId=data.HOSPITAL_ID;
					AjaxPostJson(url, param, function(data) {
						if (data.errCode == "0") {
							layer.msg('删除成功', {time : 1000});
							findHospitalPageList();
						} 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 findHospitalPageList(){
		var hospitalName = $("#hospitalName").val();
		table.reload('test', {
			method: 'get',
			url:'/hospital/findHospitalPageList',
			where: {
				'hospitalName':hospitalName
			},
			page: {
				curr: 1
			}
		});
	}
    </script>