@using GBLab.Common.Expand;
@model GBLab.Entities.T_Message
@{
    Layout = null;
}

<div id="Item_tabsContent" class="tabsContent" style="border-style: none;padding-top:3px;background-color:#E5EFEF;">
    <div id="layout">
        <div id="Item_sidebar_sMids" class="sidebar_sMid" layouth="8" style="float: left;
            width: 24px; height: 100%; display: none; z-index: 21; border: 1px solid #B8D0D6;margin-right: 3px;">
            <div style="background: none repeat scroll 0 0 #EFF5F6;">
                <div id="Item_sidebar_sMid" class="toggleCollapse" style="background: none repeat scroll 0 0 transparent;
                    border: 0 none;">
                    <div style="background-position: -2px -147px; border: 0 none; width: 21px;">
                    </div>
                </div>
            </div>
        </div>        
        @*左侧导航展开后效果*@
        @{
            if (Request.QueryString["IsLeftTree"].DefaultIsNullOrEmpty(true) == true) {
                <div id="Item_MidTree" layouth="8" style="float: left; display: block;overflow: auto; width: 227px; border: solid 1px #CCC; line-height: 21px; background: #fff;margin-right: 3px; ">
                    <div class="toggleCollapseForAction" id="Item_toggleCollapseMid" style="border-style: none;">
                        <h2>
                            栏目列表
                        </h2>
                        <div>
                            收缩
                        </div>
                    </div>
                    <ul id="Item_Tree" class="ztree"></ul>
                </div>
            }
        }
        <div id="jbsxBox" class="unitBox" style="display:block; overflow:auto;@(Request.QueryString["IsLeftTree"].DefaultIsNullOrEmpty(true)==true?"margin-left:29px;":"")">
            <div class="pageHeader" style="border: 1px #B8D0D6 solid; padding: 0px;margin-bottom: 1px;">
                <div class="searchBar">
                    <table class="searchContent">
                        <tr>
                            <td>
                                名称
                            </td>
                            <td>
                                @Html.Raw(Html.WebInput_CommonConfirmIdForListSearch("F_Name", "名称", "", "true", "", "1", "80", "", ""))
                            </td>
                            <td>
                                <div class="buttonActive">
                                    <div class="buttonContent">
                                        <button type="button" onclick="Item_subSearch();">
                                            检索
                                        </button>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="pageContent" style="border-left: 1px #B8D0D6 solid; border-right: 1px #B8D0D6 solid">
                <div class="panelBar" style="margin: 0px; padding: 0px;">
                    <ul class="toolBar">
                        <span style="float:right;">
                            <li>
                                <a id="Item_Add" class="add" href="/Manage/Message/Edit?Action=Add&F_TypeId=" target="dialog"
                                   title="[系统消息]信息编辑" max="true" rel="Item_EditPage"
                                   resizable="true" drawable="true" close="Item_closedialog" param="{msg:'gogo'}">
                                    <span>添加</span>
                                </a>
                            </li>
                            <li>
                                <a class="delete" rel="ids" title="确定要删除吗?" onclick="Item_DelItems('')">
                                    <span>删除</span>
                                </a>
                            </li>
                            <li class="line">line</li>
                            <li>
                                <a class="edit" onclick="Item_ExportExcel('false')">
                                    <span>导出当前页到excel</span>
                                </a>
                            </li>
                            <li>
                                <a class="edit" onclick="Item_ExportExcel('true')">
                                    <span>导出到excel</span>
                                </a>
                            </li>
                            <li>
                                <a class="icon" href="javascript:$.printBox('Item_TableInfo')">
                                    <span>打印当前页</span>
                                </a>
                            </li>
                        </span>
                        <div style="float:left;">
                            <li>
                                <div id="Item_100" class="buttonDisabled">
                                    <div class="buttonContent">
                                        <button type="button" onclick="Item_SetMarkStatus(100, '100');">
                                            全部
                                        </button>
                                    </div>
                                </div>
                            </li>
                            <li>
                                <div id="Item_0" class="buttonActive">
                                    <div class="buttonContent">
                                        <button type="button" onclick="Item_SetMarkStatus(0, '0');">
                                            正常
                                        </button>
                                    </div>
                                </div>
                            </li>
                            <li>
                                <div id="Item_10" class="buttonActive">
                                    <div class="buttonContent">
                                        <button type="button" onclick="Item_SetMarkStatus(10, '10');">
                                            待审核
                                        </button>
                                    </div>
                                </div>
                            </li>
                            <li>
                                <div id="Item_1" class="buttonActive">
                                    <div class="buttonContent">
                                        <button type="button" onclick="Item_SetMarkStatus(-1,'1');">
                                            删除
                                        </button>
                                    </div>
                                </div>
                            </li>
                        </div>
                    </ul>
                </div>
            </div>
            <div id="Item_TableInfo" style="border-width:0 1px;border-color:#D0D0D0;border-style:solid;"></div>
        </div>
        <!-- 用于子标签引用的时候在高度上的处理 -->
        <span id="Item_MidNumber" style="display: none;">@Html.ViewContext.HttpContext.Request.QueryString["Mid"]</span>
        <span id="HeadInfo" style="display: none;"></span><span style="display: none;">
            <!-- 树形节点存储 -->
            <div id="Item_TreeCode"></div>
            <!-- 当前页面存储 -->
            <div id="Item_currentPage">1</div>
            <!-- 分页大小存储 -->
            <div id="Item_pageSize">-1</div>
            <!-- 分页数量存储 -->
            <div id="Item_pageCount"></div>
            <!-- 查询条件：排序 -->
            <div id="Item_OrderInfo"></div>
			<!-- 查询条件：名称 -->
            <div id="Item_name"></div>
            <!-- 查询条件：状态信息 -->
            <div id="Item_markStatus">100</div>
        </span>
    </div>
