<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" th:href="@{/images/logo.jpg}"/>
    <link rel="stylesheet" th:href="@{/js/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/js/layui/css/admin.css}">
    <script type="text/javascript" th:src="@{/js/jquery-3.3.1.min.js}"></script>
    <script th:src="@{/js/layui/layui.js}" charset="utf-8"></script>
</head>
<body>
<div class="layui-form" style="padding: 20px 0 0 0;">
    <form id="formId" onsubmit="return false;">

        <input type="hidden" class="layui-input" th:value="${obj.id}" name="id">


        <div class="layui-input-inline">
            <label class="layui-form-label">小区名称</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="areaName" th:value="${obj.areaName}" placeholder="请输入小区名称"
                       name="areaName" style="width: 300px">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <label class="layui-form-label">小区地址</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="province" th:value="${obj.province}" placeholder="省"
                           name="province" style="width: 100px">
                </div>
            </div>
            <div class="layui-input-inline">
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="city" th:value="${obj.city}" placeholder="市"
                           name="city" style="width: 100px">
                </div>
            </div>
            <div class="layui-input-inline">
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="region" th:value="${obj.region}" placeholder="区"
                           name="region" style="width: 100px">
                </div>
            </div>
            <div class="layui-input-inline">
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="areaAddress" th:value="${obj.areaAddress}"
                           placeholder="详细地址"
                           name="areaAddress" style="width: 300px">
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">联系人</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="liaisonMan" th:value="${obj.liaisonMan}" placeholder="联系人"
                       name="liaisonMan" style="width: 300px">
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="liaisonPhone" th:value="${obj.liaisonPhone}"
                       placeholder="联系电话"
                       name="liaisonPhone" style="width: 300px">
            </div>
        </div>

        <button class="layui-btn" style="display: none;" id="saveBtn" onclick="save()">保存</button>
    </form>
</div>
<script>

    layui.use('form', function () {
        var form = layui.form;
        form.render();
    });

    function save() {

        var id = '[[${obj.id}]]';


        var areaName = $("#areaName").val().trim();
        if (areaName == '') {
            layer.msg("小区名称不能为空!");
            return false;
        }


        var province = $("#province").val().trim();
        if (province == '') {
            layer.msg("省份不能为空!");
            return false;
        }

        var city = $("#city").val().trim();
        if (city == '') {
            layer.msg("城市不能为空!");
            return false;
        }
        var region = $("#region").val().trim();
        if (region == '') {
            layer.msg("区域不能为空!");
            return false;
        }
        var areaAddress = $("#areaAddress").val().trim();
        if (areaAddress == '') {
            layer.msg("详细地址不能为空!");
            return false;
        }
        var liaisonMan = $("#liaisonMan").val().trim();
        if (liaisonMan == '') {
            layer.msg("联系人不能为空!");
            return false;
        }
        var liaisonPhone = $("#liaisonPhone").val().trim();
        if (liaisonPhone == '') {
            layer.msg("联系电话不能为空!");
            return false;
        }

        var param = {};
        param.id = id;
        param.areaName = areaName;
        param.province = province;
        param.city = city;
        param.region = region;
        param.areaAddress = areaAddress;
        param.liaisonMan = liaisonMan;
        param.liaisonPhone = liaisonPhone;
        $.ajax({
            url: "addOrUpdate",
            data: JSON.stringify(param),
            type: "POST",
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            success: function (result) {
                if (result.code == 100) {
                    closeLayer();
                    parent.layui.table.reload('tableId');
                } else {
                    layer.msg(result.msg, {icon: 5});
                }
            }
        });
    }

    function closeLayer() {
        //关闭当前frame
        parent.layer.close(parent.layer.getFrameIndex(window.name));
    }

</script>
</body>

</html>