<!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">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>字段主键：</label>
                                <input type="text" name="fieldKey"/>
                            </li>
                            <li>
                                <label>显示标志：</label>
                                <select name="showFlag" th:with="type=${@dict.getType('sys_yes_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </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="$.operate.add()" shiro:hasPermission="master:roleField:add">-->
<!--                    <i class="fa fa-plus"></i> 添加-->
<!--                </a>-->
<!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="master:roleField:edit">-->
<!--                    <i class="fa fa-edit"></i> 修改-->
<!--                </a>-->
<!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="master:roleField:remove">-->
<!--                    <i class="fa fa-remove"></i> 删除-->
<!--                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('master:roleField:edit')}]];
        var removeFlag = [[${@permission.hasPermi('master:roleField:remove')}]];
        var prefix = ctx + "master/roleField";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "角色字段控制",
                detailView: true,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                columns: [
                // {
                //     checkbox: true
                // },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'roleKey',
                    title: '角色主键'
                }]
            };
            $.table.init(options);
        });

        initChildTable = function(index, row, $detail) {
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            $(childTable).bootstrapTable({
                url: prefix + "/listDetail",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams : {
                    roleKey: row.roleKey
                },
                columns: [{
                        field: 'fieldKey',
                        title: '字段主键'
                    },
                    {
                        field: 'showFlag',
                        title: '显示标志',
                        formatter: function(value, row, index) {
                            return statusTools(row);
                        }
                    }]
            });
        };

        function statusTools(row) {
            if ($.common.equals('1', row.showFlag)) {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="changeShowFlag(\'' + row.id + '\',\'' + row.roleKey + '\',\'' + row.fieldKey + '\',\'' + row.showFlag + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="changeShowFlag(\'' + row.id + '\',\'' + row.roleKey + '\',\'' + row.fieldKey + '\',\'' + row.showFlag + '\')"></i> ';
            }
        }

        function changeShowFlag(id, roleKey,fieldKey,showFlag) {
            var text = !$.common.equals('1', showFlag) ? '显示' : '控制';
            $.modal.confirm("确认要" + text + "字段吗？", function () {
                if ($.common.isEmpty(id) || id == 'null') {
                    $.operate.post(prefix + "/changeShowFlag", {"roleKey":roleKey,"fieldKey":fieldKey});
                } else {
                    $.operate.post(prefix + "/changeShowFlag", {"id": id,"roleKey":roleKey,"fieldKey":fieldKey});
                }
            })
        }
    </script>
</body>
</html>