<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RegionBrowse.aspx.cs" Inherits="M_Main.NewHouse.RegionBrowse" %>

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="../jscript/jquery-1.11.3.min.js"></script>
    <script src="../jscript/jquery.tool.new.js" type="text/javascript"></script>
    <script src="../jscript/Dialog.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="../Jscript-Ui/jquery-easyui-1.4.4/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../Jscript-Ui/jquery-easyui-1.4.4/themes/icon.css" />
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.4/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script>
    <link href="../css/framesearch.css" type="text/css" rel="stylesheet" />
</head>
<body>
    <form id="frmForm" runat="server">
        <div class="SearchContainer" id="TableContainer">
        </div>
        <div id="SearchDlg" class="easyui-dialog" title="筛选条件" data-options="iconCls:'icon-search',closed: true,modal:true"
            style="width: 400px; height: 100px; padding: 10px;">
            <table style="width: 100%; font-size: 12px; font-family: 微软雅黑;">
                <tr>
                    <td width="25%">组团区域名称
                    </td>
                    <td width="75%">
                        <input id="RegionName" style="width: 136px" size="17" name="RegionName" maxlength="50" />
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="LoadList();">确定筛选</a>
                    </td>

                </tr>

            </table>
        </div>

        <script src="../jscript/CloseAjaxCache.js" type="text/javascript"></script>
        <script type="text/javascript">

            function InitFunction() {
                var h = $(window).height();
                $("#TableContainer").css("height", h + "px");
            }
            InitFunction();

            var column = [[
                { field: 'ck', checkbox: true },
                { field: 'RegionID', title: 'RegionID', width: 50, align: 'left', sortable: true, hidden: true },
                {
                    field: 'RegionName', title: '组团区域名称', width: 200, align: 'left', sortable: true, formatter: function (value, row, index) {
                        var str = value;
                        if (row.IsLock == 0) {
                            str = "<a class=\"HrefStyle\"  href='#' onclick=\"ViewDetail('修改组团区域','update'," + row.RegionID + ");\">" + row.RegionName + "</a>";
                        }
                        return str;
                    }
                },
                { field: 'UserName1', title: '管家姓名', width: 200, align: 'left', sortable: true },
                { field: 'Tel', title: '管家电话', width: 200, align: 'left', sortable: true },
                {
                    field: 'IsLock', title: '是否锁定', width: 50, align: 'left', sortable: true, formatter: function (value, row, index) {
                        var str = "否";
                        if (value == 1) {
                            str = "是";
                        }
                        return str;
                    }
                }
            ]];

            var toolbar = [
                {
                    text: '新增组团',
                    iconCls: 'icon-add',
                    handler: function () {
                        ViewDetail("新增组团区域", 'add', 0);
                    }
                }, '-',
                {
                    text: '删除组团',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        var rows = $('#TableContainer').datagrid('getChecked');
                        if (rows == "") {
                            HDialog.Info('请勾选需要删除的组团区域!');
                            return;
                        }
                        else {
                            var SelRegionID = "";
                            $.each(rows, function (key, val) {
                                SelRegionID += rows[key]["RegionID"] + ",";
                            });
                            SelRegionID = SelRegionID.substr(0, SelRegionID.length - 1);
                            $.tool.DataPostChk('frmForm', 'ResourceBaseAuditing', 'CheckLock', '&KeyIDValues=' + SelRegionID + '&CheckType=Region',
                                function Init() {
                                },
                                function callback(_Data) {
                                    if (_Data == "true") {
                                        HDialog.Info('包含已被锁定的记录不能删除组团!');
                                    } else {
                                        DelRecord(SelRegionID);
                                    }
                                }
                            );
                        }
                    }
                },
                //'-',
                //    {
                //        text: '设置管家',
                //        iconCls: 'icon-save',
                //        handler: function () {
                //            var rows = $('#TableContainer').datagrid('getChecked');
                //            if (rows == "") {
                //                HDialog.Info('请勾选要设置管家的组团区域!');
                //                return;
                //            }
                //            else {
                //                var SelRegionID = "";
                //                var SelRegionName = "";
                //                $.each(rows, function (key, val) {
                //                    SelRegionID += rows[key]["RegionID"] + ",";
                //                    SelRegionName += rows[key]["RegionName"] + ",";
                //                });
                //                SelRegionID = SelRegionID.substr(0, SelRegionID.length - 1);
                //                SelRegionName = SelRegionName.substr(0, SelRegionName.length - 1);
                //                $.tool.DataPostChk('frmForm', 'ResourceBaseAuditing', 'CheckLock', '&KeyIDValues=' + SelRegionID + '&CheckType=Region',
                //                    function Init() {
                //                    },
                //                    function callback(_Data) {
                //                        if (_Data == "true") {
                //                            HDialog.Info('包含已被锁定的记录不能设置管家!');
                //                        } else {
                //                            ViewDetail2("设置管家", 'add', SelRegionID, SelRegionName);
                //                        }
                //                    }
                //                );
                //            }
                //        }
                //    },
                //'-',
                //{
                //    text: '删除管家',
                //    iconCls: 'icon-cancel',
                //    handler: function () {
                //        var rows = $('#TableContainer').datagrid('getChecked');
                //        if (rows == "") {
                //            HDialog.Info('请勾选需要删除的管家!');
                //            return;
                //        }
                //        else {
                //            var SelRegionID = "";
                //            var SelIID = "";
                //            $.each(rows, function (key, val) {
                //                SelRegionID += rows[key]["RegionID"] + ",";
                //                SelIID += rows[key]["IID"] + ",";
                //            });
                //            SelIID = SelIID.substr(0, SelIID.length - 1);
                //            SelRegionID = SelRegionID.substr(0, SelRegionID.length - 1);
                //            $.tool.DataPostChk('frmForm','ResourceBaseAuditing', 'CheckLock', '&KeyIDValues=' + SelRegionID + '&CheckType=Region',
                //                function Init() {
                //                },
                //                function callback(_Data) {
                //                    if (_Data == "true") {
                //                        HDialog.Info('包含已被锁定的记录不能删除管家!');
                //                    } else {
                //                        DelRecord2(SelIID);
                //                    }
                //                }
                //            );
                //        }
                //    }
                //}，
                '-',
                {
                    text: '筛选',
                    iconCls: 'icon-search',
                    handler: function () {
                        $('#SearchDlg').parent().appendTo($("form:first"))
                        $('#SearchDlg').dialog('open');
                        $("#RegionName").val("");
                    }
                }
            ];

            function CheckLock(RegionID) {
                var Ischeck = false;
                return Ischeck;
            }

            function DelRecord2(Id) {
                $.messager.confirm('确定', '是否删除该项', function (r) {
                    if (r) {
                        $.tool.DataGet('HouseKeeper', 'Del', 'IID=' + Id,
                            function Init() {
                            },
                            function callback(_Data) {
                                var data = _Data.split('|');
                                if (data[0] == "true") {
                                    HDialog.Info('删除成功');
                                    LoadList();
                                }
                                else { HDialog.Info('删除失败'); }

                            },
                            function completeCallback() {
                            },
                            function errorCallback() {
                            });
                    }
                });
            }

            function DelRecord(Id) {
                $.messager.confirm('确定', '是否删除该项', function (r) {
                    if (r) {
                        $.tool.DataGet('Region', 'delete', 'RegionID=' + Id,
                            function Init() {
                            },
                            function callback(_Data) {
                                if (_Data == "true") {
                                    HDialog.Info('删除成功');
                                }
                                else { HDialog.Info('删除失败'); }
                                LoadList();
                            },
                            function completeCallback() {
                            },
                            function errorCallback() {
                            });
                    }
                });
            }

            function LoadList() {
                $("#TableContainer").datagrid({
                    url: '/HM/M_Main/HC/DataGetControl.aspx?Method=DataGet&Class=Region&Command=search&' + $("#frmForm").serialize(),
                    method: "get",
                    nowrap: false,
                    pageSize: top.ListPageSize,
                    pageList: top.ListPageList,
                    columns: column,
                    fitColumns: true,
                    remoteSort: false,
                    singleSelect: true,
                    pagination: true,
                    width: "100%",
                    toolbar: toolbar,
                    sortOrder: "asc",
                    selectOnCheck: false,
                    checkOnSelect: false,
                    rownumbers: true,
                    border: false,
                    toolbar: toolbar,
                    sortOrder: "asc",
                    onLoadSuccess: function (data) {
                        if (data.rows.length > 0) {
                            //循环判断操作为新增的不能选择
                            for (var i = 0; i < data.rows.length; i++) {
                                //根据operate让某些行不可选
                                if (data.rows[i].IsLock == "1") {
                                    $("input[type='checkbox']")[i + 1].disabled = true;
                                }
                            }
                        }
                    }
                });
                $("#SearchDlg").dialog("close");
            }

            LoadList();
            function ViewDetail(title, OpType, ID) {
                HDialog.Open('620', '300', '../HouseNew/RegionManage.aspx?RegionID=' + ID + '&OpType=' + OpType, title, false, function callback(_Data) {
                    LoadList();
                });
            }
            function ViewDetail2(title, OpType, ID, RegionName) {

                HDialog.Open('620', '250', '../HouseNew/RegionHouseKeeperManage.aspx?RegionID=' + ID + '&RegionName=' + RegionName + '&OpType=' + OpType, title, false, function callback(_Data) {
                    LoadList();
                });
            }

        </script>
    </form>
</body>
</html>
