<%@ Page Language="c#" CodeBehind="RepealOffsetWaivBrowse.aspx.cs" AutoEventWireup="false" Inherits="M_Main.ChargesNew.RepealOffsetWaivBrowse" %>

<!DOCTYPE html>
<html>
<head>
    <title>RepealOffsetWaivBrowse</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>
</head>
<body onload="Win_OnLoad()">
    <form id="FrmForm" method="post" runat="server">
        <input id="btnCanCel" style="display: none;" type="button" value=" " name="btnCanCel" runat="server" />
        <input id="IID" type="hidden" name="IID" runat="server" value="" />
        <input id="WriteOffIID" type="hidden" name="WriteOffIID" runat="server" value="" />
        <input id="WaivDate" type="hidden" name="WaivDate" runat="server" value="" />
        <input id="CheckDates" type="hidden" name="CheckDates" runat="server" value="" />
        <input class="button" id="btnPrint" type="button" value="打印" style="display: none;" name="btnPrint" runat="server">
        <input id="PrintParms" type="hidden" name="PrintParms" runat="server">
        <div style="width: 100%; background-color: #cccccc;" id="TableContainer">
        </div>
        <div id="SearchDlg" class="easyui-dialog" title="筛选条件" data-options="iconCls:'icon-search',closed: true,modal:true"
            style="width: 800px; height: 200px;">
            <table style="width: 100%; padding-top: 5px; line-height: 25px;">
                <tr>
                    <td class="TdTitle">客户名称</td>
                    <td class="TdContentSearch">
                        <input class="easyui-searchbox" style="width: 80%;" id="CustName" data-options="editable:false" name="CustName" searcher="SelCust" runat="server" />
                        <input type="hidden" name="CustID" id="CustID" runat="server" />
                    </td>
                    <td class="TdTitle">可选房号</td>
                    <td class="TdContentSearch">
                        <select id="SelectRoomID" class="easyui-combobox" name="SelectRoomID" data-options="editable:false,panelHeight: '100px'" onchange="javascript:SelectRoomID_OnChange();" runat="server">
                            <option selected></option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle">房屋编号</td>
                    <td class="TdContentSearch">
                        <input class="easyui-searchbox" id="RoomSign" style="width: 80%;" data-options="editable:false" name="RoomSign" searcher="SelRoom" runat="server" />
                        <input type="hidden" name="RoomID" id="RoomID" runat="server" />
                    </td>

                    <td class="TdTitle">减免业务类型</td>
                    <td class="TdContent">
                        <select id="WaiversCategory" class="easyui-combobox" name="WaiversCategory" runat="server" style="width: 82%;">
                            <option value=""></option>
                            <option value="政策性减免">政策性减免</option>
                            <option value="非政策性减免">非政策性减免</option>
                        </select></td>
                </tr>
                <tr>
                    <td class="TdTitle">费用项目</td>
                    <td class="TdContentSearch">
                        <input style="width: 8px" id="CostIDs" class="easyui-validatebox" size="1" type="hidden" name="CostIDs" runat="server" />
                        <input style="width: 80%;" id="CostNames" class="easyui-searchbox" data-options="editable:false" size="14" name="CostNames" runat="server" searcher="SelCost" />
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="4">
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="LoadList();">确定筛选</a>&nbsp;&nbsp;
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-filter'" onclick="CancelParm();">清&nbsp;&nbsp;空</a>
                    </td>
                </tr>
            </table>
        </div>

        <div id="Dlg" class="easyui-dialog" title="冲销原因" data-options="iconCls:'icon-search',closed: true,modal:true"
            style="width: 500px; height: 150px;">
            <table style="width: 100%; padding-top: 5px; line-height: 25px;">
                <tr>
                    <td class="TdTitle">冲销原因</td>
                    <td class="TdContentSearch">
                        <input style="width: 80%;" id="ReferReason" name="ReferReason" runat="server" />
                    </td>

                </tr>
                <tr>
                    <td align="center" colspan="4">
                        <a href="#" class="easyui-linkbutton" style="width: 100px" onclick="OffsetWaivDetailWriteOffClick();">确定</a>&nbsp;&nbsp;                        
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>