</div>

<script type="text/javascript" language="javascript">
	var typeId = 10425;
    var test = '@Html.ViewContext.RouteData.Values["id"]' + '_0';
    var isMidType=false;
    if (test != '_0') {
        test = test.replace('_0', '');
        typeId = test;
        isMidType = true;
    }

	var testMidId = '@Html.ViewContext.RouteData.Values["midId"]' + '_0';
    var isMidId = false;
    var testMidIdArg = '&F_CommonId=';
    var testSearchArg = "&strCommonId=";
    if (testMidId != '_0') {
        testMidIdArg += testMidId.replace('_0', '');
        testSearchArg += testMidId.replace('_0', '');
        isMidId = true;
    }

    $(function () {
		var MidNumber = $("#Item_MidNumber").html();
        if (MidNumber != '') {
            $("#Item_sidebar_sMids").attr("layouth", "84");
            $("#Item_MidTree").attr("layouth", "84");
        }

        // 初始化显示的动画效果
        $("#Item_toggleCollapseMid div").off().on("click", function () {
            $("#Item_MidTree").hide("slow");
            $("#Item_sidebar_sMids").show("slow"); setTimeout(Item_initData, 500);
        });
        $(".sidebar_sMid div #Item_sidebar_sMid").off().on("click", function () {
            $("#Item_MidTree").show("slow");
            $("#Item_toggleCollapseMid").show();
            $("#Item_sidebar_sMids").hide("slow"); setTimeout(Item_initData, 500);
        });
        // 分页点击
        $("#Item_tabsContent div div div div div ul .j-num a").off().on("click", function () {
            $("#Item_currentPage").html($(this).html());
            Item_initData();
        });
        // 下一页点击
        $("#Item_tabsContent div div div div div ul .j-next a").off().on("click", function () {
            $("#Item_currentPage").html($("#Item_currentPage").html() * 1 + 1);
            Item_initData();
        });
        // 上一页点击
        $("#Item_tabsContent div div div div div ul .j-prev a").off().on("click", function () {
            $("#Item_currentPage").html($("#Item_currentPage").html() * 1 - 1);
            Item_initData();
        });
        // 第一页点击
        $("#Item_tabsContent div div div div div ul .j-first a").off().on("click", function () {
            $("#Item_currentPage").html(1);
            Item_initData();
        });
        // 最后一页点击
        $("#Item_tabsContent div div div div div ul .j-last a").off().on("click", function () {
            $("#Item_currentPage").html($("#Item_pageCount").html());
            Item_initData();
        });
        // 转到指定页事件
        $("#Item_tabsContent div div div div div ul .goto").off().on("click", function () {
            $("#Item_currentPage").html($("#Item_TableInfo div div ul li .textInput").val());
            Item_initData();
        });
        // 选中处理
        $("#Item_TableInfo div div .gridTbody table tbody tr td").off().on("click", function () {
            if ($(this).parent().find("td div input").attr("checked") == "checked") {
                $(this).parent().find("td div input").attr("checked", false);
            } else {
                $(this).parent().find("td div input").attr("checked", true);
            }
        });
        // 获取分类信息
        $.ajax({
            type: "GET",
            url: "/Manage/Type/GetTypeList",
            data: "F_TypeId=" + typeId + "&num=" + Math.round(Math.random() * 10000),
            success: function (data) {
                var Container = '<ul id="Item_Mid10007" class="tree treeFolder expand"></ul>';
                var TemplateHead = '<ul id="Big$F_BigId" class="tree treeFolder collapse">';
                var TemplateMid = '<li ><a $F_IsSystemAction>$F_Name</a>$F_IsSystem</li>';
                var TemplateDown = '</ul>';
                var IsSystem = '<ul class="tree treeFolder collapse" id="Item_Mid$F_Id"></ul>';
                var IsSystemAction = ' onclick="Item_TreeListChange($TypeId)"';
				var IsNoTypeSystemAction  = '';

                $("#Item_MidTree").html($("#Item_MidTree").html() + Container);

                for (var i = 0; i < data.length; i++) {
                    var tree = '';
                    if (data[i].IsSystemPoint == true) {
                        if (isMidType) {
                            tree += TemplateMid.replace('$F_Id', data[i].Id).replace('$F_Id', data[i].Id).replace('$F_Id', data[i].Id).replace('$F_Name', data[i].Name).replace('$F_IsSystemAction', IsNoTypeSystemAction.replace('$TypeId', data[i].Id)).replace('$F_IsSystem', IsSystem.replace('$F_Id', data[i].Id));
                        } else {
                            tree += TemplateMid.replace('$F_Id', data[i].Id).replace('$F_Id', data[i].Id).replace('$F_Id', data[i].Id).replace('$F_Name', data[i].Name).replace('$F_IsSystemAction', IsSystemAction.replace('$TypeId', data[i].Id)).replace('$F_IsSystem', IsSystem.replace('$F_Id', data[i].Id));
                        }
                    } else {
						if (isMidType) {
                            tree += TemplateMid.replace('$F_Id', data[i].Id).replace('$F_Id', data[i].Id).replace('$F_Id', data[i].Id).replace('$F_Name', data[i].Name).replace('$F_IsSystemAction', IsNoTypeSystemAction.replace('$TypeId', data[i].Id)).replace('$F_IsSystem', '');
                        } else{
                            tree += TemplateMid.replace('$F_Id', data[i].Id).replace('$F_Id', data[i].Id).replace('$F_Id', data[i].Id).replace('$F_Name', data[i].Name).replace('$F_IsSystemAction', IsSystemAction.replace('$TypeId', data[i].Id)).replace('$F_IsSystem', '');
                        }
					}
                    $("#Item_Mid" + data[i].FatherId).html($("#Item_Mid" + data[i].FatherId).html() + tree);
                }
                $("#Item_Mid10007").jTree();
            }
        });
        Item_TreeListChange(typeId);
    });

    // 用于树形切换的时候数据的处理。
    function Item_TreeListChange(typeid) {
        $("#Item_currentPage").html(1);
        $("#Item_TreeCode").html(typeid);
        Item_firstinitData();
    }

    function Item_CheckLogin(data) {
        try {
            data = eval("(" + data + ")");
            if (data.statusCode == "301") {
                DWZ.loadLogin();
                return false;
            }
        } catch (e) {
            return true;
        }
    }

    //初始化获取列表信息
    function Item_GetList(TypeId, SearchInfo, OrderInfo, pageSize, currentPage, strName, strMarkStatus) {
        $.ajax({
            type: "GET",
            url: "/Manage/Message/List_Data",
            data: "TypeId=" + TypeId + "&strName=" + strName + "&strMarkStatus=" + strMarkStatus + testSearchArg + "&strWhere=" + SearchInfo + "&strOrder=" + OrderInfo + "&pageSize=" + pageSize + "&currentPage=" + currentPage + "&num=" + Math.round(Math.random() * 10000),
            success: function (data) {
                if (Item_CheckLogin(data) == false) {
                    return;
                }

                $("#Item_TreeCode").html(TypeId);
                $("#Item_currentPage").html(currentPage);
                $("#Item_pageSize").html(pageSize);
                $("#Item_name").html(strName);
                $("#Item_markStatus").html(strMarkStatus);

				var aa = data[0].toString().replace(/Itemaa_/gi, 'Item_');

                // 用于子标签引用的使用在高度上的处理
                var MidNumber = $("#Item_MidNumber").html();
                if (MidNumber != '') {
                    aa = aa.replace('layouth="110"', 'layouth="' + MidNumber + '"');
                }

                $("#Item_TableInfo").html(aa);
                $("#Item_TableView").jTable();
                initUITwo();
                $(".gridTbody table tbody tr").css("cursor", "pointer");
                var pageCount = 0;
                if ($("#Item_TotalNum").html() % $("#Item_numPerPage").val() == 0) {
                    pageCount = $("#Item_TotalNum").html() / $("#Item_numPerPage").val();
                } else {
                    pageCount = $("#Item_TotalNum").html() / $("#Item_numPerPage").val() + 1;
                }
                $("#Item_pageCount").html(Math.floor(pageCount));
                initLayout();
                try {
					if (isMidId == false) {
                        $("#Item_Add").attr("href", "/Manage/Message/Edit?Action=Add&F_TypeId=" + TypeId);
                    } else {
                        $("#Item_Add").attr("href", "/Manage/Message/Edit?Action=Add&F_TypeId=" + TypeId + testMidIdArg);
                    }
                } catch (e) {
                }
				try{
                    var content = $(".dialogContent");
                    content.find("[layoutH]").layoutH(content);
                }catch(e){
                }
            }
        });
    }

    // 分页大小变化时切换
    function Item_changePageSize(e) {
		$("#Item_currentPage").html(1);
		$("#Item_pageSize").html(e);
        Item_initData();
    }

    // 提交查询时处理
    function Item_subSearch() {
		$("#Item_currentPage").html(1);
		$("#Item_name").html($("#Item_F_Name").val());
        $("#Item_markStatus").html($("#Item_F_MarkStatus").val());
        Item_initData();
    }

    // 初始化数据
    function Item_initData() {
        var currentPage = $("#Item_currentPage").html();
        if (currentPage == '') {
            currentPage = 1;
        }
        Item_GetList($("#Item_TreeCode").html(), '', $("#Item_OrderInfo").html(), $("#Item_pageSize").html(), currentPage, $("#Item_name").html(), $("#Item_markStatus").html());
    }

    // 是否全部导出
    function Item_ExportExcel(isAll) {
        var currentPage = $("#Item_currentPage").html();
        if (currentPage == '') {
            currentPage = 1;
        }
        window.open('/Manage/Message/List_Excel?isAll=' + isAll + '&TypeId=' + $("#Item_TreeCode").html() + '&strName=' + $("#Item_name").html() + '&strMarkStatus=' + $("#Item_markStatus").html() + '&strWhere=&strOrder=' + $("#Item_OrderInfo").html() + '&pageSize=' + $("#Item_pageSize").html() + '&currentPage=' + currentPage + '&num=' + Math.round(Math.random() * 10000));
    }

    // 当类别切换的时候数据的初始化，要清除必要的查询条件。
    function Item_firstinitData() {
        var currentPage = $("#Item_currentPage").html();
        if (currentPage == '') {
            currentPage = 1;
        }
        Item_GetList($("#Item_TreeCode").html(), '', '', $("#Item_pageSize").html(), currentPage, '', $("#Item_markStatus").html());
    }

    // 排序更改时处理
    function Item_OrderBy(e) {
        var orderInfo = $("#Item_OrderInfo").html();
        if (orderInfo.toString().length == 0 || orderInfo.indexOf(e) < 0) {
            $("#Item_OrderInfo").html(e + ' desc ');
            $("#Item_currentPage").html(1);
            Item_initData();
            return;
        }
        if (orderInfo.indexOf('desc') >= 0) {
            $("#Item_OrderInfo").html(e + ' asc ');
            $("#Item_currentPage").html(1);
            Item_initData();
            return;
        } else {
            $("#Item_OrderInfo").html(e + ' desc ');
            $("#Item_currentPage").html(1);
            Item_initData();
            return;
        }
    }

    // 删除选中的记录
    function Item_DelItems(url, data) {
        alertMsg.confirm("确认要删除选中的记录吗？", {
            okCall: function () {
                var obj = document.getElementsByName("Item_ids");
                var ids = '';
                for (var i = 0; i < obj.length; i++) {
                    if (obj[i].checked == true) {
                        ids += obj[i].value + ',';
                    }
                }
                if (ids == '') {
                    alertMsg.error("未选择要删除的记录!");
                    return;
                }
                // 获取分类信息
                $.ajax({
                    type: "GET",
                    url: "/Manage/Message/Delete",
                    data: "ids=" + ids,
                    success: function (data) {
						if (Item_CheckLogin(data) == false) {
                            return;
                        }

                        Item_initData();
                        if (data[0] == "true") {
                            alertMsg.correct("删除成功!");
                        } else {
                            alertMsg.error("删除失败!");
                        }
                    }
                });
            }
        });
    }

    // 删除指定的记录
    function Item_DelItem(id) {
        alertMsg.confirm("确认要删除指定的记录吗？", {
            okCall: function () {
                var ids = id + ',';
                if (ids == '') {
                    alertMsg.error("未选择要删除的记录!");
                    return;
                }
                // 获取分类信息
                $.ajax({
                    type: "GET",
                    url: "/Manage/Message/Delete",
                    data: "ids=" + ids,
                    success: function (data) {
						if (Item_CheckLogin(data) == false) {
                            return;
                        }

                        Item_initData();
                        if (data[0] == "true") {
                            alertMsg.correct("删除成功!");
                        } else {
                            alertMsg.error("删除失败!");
                        }
                    }
                });
            }
        });
    }

    function Item_SetMarkStatus(e, index) {
        $("#Item_markStatus").html(e);

        $("#Item_100").attr("class", "buttonActive");
        $("#Item_10").attr("class", "buttonActive");
        $("#Item_0").attr("class", "buttonActive");
        $("#Item_1").attr("class", "buttonActive");

        $("#Item_" + index).attr("class", "buttonDisabled");

        Item_initData();
    }

    // 关闭窗口时的数据回刷
    function Item_closedialog(param) {
        Item_initData();
        return true;
    }
</script>