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

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
    <title></title>
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.4/jquery.min.js"></script>
    <script src="../jscript/JSClient.js" type="text/javascript"></script>
    <script src="../jscript/jquery.tool.new.js" type="text/javascript"></script>
    <link href="../css/framesearch_old.css" type="text/css" rel="stylesheet" />
    <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" />
    <script type="text/javascript" src="../Jscript-Ui/JQForm/JQForm.js"></script>
    <script src="../jscript/Dialog.js" type="text/javascript"></script>

    <link href="../css/framesearch.css" type="text/css" rel="stylesheet" />
    <link href="../css/button.css" rel="stylesheet" />
    <script src="../jscript/DateFormat.js" type="text/javascript"></script>
    <script src="../jscript/format.js" type="text/javascript"></script>
    <script type="text/javascript" src="../jscript/DatePicker/WdatePicker.js"></script>

</head>
<body>
    <form id="FrmForm">
        <input type="hidden" id="SelAll" name="SelAll" runat="server" />
        <input type="hidden" class="easyui-validatebox" id="CostGeneType" name="CostGeneType" runat="server" />
        <input type="hidden" class="easyui-validatebox" id="IsHis" name="IsHis" runat="server" />
        <input type="hidden" class="easyui-validatebox" id="IncidentID" name="IncidentID" runat="server" />
        <input type="hidden" class="easyui-validatebox" id="IsParking" name="IsParking" value="ispark" runat="server" />
        <input type="hidden" class="easyui-validatebox" id="MeterTypes" name="MeterTypes" runat="server" />
        <input type="hidden" id="SelRoomID" name="SelRoomID" value="" runat="server" />
        <div id="SearchDlg" class="easyui-dialog" title="筛选条件" data-options="iconCls:'icon-search',closed: true,modal:true"
            style="width: 300px; height: 100px;">
            <table style="width: 100%;">
                <tr>
                    <td class="TdTitle">费用项目
                    </td>
                    <td class="TdContent">
                        <input type="text" class="easyui-validatebox" id="CostName" name="CostName"
                            runat="server" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center" colspan="2">
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="LoadData(1,100);">确定筛选</a>
                    </td>
                </tr>
            </table>
        </div>
        <div id="ChargeMealDlg" class="easyui-dialog" title="绑定邦道车位套餐" data-options="iconCls:'icon-search',closed: true,modal:true"
            style="width: 400px; height: 100px;">
            <table style="width: 100%;">
                <tr>
                    <td class="TdTitle">套餐
                    </td>
                    <td class="TdContent">
                        <input name="ChargeMealName" type="text" id="ChargeMealName" class="easyui-searchbox" style="width: 160px;" data-options="editable:false,required:true" searcher="SelChargeMeal" runat="server" />
                        <input name="CostID" type="hidden" id="CostID" runat="server" />
                        <input name="StanID" type="hidden" id="StanID" runat="server" />
                        <input name="CarparkID" type="hidden" id="CarparkID" runat="server" />
                        <input name="packageId" type="hidden" id="packageId" runat="server" />
                        &nbsp;
                        &nbsp;
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="SaveChargeMeals()">绑定</a>
                    </td>

                </tr>

            </table>
        </div>
        <div style="width: 100%;" id="TableContainer">
        </div>
        <script src="../jscript/CloseAjaxCache.js" type="text/javascript"></script>
        <script type="text/javascript">
            function InitTableHeight() {
                var h = $(window).height();
                $("#TableContainer").css("height", h + "px");
            }
            InitTableHeight();
            var Column;
            Column = [[
                {
                    field: 'text', title: '费用名称/标准名称', width: 250, align: 'left', sortable: false
                },
                {
                    field: 'ChargeMealName', title: 'BD-套餐名称', width: 250, align: 'left', sortable: false, formatter: function (value, row, rowIndex) {
                        try {
                            return row.attributes.ChargeMealName;
                        }
                        catch (e) {
                            return '';
                        }
                    }
                },
                {
                    field: 'parkName', title: 'BD-车场名称', width: 250, align: 'left', sortable: false, formatter: function (value, row, rowIndex) {
                        try {
                            return row.attributes.parkName;
                        }
                        catch (e) {
                            return '';
                        }
                    }
                },
                {
                    field: 'area', title: 'BD-车场区域', width: 250, align: 'left', sortable: false, formatter: function (value, row, rowIndex) {
                        try {
                            if (!!row.attributes.ChargeMealName) {
                                return row.attributes.area;
                            }
                        }
                        catch (e) {
                            return '';
                        }
                    }
                },

                {
                    field: 'StanFormulaName', title: '计算方式', width: 180, align: 'left', sortable: false, formatter: function (value, row, rowIndex) {
                        try {
                            return row.attributes.StanFormulaName;
                        }
                        catch (e) {
                            return '';
                        }
                    }
                },
                {
                    field: 'StanAmount', title: '计算标准', width: 100, align: 'left', sortable: false, formatter: function (value, row, rowIndex) {
                        try {
                            return row.attributes.StanAmount;
                        }
                        catch (e) {
                            return '';
                        }
                    }
                },
                {
                    field: 'ChargeCycle', title: '计费周期', width: 100, align: 'left', sortable: false, formatter: function (value, row, rowIndex) {
                        try {
                            return row.attributes.ChargeCycle;
                        }
                        catch (e) {
                            return '';
                        }
                    }
                },
                {
                    field: 'DelinRates', title: '合同违约金比率', width: 100, align: 'left', sortable: false, formatter: function (value, row, rowIndex) {
                        try {
                            return row.attributes.DelinRates;
                        }
                        catch (e) {
                            return '';
                        }
                    }
                },
                {
                    field: 'StanExplain', title: '标准说明', width: 100, align: 'left', sortable: false, formatter: function (value, row, rowIndex) {
                        try {
                            return row.attributes.StanExplain;
                        }
                        catch (e) {
                            return '';
                        }
                    }
                },
                {
                    field: 'StanEndHit', title: '标准状态', width: 100, align: 'left', sortable: false, formatter: function (value, row, rowIndex) {
                        try {
                            return row.attributes.StanEndHit;
                        }
                        catch (e) {
                            return '';
                        }
                    }
                }
            ]];
            var IsCollapseAll = false;
            var toolbar = [
                {
                    text: '绑定套餐',
                    iconCls: 'icon-save',
                    handler: function () {
                        var row = $('#TableContainer').treegrid("getSelected");
                        if (row) {
                            if (row.attributes.StanID == 0) {
                                HDialog.Info("请选择最底层收费标准");
                                return;
                            }
                            else {
                                $('#ChargeMealName').searchbox("setValue", row.attributes.ChargeMealName);
                                $('#packageId').val(row.attributes.packageId);
                                $('#CostID').val(row.attributes.CostID);
                                $('#StanID').val(row.attributes.StanID);
                                $('#CarparkID').val(row.attributes.CarparkID);
                                $('#ChargeMealDlg').parent().appendTo($("form:first"));
                                $('#ChargeMealDlg').dialog('open');
                            }
                        } else {
                            HDialog.Info("请选择收费项!");
                        }
                    }
                }, {
                    text: '筛选',
                    iconCls: 'icon-search',
                    handler: function () {
                        $('#SearchDlg').parent().appendTo($("form:first"));
                        $('#SearchDlg').dialog('open');
                    }
                }, '-', {
                    text: '展开/折叠',
                    iconCls: 'icon-redo',
                    handler: function () {
                        if (IsCollapseAll == true) {
                            $('#TableContainer').treegrid('expandAll');
                            IsCollapseAll = false;
                        }
                        else {
                            $('#TableContainer').treegrid('collapseAll');
                            IsCollapseAll = true;
                        }
                    }
                }
            ];

            function LoadData() {
                var CostName = $('#CostName').val();
                var CostGeneType = $('#CostGeneType').val();
                var IsHis = $('#IsHis').val();
                var IncidentID = $('#IncidentID').val();
                var IsParking = $('#IsParking').val();
                var MeterTypes = $('#MeterTypes').val();
                $.tool.DataPost('BangDao_Park', 'GetBangDao_CostStanTree', "CostName=" + CostName + "&CostGeneType=" + CostGeneType + "&IsHis=" + IsHis + "&IncidentID=" + IncidentID + "&IsParking=" + IsParking + "&MeterTypes=" + MeterTypes,
                    function Init() {
                    },
                    function callback(_Data) {
                        var Data;
                        try {
                            Data = eval("(" + _Data + ")"); //转换为json对象
                            LoadList(Data);
                        }
                        catch (e) {
                            $("#TableContainer").treegrid({
                                method: "get",
                                title: '',
                                loadMsg: '加载中,请稍侯',

                                nowrap: false,
                                singleSelect: true,
                                selectOnCheck: false,
                                checkOnSelect: false,
                                nowrap: false,
                                pageSize: 200,
                                pageList: [200, 500, 1000],
                                pageNumber: 1,
                                cascadeCheck: true,
                                columns: Column,
                                fitColumns: false,
                                border: false,
                                singleSelect: true,
                                pagination: true,
                                border: false,
                                rownumbers: true,
                                width: "100%",
                                toolbar: toolbar,
                                sortOrder: "asc",
                                onDblClickRow: function (row) {

                                },
                                onLoadSuccess: function (data) {
                                    $("#SearchDlg").dialog("close");
                                }

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

            function LoadList(Data) {
                $("#TableContainer").treegrid({
                    method: "get",
                    data: Data,
                    title: '',
                    loadMsg: '加载中,请稍侯',
                    treeField: 'text',
                    idField: 'id',
                    nowrap: false,
                    singleSelect: true,
                    selectOnCheck: false,
                    checkOnSelect: false,
                    nowrap: false,
                    pageSize: 200,
                    pageList: [200, 500, 1000],
                    pageNumber: 1,
                    cascadeCheck: true,
                    columns: Column,
                    fitColumns: false,
                    border: false,
                    singleSelect: true,
                    pagination: true,
                    border: false,
                    rownumbers: true,
                    width: "100%",
                    toolbar: toolbar,
                    sortOrder: "asc",
                    onDblClickRow: function (row) {
                        //if (row.attributes.StanID == 0) {
                        //    HDialog.Info("请选择最底层收费标准");
                        //}
                        //else {
                        //    HDialog.ReturnIsJson = true;
                        //    HDialog.Close(row);
                        //}
                    },
                    onLoadSuccess: function (data) {
                        var pg = $("#TableContainer").treegrid("getPager");
                        if (pg) {
                            $(pg).pagination({
                                onBeforeRefresh: function () {
                                },
                                onRefresh: function (pageNumber, pageSize) {
                                },
                                onChangePageSize: function () {
                                },
                                onSelectPage: function (Pn, Ps) {
                                    LoadData(Pn, Ps);
                                    $('#TableContainer').treegrid('options').pageNumber = Pn;
                                    $('#TableContainer').treegrid('options').pageSize = Ps;
                                }
                            });
                        }
                        $("#SearchDlg").dialog("close");
                        $("#ChargeMealDlg").dialog("close");
                    }
                });
            }
            LoadData();


            function SelChargeMeal() {
                var conent = "../CarparkNew/Dialog/BangDao/BangDao_ChargeMealDlg.aspx";
                HDialog.Open('1200', '600', conent, '邦道车场信息', false, function callback(_Data) {
                    if (_Data != "") {
                        var data = JSON.parse(_Data);
                        $('#ChargeMealName').searchbox("setValue", data.name);
                        $('#packageId').val(data.packageId);
                    }
                });
            }

            function SaveChargeMeals() {
                if (!$("#CostID").val()) {
                    parent.layer.alert('费用标准为空');
                    return false;
                }
                if (!$("#StanID").val()) {
                    parent.layer.alert('费用标准为空!');
                    return false;
                }
                if (!$("#packageId").val()) {
                    parent.layer.alert('请选择套餐!');
                    return false;
                }


                var param = { CostID: $("#CostID").val(), StanID: $("#StanID").val(), packageId: $("#packageId").val(), CarparkID: $("#CarparkID").val() }
                $.tool.DataPost('BangDao_Park', "SaveChargeMeals", $.param(param),
                    function Init() {
                    },
                    function callback(_Data) {
                        var data = JSON.parse(_Data);
                        if (data.result) {
                            parent.layer.alert('保存成功');
                            $("#ChargeMealDlg").dialog("close");
                            LoadData();
                        }
                    },
                    function completeCallback() {
                    },
                    function errorCallback() {

                    });
            }
        </script>
    </form>
</body>
</html>
