@page 
@model Waste.Web.Entry.Pages.Role.IndexModel
@{
    ViewData["Title"] = "角色管理";
}
<div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" name="RoleName" id="RoleName" placeholder="请输入角色名称" />
                </div>
            </div>
            <div class="layui-inline">
                <button class="btn btn-primary btn-lg  js-search" type="button">查询</button>
                <button class="btn btn-primary btn-lg  js-add" type="button">添加</button>
            </div>
        </div>
    </div>
    <div class="layui-card-body">
        <table class="layui-table" id="list" lay-filter="list">
        </table>
    </div>
</div>
@section Scripts{
    <script type="text/javascript">
        layui.use(['common'], function () {
            var common = layui.common;
            common.initTable({
                url: '/api/role/getlist'
                , method: 'post'
                , cols: [[
                    {
                        field: 'name', title: '角色名称'
                    },
                    {
                        field: 'encode', title: '角色编号'
                    }
                    ,
                    {
                        field: 'remark', title: '备注'
                    }
                    ,
                    {
                        title: '操作', templet: function (d) {
                            var html = "<a href='#' class='js-edit' title='编辑'  data-id='" + d.id + "'>编辑</a>&nbsp";
                            html += "<a  href='#' class='layui-btn-xs js-delete' title='删除' data-id='" + d.id + "'>删除</a>";
                            return html;
                        }
                    }
                ]]
            });
            $(".js-search").on("click", function () {
                common.reloadtable("list", {
                    where: {
                        queryParam: [{
                            "Name": 'Name',
                            "Type": QueryCond.Like,
                            "Value": $("#RoleName").val()
                        }]
                    }
                });
            });
            $(".js-add").on("click", function () {
                common.dialog({
                    title: '添加角色',
                    content: '/Role/Edit'
                });
            });
            $("body").on("click", ".js-edit", function () {
                var id = $(this).data('id');
                common.dialog({
                    title: '编辑角色',
                    content: '/Role/Edit?id=' + id
                });
            });
            $("body").on("click", ".js-delete", function () {
                var id = $(this).data('id');
                common.confirm("确定删除?", function () {
                    common.ajax({
                        url: "/api/role/deleteform?id=" + id,
                        success: function (res) {
                            if (res.code == 0) {
                                common.info(res.message, function () {
                                    $(".js-search").trigger("click");
                                });
                            } else {
                                common.alert(res.message);
                            }
                        }
                    });
                });
            });
        });
    </script>
}