<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
>
<head>
    <meta charset="UTF-8">
    <title>设备编辑</title>
    <link rel="stylesheet" href="/css/metroStyle/metroStyle.css">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="/css/public.css">
    <style type="text/css">
        .layui-form-label {
            width: 100px;
        }
    </style>
</head>
<body class="child-body">
<div class="child-nav">
    <span class="layui-breadcrumb">
         <a>系统管理</a>
         <a href="/admin/device/list">设备列表</a>
         <a><cite th:text="${#strings.equals(device.id,null)?'新增设备':'修改设备'}"></cite></a>
    </span>
    <a class="layui-btn layui-btn-sm" href="javascript:location.replace(location.href);" title="刷新"
       style="float:right;margin-top: 3px"><i class="layui-icon" style="line-height:30px">&#x1002;</i></a>
</div>
<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-header" th:text="${#strings.equals(device.id,null)?'新增设备':'修改设备'}"></div>
        <div class="layui-card-body">
            <form class="layui-form" action="/admin/device/save" method="post">
                <input type="hidden" id="deviceId" name="id" th:value="${device.id}">
                <div class="layui-form-item">
                    <label class="layui-form-label">设备号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="deviceId" th:value="${device.deviceId}" lay-verify="required"
                               lay-vertype="tips" class="layui-input" >
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备号16进制码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="deviceId16Hex" th:value="${device.deviceId16Hex}" lay-verify="required"
                               lay-vertype="tips" class="layui-input" >
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备类型</label>
                    <div class="layui-input-inline">
                        <select name="deviceType" lay-verify="required">
                            <option value="YG" th:selected="${#strings.equals(device.deviceType,'YG')}">烟感</option>
                            <option value="JG" th:selected="${#strings.equals(device.deviceType,'JG')}">井盖</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="save"
                                th:text="${#strings.equals(device.id,null)?'保存':'修改'}"></button>
                        <a href="javascript:history.back()" type="button" class="layui-btn layui-btn-primary">返回</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="/plugins/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['element', 'form', 'laydate', 'upload'], function () {
        var form = layui.form, $ = layui.jquery;

        //监听提交
        form.on('submit(save)', function (data) {
            var headers = {};
            headers['X-CSRF-TOKEN'] = "[[${_csrf.token}]]";
            $.ajax({
                url: data.form.action,
                type: data.form.method,
                headers: headers,
                data: data.field,
                dataType: 'json',
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                            location.href = "/admin/device/list";
                        });
                    } else {
                        layer.msg(data.msg, {time: 1000});
                    }
                }
            });
            return false;
        });

        form.render();
    });
</script>
</body>
</html>