
@{
    ViewData["Title"] = "用户角色";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "系统设置", "用户角色管理" };
}

<div class="row">
    <div class="col-sm-12">
        <div class="ibox-content m-b-sm border-bottom">
            <form id="toolbar">
                <div class="form-inline" style="line-height:40px;">
                    <div class="form-group">
                        <label>角色名称：</label>
                        <input id="name" name="name" class="form-control" placeholder="角色名称" />
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <button type="button" class="btn btn-primary" onclick="list();"><i class="fa fa-search"></i>&nbsp;查询</button>
                        <button type="button" class="btn btn-success" onclick="add();">新增</button>
                    </div>
                </div>
            </form>
        </div>

        <div class="ibox-content m-b-sm border-bottom">
            <table id="roletable" style="table-layout:fixed;"></table>
        </div>
    </div>
</div>
@section css{
    <link href="~/css/bootstrap-table-fixed-columns.css" rel="stylesheet" />
    <style>
        .mules {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
}
@section scripts{
    <script src="~/js/bootstrap-table-fixed-columns.js" type="text/javascript"></script>
    <script type="text/javascript">
        var tb;
        $(document).ready(function () {

            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 170));

            list();
        })

        function list() {
            var columns = [
                { field: 'name', title: '角色名称', width: '130' },
                { field: 'note', title: '备注', width: '180' },
                { field: 'lastupdateusername', title: '更新人', width: '100', sortable: true, iscount: true },
                { field: 'lastupdatetime', title: '更新时间', width: '130', sortable: true, iscount: true },
                {
                    field: 'option', title: '操作', width: '110', formatter: function (idx, data) {
                        return '<a class="btn btn-success btn-xs" onclick="ShowDetail(' + data.id + ')">编辑</a>' + (data.id != 1 ? '<a class="btn btn-danger btn-xs" style="margin-left:3px" onclick="DelDetail(' + data.id +')">删除</a>':"");
                    }
                }
            ];

            var url = '@Url.Content("~/Users/Home/ListUserRoles")' + '?' + $("#toolbar").serialize();

            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "");
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }

        function add() {
            layer_show('新增角色', '@Url.Content("~/Users/Home/RoleDetail")', '90%', '90%');
        }

        function ShowDetail(id) {
            layer_show('编辑角色', '@Url.Content("~/Users/Home/RoleDetail?id=")'+id, '90%', '90%');
        }

        function DelDetail(id) {
            if (confirm("删除后不可恢复，是否要删除该角色")) {

                $.submit({
                    url: '@Url.Content("~/Users/Home/DelUserRole")',
                    type:'POST',
                    paramData: 'id='+id,
                    func: function (result) {
                        if (result.success) {
                            layer.msg('删除成功！');
                            list();
                        }
                        else {
                            layer.msg(result.msg);
                        }
                    }
                })

            }
        }

    </script>
}

