<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <title text="">代码生成导入</title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css">
    <style>
        .layui-table-tool {display: none;}
        .layui-card-body {padding: 10px 15px 5px 15px;}
    </style>
</head>
<body class="pear-container">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">表名称</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" type="text" name="tableName" placeholder="" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">表描述</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" type="text" name="tableComment" placeholder="" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="button" class="pear-btn pear-btn-md-0 pear-btn-primary" lay-submit lay-filter="query">
                            <i class="layui-icon layui-icon-search"></i> 搜索
                        </button>
                        <button type="reset" class="pear-btn pear-btn-md-0">
                            <i class="layui-icon layui-icon-refresh"></i> 重置
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="table" lay-filter="table"></table>
        </div>
    </div>
<script type="text/html" id="createTime">
    {{ layui.util.toDateString(d.createTime, 'yyyy-MM-dd') }}
</script>
<script type="text/html" id="updateTime">
    {{ layui.util.toDateString(d.updateTime, 'yyyy-MM-dd') }}
</script>
<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script>
    layui.use(['request', 'form', 'common', 'table'], function() {
        var $ = layui.jquery,
            request = layui.request,
            form = layui.form,
            table = layui.table;

        var MODULE_PATH = "/generator/v1/";

        request.tableRender({
            url: MODULE_PATH + 'database',
            defaultToolbar: [],
            cols: [
                [
                    {type: 'checkbox', width: 40},
                    {title: '表名称',  field: 'tableName' },
                    {title: '表描述',  field: 'tableComment' },
                    {title: '创建时间',field: 'createTime', width: 160, sort: true, templet: '#createTime'},
                    {title: '更新时间',field: 'updateTime', width: 160, templet: '#updateTime'}
                ]
            ]
        });

        form.on('submit(query)', function (data) {
            window.refresh(data.field);
            return false;
        });

        window.refresh = function (param) {
            table.reload('table', {where: param});
        }
    });

    function submitHandler() {
        var check = layui.table.checkStatus('table');
        if (check.data.length === 0) {
            parent.layer.alert("请至少选择一条记录");
            return;
        }
        layui.request.http({
            url: "/generator/v1/",
            type: 'post',
            data: {"params": layui.common.joinArray(check.data, "tableName")},
            success: function (result) {
                if (result.success) {
                    parent.layui.popup.success(result.msg, function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        parent.refresh();
                    })
                } else {
                    parent.layui.popup.failure(result.msg);
                }
            }
        })
    }
</script>
</body>
</html>