<script type="text/javascript">

    function Win_OnLoad() {
        var strPrintParms = getObject("PrintParms").value;
        if (strPrintParms != "") {
            showOperatWin(strPrintParms);

            getObject("PrintParms").value = "";
        }
    }
    $(function () {
        LoadList();
    });

    function SelCost() {
        HDialog.Open('700', '400', "../dialogNew/MultiCorpCommCostDlg.aspx", '收费项目选择', false, function callback(_Data) {
            if (_Data != "") {//**获得返回 刷新
                var varObjects = _Data.split("\t");
                $('#CostIDs').val(varObjects[0]);
                $('#CostNames').searchbox('setValue', varObjects[1]);
            }
        });
        return false;
    }

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

    InitFunction();
    var column = [[
        { field: 'ck', checkbox: true },
        { field: 'CustName', title: '客户名称', width: 200, align: 'left', sortable: true },
        { field: 'RoomSign', title: '房屋编号', width: 150, align: 'left', sortable: true },
        { field: 'RoomName', title: '房屋名称', width: 150, align: 'left', sortable: true },
        { field: 'ParkName', title: '车位编号', width: 100, align: 'left', sortable: true },

        { field: 'CostName', title: '费用名称', width: 150, align: 'left', sortable: true },

        { field: 'WaiversCategory', title: '减免业务类型', width: 100, align: 'left', sortable: true },
        { field: 'CreYear', title: '减免年度', width: 100, align: 'left', sortable: true },
        { field: 'CreMonth', title: '减免月份', width: 100, align: 'left', sortable: true },
        {
            field: 'WaivDate', title: '冲抵时间', width: 100, align: 'left', sortable: true, formatter: function (value, row, index) {
                var str = formatDate(row.WaivDate, "yyyy-MM-dd");
                return str;
            }
        },
        //{ field: 'WaivCostName', title: '减免费项', width: 100, align: 'left', sortable: true },
        { field: 'IsWaivName', title: '是否减免', width: 100, align: 'left', sortable: true },
        { field: 'OldWaivAmount', title: '未减免金额', width: 100, align: 'left', sortable: true },
        { field: 'OffsetAmount', title: '已减免金额', width: 100, align: 'left', sortable: true },
        {
            field: 'WriteOffIsAudit', title: '是否冲销', width: 100, align: 'left', sortable: true, formatter: function (value, row, index) {
                var str = "否";

                if (row.WriteOffIsAudit == "1") {
                    str = "是";
                }
                return str;
            }
        }
    ]];

    var toolbar = [
        {
            text: '筛选',
            iconCls: 'icon-search',
            handler: function () {
                $('#SearchDlg').parent().appendTo($("form:first"))
                $('#SearchDlg').dialog('open');
            }
        }, '-',
        {
            text: '撤销',
            iconCls: 'icon-cancel',
            handler: function () {
                var rows = $('#TableContainer').datagrid('getChecked');
                if (rows == "") {
                    HDialog.Info('请选择撤销项！');
                    return;
                }
                else {
                    var SelIID = "";
                    var SelWaivDate = "";
                    $.each(rows, function (key, val) {
                        SelIID += rows[key]["IID"] + ",";
                        SelWaivDate += rows[key]["WaivDate"] + ",";
                    });
                    SelIID = SelIID.substr(0, SelIID.length - 1);
                    SelWaivDate = SelWaivDate.substr(0, SelWaivDate.length - 1);
                    HDialog.Prompt('确认撤销选择的减免冲抵记录', function () {
                        CheckIsOverAcount(SelIID, SelWaivDate);
                    });
                }

            }
        }, '-',
        {
            text: '冲销',
            iconCls: 'icon-redo',
            handler: function () {
                var rows = $('#TableContainer').datagrid('getChecked');
                if (rows == "") {
                    HDialog.Info('请选择冲销项！');
                    return;
                }
                else {
                    var IID = "";
                    var WaivDate = "";
                    var flag = 2; //冲销标识（0审核中，1已冲销，2未冲销）
                    $.each(rows, function (key, val) {
                        if (rows[key]["WriteOffIsAudit"] == "0") {
                            flag = 0;
                            return false;
                        }


                        if (rows[key]["WriteOffIsAudit"] == "1") {
                            flag = 1;
                            return false;
                        }

                        IID += rows[key]["IID"] + ",";
                        WaivDate += rows[key]["WaivDate"] + ",";
                    });

                    if (flag == 0) {
                        HDialog.Info('冲销记录审核中，无法多次提交！');
                        return;
                    }

                    if (flag == 1) {
                        HDialog.Info('已冲销，无法多次提交！');
                        return;
                    }

                    IID = IID.substr(0, IID.length - 1);
                    WaivDate = WaivDate.substr(0, WaivDate.length - 1);
                    HDialog.Prompt('确认冲销选择的减免冲抵记录', function () {
                        Check(IID, WaivDate);
                    });
                }

            }
        }
        //, '-',
        //{
        //    text: '打印',
        //    iconCls: 'icon-print',
        //    handler: function () {
        //        document.getElementById('btnPrint').click();
        //    }
        //}
    ];

    function LoadList() {
        $("#TableContainer").datagrid({
            url: '/HM/M_Main/HC/DataGetControl.aspx?Method=DataGet&Class=WaiversFees&Command=getrepealoffsetwaivlist&' + $("#FrmForm").serialize(),
            method: "get",
            title: '',
            nowrap: false,
            pageSize: top.ListPageSize,
            pageList: top.ListPageList,
            columns: column,
            remoteSort: false,
            fitColumns: true,
            rownumbers: true,
            freezeRow: 1,
            singleSelect: false,
            pagination: true,
            width: "100%",
            toolbar: toolbar,
            border: false,
            sortOrder: "asc"
        });
        $("#SearchDlg").dialog("close");
    }

    //判断是否已结账（减免撤销）
    function CheckIsOverAcount(SelIID, SelWaivDate) {
        //判断是否已结账 2017年11月7日17:30:24
        $("#CheckDates").val(SelWaivDate);
        $.tool.DataPostChk('FrmForm', 'WriteOff', 'CheckIsWriteOff', $('#FrmForm').serialize(),
            function Init() {
            },
            function callback(_Data) {
                if (_Data == "True") {
                    HDialog.Info("包含已结账的数据，不能撤销，若需要撤销，请到冲销节点操作！");
                    return;
                } else {
                    DelRecord(SelIID, SelWaivDate);
                }
            },
            function completeCallback() {
            },
            function errorCallback() {
            });
    }


    //判断是否已结账（冲销）
    function Check(IID, WaivDate) {
        $.tool.DataPost('WriteOff', 'CheckIsWriteOff', "CheckDates=" + WaivDate,
            function Init() {
            },
            function callback(_Data) {
                $("#WriteOffIID").val(IID);
                if (_Data == "False") {
                    HDialog.Info("包含未结账的数据，无法冲销！");
                    return;
                } else {
                    $('#Dlg').parent().appendTo($("form:first"))
                    $('#Dlg').dialog('open');
                }
            },
            function completeCallback() {
            },
            function errorCallback() {

            });
    }

    //冲销操作点击事件
    function OffsetWaivDetailWriteOffClick() {
        OffsetWaivDetailWriteOff($("#WriteOffIID").val())
    }

    //执行冲销操作
    function OffsetWaivDetailWriteOff(IID) {
        $.tool.DataPost('WriteOff', 'OffsetWaivDetailWriteOff', $('#FrmForm').serialize(),
            function Init() {
            },
            function callback(_Data) {
                if ($("#ReferReason").val() == "") {
                    HDialog.Info("请填写冲销原因!");
                    return;
                } else {
                    if (_Data == "true") {
                        HDialog.Info("提交成功！");
                    } else if (_Data == "repeat") {
                        HDialog.Info("无法重复提交！");
                    }
                    else {
                        HDialog.Info("提交失败！");
                    }
                }
                $('#Dlg').dialog('close');

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

            });
    }


    //撤销
    function DelRecord(IIDs, WaivDates) {
        $("#IID").val(IIDs);
        $("#WaivDate").val(WaivDates);
        $('#btnCanCel').click();
    }

    function SelCust() {

        $('#CustName').searchbox("setValue", '');
        $('#CustID').val('');
        $('#RoomSign').searchbox("setValue", '');
        $('#RoomID').val('');
        $('#SelectRoomID').combobox({ data: [], valueField: 'RoomID', textField: 'RoomText' });

        var conent = "../DialogNew/CustDlg.aspx";

        HDialog.Open('700', '400', conent, '客户选择', false, function callback(_Data) {
            var data = JSON.parse(_Data);
            $('#CustName').searchbox("setValue", data.CustName);

            $('#CustID').val(data.CustID);


            $.tool.DataGet('Choose', 'CustRoomSigns', $('#FrmForm').serialize(),
                function Init() {
                },
                function callback(_Data) {

                    varObjects = eval("(" + _Data.replace(/\\/g, "/") + ")"); //转换为json对象
                    if (varObjects.length > 0) {

                        var RoomData = [];
                        for (var i = 0; i < varObjects.length; i++) {

                            var vIsDelLive = varObjects[i].IsDelLive;
                            var strTmp = "";

                            if (vIsDelLive == 1) {
                                strTmp = "(历史)";
                            }

                            var RoomID = varObjects[i].RoomID;
                            var RoomSign = varObjects[i].RoomSign;
                            var Buildarea = varObjects[i].BuildArea;

                            var RoomText = RoomSign + "(" + Buildarea + ")" + strTmp;
                            RoomData.push({ "RoomText": RoomText, "RoomID": RoomID });

                        }
                        $('#SelectRoomID').combobox({
                            data: RoomData,
                            valueField: 'RoomID',
                            textField: 'RoomText',
                            onChange: function (n, o) {


                                var data = $('#SelectRoomID').combobox('getData');
                                if (data.length > 0) {
                                    for (var i = 0; i < data.length; i++) {
                                        if (n == data[i].RoomID) {

                                            $('#RoomSign').searchbox('setValue', data[i].RoomText);
                                            $('#RoomID').val(data[i].RoomID);
                                            break;
                                        }
                                    }
                                }

                            }


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

        });
    }

    function SelRoom() {
        $('#CustName').searchbox("setValue", '');
        $('#CustID').val('');
        $('#RoomSign').searchbox("setValue", '');
        $('#RoomID').val('');
        $('#SelectRoomID').combobox({ data: [], valueField: 'RoomID', textField: 'RoomText' });

        var conent = "../DialogNew/RoomDlg.aspx";
        var w = $(window).width();
        var h = $(window).height();
        HDialog.Open(w, h, conent, '房屋选择', false, function callback(_Data) {
            var data = JSON.parse(_Data);
            $('#RoomSign').searchbox("setValue", data.RoomSign);
            $('#CustName').searchbox("setValue", data.CustName);
            $('#CustID').val(data.CustID);
            $('#RoomID').val(data.RoomID);

        });

    }
    //清空查询条件
    function CancelParm() {
        $('#CustName').searchbox("setValue", '');
        $("#CustID").val("");
        $('#SelectRoomID').combobox({ data: [], valueField: 'RoomID', textField: 'RoomText' });
        $("#RoomID").val("");
        $("#RoomSign").searchbox("setValue", '');
        $("#WaiversCategory").searchbox("setValue", '');

    }

    $("select").each(function () {

        var key = $(this).attr("id");

        if (key != undefined) {
            $(this).css("width", '85%');
        }
    });
</script>
