@page 
@model Waste.Web.Entry.Pages.Menu.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="FullName" id="FullName" placeholder="请输入菜单名称" />
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" name="UrlAddress" id="UrlAddress" 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/system/GetMenuTreeJson",
                method: "post",
                where: {
                    queryParam: [{
                        "Name": 'Name',
                        "Type": QueryCond.Like,
                        "Value": $("#FullName").val()
                    }, {
                        "Name": 'UrlAddress',
                        "Type": QueryCond.Like,
                        "Value": $("#UrlAddress").val()
                    }]
                },
                parseData: function (res) {
                    var data = JSON.parse(res.data);
                    return {
                        "statuscode": res.statuscode,
                        "message": "success",
                        "data": data,
                        "TotalNum": 0
                    };
                },
                page: false,
                cellMinWidth: 80,
                initSort: false,
                cols: [[
                    {
                        field: 'Name', title: '名称', templet: function (d) {
                            return d.text;
                        }
                    }
                    , {
                        field: 'UrlAddress', title: '链接', templet: function (d) {
                            return d.data.UrlAddress;
                        }
                    }
                    , {
                        field: 'Icon', title: '图标', templet: function (d) {
                            return d.data.Icon;
                        }
                    }
                    , {
                        field: 'SortCode', title: '排序', templet: function (d) {
                            return d.data.SortCode;
                        }
                    }
                    , {
                        field: 'Status', title: '是否可用', templet: function (d) {
                            if (d.data.Status == 1) {
                                return '<input type="checkbox" name="close" lay-skin="switch" lay-text="是|否" checked>';
                            } else {
                                return '<input type="checkbox" name="close" lay-skin="switch" lay-text="是|否">';
                            }
                        }
                    }
                    , {
                        field: 'op', title: '操作', templet: function (d) {
                            return '<a href="javascript:void(0)" class="js-edit" data-id="' + d.id + '">编辑</a>&nbsp<a href="javascript:void(0)" class="js-delete" data-id="' + d.id + '">删除</a>'
                        }
                    }
                ]]
            });
            $("body").on("click", ".js-edit", function () {
                var id = $(this).data("id");
                common.dialog({
                    title: '编辑菜单',
                    content: '/Menu/MenuEdit?id=' + id
                });
            });
            $(".js-add").on("click", function () {
                common.dialog({
                    title: '添加菜单',
                    content: '/Menu/MenuEdit'
                });
            });
            $("body").on("click", ".js-delete", function () {
                var id = $(this).data("id");
                common.confirm("确定删除?", function () {
                    common.uajax({
                        url: "/api/system/deletemenu?id=" + id
                    });
                });
            });
            $(".js-search").on("click", function () {
                var param = {
                    queryParam: [{
                        "Name": 'Name',
                        "Type": QueryCond.Like,
                        "Value": $("#FullName").val()
                    }, {
                        "Name": 'UrlAddress',
                        "Type": QueryCond.Like,
                        "Value": $("#UrlAddress").val()
                    }]
                };
                common.reloadtable("list", {
                    where: param
                });
            });
        });
    </script>
}