<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="${#request.getContextPath() + '/'} ">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
    <link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
</head>
<body>
<div class="layui-fluid layui-anim layui-anim-fadein" style="padding: 0;">
    <div class="layui-row">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="test-table-reload-btn" style="margin-bottom: 10px;">
                        <div class="layui-inline">
                            <input type="text" id="keywords" class="layui-input search-item" placeholder="输入名称">
                        </div>
                        <div class="layui-btn-group">
                            <button type="button" id="search" class="layui-btn layui-btn-sm">
                                <i class="fa fa-lg fa-search"></i> 搜索
                            </button>
                        </div>
                    </div>
                    <table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="areaParentId" th:value="${areaParentId}">
<script src="assets/layuiadmin/layui/layui.js"></script>
<script type="text/javascript">
    layui.config({
        base: 'assets/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'table', 'laydate', 'ztree'], function() {
        var $ = layui.$;
        var $win = $(window);
        var table = layui.table;
        var admin = layui.admin;
        var laydate = layui.laydate;
        var parentId = top.restAjax.params(window.location.href).parentId;
        var tableUrl = top.restAjax.path('api/mongo/area/listpage?parentId={parentId}', [parentId]);

        // 初始化表格
        function initTable() {
            table.render({
                elem: '#dataTable',
                id: 'dataTable',
                url: tableUrl,
                width: admin.screen() > 1 ? '100%' : '',
                height: $win.height() - 60,
                limit: 20,
                limits: [20, 40, 60, 80, 100, 200],
                toolbar: '#headerToolBar',
                request: {
                    pageName: 'page',
                    limitName: 'rows'
                },
                cols: [
                    [
                        {type:'checkbox', fixed: 'left'},
                        {field:'rowNum', width:80, title: '序号', fixed: 'left', align:'center', templet: '<span>{{d.LAY_INDEX}}</span>'},
                        {field:'areaId', width:120, title: '地区ID', align:'center',},
                        {field:'areaName', width:160, title: '地区名称', align:'center',},
                        {field:'areaCode', width:160, title: '地区编码', align:'center',},
                        {field:'areaCityCode', width:160, title: '城市编码', align:'center',},
                        {field:'areaMergerName', width:160, title: '合并名称', align:'center',},
                        {field:'areaShortName', width:160, title: '简称', align:'center',},
                        {field:'areaZipCode', width:160, title: '邮政编码', align:'center',},
                        {field:'areaLevel', width:60, title: '级别', align:'center',},
                        {field:'areaLng', width:160, title: '地区经度', align:'center',},
                        {field:'areaLat', width:160, title: '地区纬度', align:'center',},
                        {field:'areaPinyin', width:160, title: '拼音', align:'center',},
                        {field:'areaFirst', width:80, title: '首字母', align:'center',},
                    ]
                ],
                page: true,
                parseData: function(data) {
                    return {
                        'code': 0,
                        'msg': '',
                        'count': data.total,
                        'data': data.rows
                    };
                }
            });
        }
        // 重载表格
        function reloadTable() {
            table.reload('dataTable', {
                url: tableUrl,
                where: {
                    keywords: $('#keywords').val(),
                },
                height: $win.height() - 60,
            });
        }
        // 初始化日期
        function initDate() {}
        initTable();
        initDate();

        // 事件 - 页面变化
        $win.on('resize', function() {
            reloadTable();
        });
        // 事件 - 搜索
        $(document).on('click', '#search', function() {
            reloadTable();
        });
    });
</script>
</body>
</html>