<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('数据类型列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <div class="select-list">
                    <div class="form-group">
                        <div class="col-sm-12">
                            <p class="form-control-static" th:attr="style='color:#333'" th:text="'模型名称 ：' + ${modelProject.modelName}"></p>
                        </div>
                        <div class="col-sm-12">
                            <p class="form-control-static" th:attr="style='color:#333'" th:text="'模型描述 ：' + ${modelProject.modelRemark}"></p>
                        </div>
                    </div>
                </div>
                <form id="formId">
                    <input type="hidden" id="projectId" name="projectId" th:value="${modelProject.id}">
                    <input type="hidden" id="versionId" name="versionId" th:value="${modelProject.versionId}">
                </form>
            </div>

<!--            <div class="col-sm-12 search-collapse">-->
<!--                <form id="formId">-->
<!--                    <input type="hidden" id="projectId" name="projectId" th:value="${modelProject.id}">-->
<!--                    <input type="hidden" id="versionId" name="versionId" th:value="${modelProject.versionId}">-->
<!--                    <div class="select-list">-->
<!--                        <ul>-->
<!--                            <li>-->
<!--                                数据类型名称：-->
<!--                                <input type="text" name="dataTypeName"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                数据类型代码：-->
<!--                                <input type="text" name="dataTypeCode"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>-->
<!--                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>-->
<!--                            </li>-->
<!--                        </ul>-->
<!--                    </div>-->
<!--                </form>-->
<!--            </div>-->

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:hasPermission="model:dataType:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="model:dataType:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="model:dataType:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="model:dataType:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                </a>-->
                <a class="btn btn-danger" onclick="closeItem()">
                    <i class="fa fa-reply-all"></i> 关闭
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"
                       data-use-row-attr-func="true"
                       data-reorderable-rows="true"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-table-reorder-rows-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('model:dataType:edit')}]];
        var removeFlag = [[${@permission.hasPermi('model:dataType:remove')}]];
        var prefix = ctx + "model/dataType";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                onReorderRow: function (data) {
                    saveSorted(JSON.stringify(data))
                    return true;
                },
                modalName: "数据类型",
                pagination: true,
                showSearch: true,
                showRefresh: true,
                showToggle: true,
                showColumns: true,
                // sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'dataTypeName',
                    title: '数据类型名称'
                },
                {
                    field: 'dataTypeCode',
                    title: '数据类型代码'
                },
                {
                    field: 'mysqlCode',
                    title: 'MYSQL'
                },
                // {
                //     field: 'oracleCode',
                //     title: 'ORACLE'
                // },
                // {
                //     field: 'sqlserverCode',
                //     title: 'SQLServer'
                // },
                // {
                //     field: 'postgresqlCode',
                //     title: 'PostgreSQL'
                // },
                // {
                //     field: 'javaCode',
                //     title: 'JAVA'
                // },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'versionId',
                    title: '版本id',
                    visible: false
                },
                {
                    field: 'dataSort',
                    title: '排序',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /*新增数据类型*/
        function add() {
            var projectId = $("#projectId").val();
            $.operate.add(projectId);
        }

        function saveSorted(data) {
            var table = $("#bootstrap-table").bootstrapTable('getOptions');
            var pageSize = table.pageSize;
            var pageNumber = table.pageNumber;
            var sortParams = {
                "pageSize": pageSize,
                "pageNumber": pageNumber,
                "sortData": data
            };

            $.ajax({
                url: prefix + "/sort",
                type: "post",
                dataType: "json",
                data: {
                    params: sortParams
                },
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    $.modal.disable();
                },
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        $.table.search();
                        $.modal.msgSuccess(result.msg)
                    } else if (result.code == web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    } else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                    $.modal.enable();
                }
            })
        }
    </script>
</body>
</html>