<!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">
</head>
<body class="pear-container">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">表名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="tableName" placeholder="" class="layui-input">
                    </div>
                    <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>
            </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="toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="import">
        <i class="pear-icon pear-icon-import"></i> 导入
    </button>
</script>
<script type="text/html" id="bar">
    <a class="cool-line-btn cool-bg-blue" lay-event="edit">编辑</a>
    <div class="cool-line-divider"></div>
    <a class="cool-line-btn cool-bg-blue" lay-event="generate">生成</a>
</script>
<script type="text/html" id="createTime">
    {{ layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss') }}
</script>
<script type="text/html" id="updateTime">
    {{ layui.util.toDateString(d.updateTime, 'yyyy-MM-dd HH:mm:ss') }}
</script>
<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script>
    layui.use(['request', 'form', 'table', 'popup'], function () {
        var $ = layui.jquery,
            request = layui.request,
            form = layui.form,
            table = layui.table;

        var MODULE_PATH = "/generator/v1/";

        request.tableRender({
            url: MODULE_PATH,
            cols: [
                [
                    {type: 'checkbox'},
                    {title: '表名称', field: 'tableName'},
                    {title: '表注释', field: 'tableComment'},
                    {title: '创建时间', field: 'createTime',templet: '#createTime'},
                    {title: '更新时间', field: 'updateTime',templet: '#updateTime'},
                    {title: '操作', toolbar: '#bar', align: 'center'}
                ]
            ]
        });

        table.on('toolbar(table)', function (obj) {
            if (obj.event === 'refresh') {
                window.refresh();
            }
            else if(obj.event === 'import') {
                window.import();
            }
        });

        table.on('tool(table)', function (obj) {
            if (obj.event === 'edit') {
                window.edit(obj);
            }
            else if (obj.event === 'generate') {
                window.generate(obj);
            }
        });

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

        window.import = function () {
            layer.open({
                type: 2,
                title: '导入表结构',
                shade: 0.1,
                area: ['1000px', '600px'],
                content: "import.html",
                btn: ["确定", "取消"],
                yes: function (index, layero) {
                    layero.find('iframe')[0].contentWindow.submitHandler();
                },
                cancel: function (index, layero) {
                    layui.layer.close(index);
                    return false;
                }
            });
        };

        window.generate = function (obj) {
            layer.open({
                type: 2,
                title: '代码生成',
                shade: 0.1,
                area: ['460px', '280px'],
                content: 'generate.html?id=' + obj.data.id
            });
        };

        window.edit = function (obj) {
            parent.layui.tab.addTabOnlyByElem('content', {
                id: "gen" + obj.data.id,
                title: '生成配置',
                url: 'view/generator/edit.html?id=' + obj.data.id,
                close: true
            })
        };

        window.refresh = function (param) {
            table.reload('table', {where: param});
        }
    });
</script>
</body>
</html>
