@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script>
    $(function () {
        $('#layout').layout();
        treeView();
        gridList();
    });
    function treeView() {
        $("#itemTree").treeview({
            url: "/SystemManage/ItemsType/GetTreeJson",
            onnodeclick: function (item) {
                $("#txt_keyword").val('');
                $('#btn_search').trigger("click");
            }
        });
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            height: $(window).height() - 96,
            colModel: [
                { label: "主键", name: "F_Id", hidden: true, key: true },
                { label: '名称', name: 'F_ItemName', width: 150, align: 'left' },
                { label: '编号', name: 'F_ItemCode', width: 150, align: 'left' },
                { label: '排序', name: 'F_SortCode', width: 80, align: 'center' },
                {
                    label: "默认", name: "F_IsDefault", width: 60, align: "center",
                    formatter: function (cellvalue) {
                        return cellvalue == true ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                {
                    label: '创建时间', name: 'F_CreatorTime', width: 80, align: 'left',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
                },
                {
                    label: "有效", name: "F_EnabledMark", width: 60, align: "center",
                    formatter: function (cellvalue) {
                        return cellvalue == true ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                { label: "备注", name: "F_Description", index: "F_Description", width: 200, align: "left", sortable: false }
            ]
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                url: "/SystemManage/ItemsData/GetGridJson",
                postData: { itemId: $("#itemTree").getCurrentNode().id, keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    function btn_add() {
        var itemId = $("#itemTree").getCurrentNode().id;
        var itemName = $("#itemTree").getCurrentNode().text;
        if (!itemId) {
            return false;
        }
        $.modalOpen({
            id: "Form",
            title: itemName + " 》新增字典",
            url: "/SystemManage/ItemsData/Form?itemId=" + itemId,
            width: "450px",
            height: "350px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_edit() {
        var itemName = $("#itemTree").getCurrentNode().text;
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalOpen({
            id: "Form",
            title: itemName + " 》修改字典",
            url: "/SystemManage/ItemsData/Form?keyValue=" + keyValue,
            width: "450px",
            height: "350px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_delete() {
        $.deleteForm({
            url: "/SystemManage/ItemsData/DeleteForm",
            param: { keyValue: $("#gridList").jqGridRowValue().F_Id },
            success: function () {
                $("#gridList").resetSelection();
                $("#gridList").trigger("reloadGrid");
            }
        })
    }
    function btn_details() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalOpen({
            id: "Details",
            title: "查看字典",
            url: "/SystemManage/ItemsData/Details?keyValue=" + keyValue,
            width: "450px",
            height: "470px",
            btn: null,
        });
    }
    function btn_itemstype() {
        $.modalOpen({
            id: "ItemsType",
            title: "字典分类",
            url: "/SystemManage/ItemsType/Index",
            width: "800px",
            height: "550px",
            btn: null,
        });
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div id="itemTree"></div>
    </div>
    <div class="ui-layout-center">
        <div class="topPanel">
            <div class="toolbar">
                <div class="btn-group">
                    <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
                </div>
                <div class="btn-group">
                    <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>新建字典</a>
                    <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                    <ul class="dropdown-menu pull-right">
                        <li><a id="NF-itemstype" authorize="yes" onclick="btn_itemstype()" href="javascript:void()">分类管理</a></li>
                    </ul>
                </div>
                <div class="operate">
                    <ul class="nav nav-pills">
                        <li class="first">已选中<span>1</span>项</li>
                        <li><a id="NF-edit" authorize="yes" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改字典</a></li>
                        <li><a id="NF-delete" authorize="yes" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除字典</a></li>
                        <li><a id="NF-Details" authorize="yes" onclick="btn_details()"><i class="fa fa-search-plus"></i>查看字典</a></li>
                    </ul>
                    <a href="javascript:;" class="close"></a>
                </div>
                <script>$('.toolbar').authorizeButton()</script>
            </div>
            <div class="search">
                <table>
                    <tr>
                        <td>
                            <div class="input-group">
                                <input id="txt_keyword" type="text" class="form-control" placeholder="名称/编号" style="width: 200px;">
                                <span class="input-group-btn">
                                    <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                                </span>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="gridPanel">
            <table id="gridList"></table>
        </div>
    </div>
</div>