<%@ 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>修改ip</title>
<%@include file="/views/common.jsp"%>
<link rel="stylesheet" href="${path}/static/css/formSelects-v4.css">
<style>
.layui-input,.layui-input-inline{
	width:350px
}
</style>
</head>
<body>
	<div class="layui-input-block layui-form" lay-filter="updateIp"
		style="margin-top: 30px">
		<form class="layui-form " action="">
			<div class="layui-form-item">
				<input type="hidden" name="id" id="id" value="" />
				<label class="layui-form-label">授权IP</label>
				<div class="layui-input-inline">
					<input type="text" name="agreeIp" placeholder="请输入IP" id="agreeIp" class="layui-input" autocomplete="off">
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">说明</label>
					<div class="layui-input-inline">
						<input type="text" name="remark" id="remark" placeholder="请输入说明" class="layui-input" autocomplete="off">
					</div>
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit="" lay-filter="enadd">确认</button>
				</div>
			</div>
		</form>
	</div>
<script>
		
		layui.use(['form', 'layer'],function() {
			var $ = layui.$,
			form = layui.form, 
			layer = layui.layer;

			$(document).ready(function() {
				$('#agreeIp').blur(function() {
					var param = {
						agreeIp : $("#agreeIp").val()
					}
					$.getJSON("${path}/checkIP",param,function(data) {
						console.log(data)
						if (data.code == 200) {
							layer.tips('IP符合规范','#agreeIp',{tips : [2,'#009688' ],time : 1500});
						} else {
							layer.tips('IP已存在，请重新输入','#agreeIp',{tips : [2,	'red' ],time : 0});
						}
					})
				});
			})
			
			//监听提交
			form.on('submit(enadd)', function(data) {
				$.ajax({
					url : '${path}/updateIp',
					dataType : 'json',
					data : $(data.form).serialize(),
					type : 'post',
					success : function(data) {
						if (data.code == 200) {
							layer.msg('修改成功！',{icon:6,offset:"auto",time:2000});//提示框
						}else  {
							layer.msg('修改失败！',{icon:5,offset:"auto",time:2000});//提示框
						}
						setTimeout(function(){
							var index = parent.layer.getFrameIndex(window.name);//获取窗口索引
							parent.layer.close(index);//关闭弹出层
							parent.layui.table.reload("loginIpTableAll"); //重新加载页面表格
						}, 2100);
					}
				})
				return false;
			});
		})
</script>
</body>
</html>