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


<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="../jscript/DateControl.js"></script>
    <script type="text/javascript" src="../jscript/JSClient.js"></script>
    <script type="text/javascript" src="../jscript/ajax.js"></script>
    <script type="text/javascript" src="../jscript/Keydown.js" event="onkeydown" for="document"></script>

    <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 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>

    <script src="../jscript/Dialog.js" type="text/javascript"></script>
    <link href="../css/framesearch_old.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-Ui/JQForm/JQForm.js"></script>
    <script type="text/javascript" src="../jscript/DatePicker/WdatePicker.js"></script>
    <style type="text/css">
        input {
            /*width: 91.7%;*/
        }
    </style>
</head>
<body>
    <form id="frmForm" runat="server">
        <input id="IsDelete" name="IsDelete" runat="server" value="0" type="hidden" />
        <input id="IsLs" name="IsLs" runat="server" value="1" type="hidden" />
        <input type="hidden" id="LsData" name="LsData" />
        <div class="SearchContainer" id="TableContainer">
        </div>
        <div id="SearchDlg" class="easyui-dialog" title="筛选条件" data-options="iconCls:'icon-search',closed: true,modal:true"
            style="width: 700px; height: 250px;">

            <table class="DialogTable">
                <tr class="hid-tr">
                    <td class="TdTitle">项目名称
                    </td>
                    <td colspan="3">
                        <input id="CommName" name="CommName" runat="server" onclick="SelComm();" style="width: 90%" />
                        <input id="CommID" size="1" type="hidden" name="CommID" runat="server" />
                        <input id="hidCommId" size="1" type="hidden" name="hidCommId" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle">收据类型
                    </td>
                    <td class="TdContentSearch">
                        <select id="DrReceive" runat="server" name="DrReceive">
                            <option value="0" selected>全部</option>
                            <option value="1">收款收据</option>
                            <option value="2">预存收据</option>
                            <%--<option value="3">退款票据</option>--%>
                        </select></td>
                    <td class="TdTitle"></td>
                    <td class="TdContentSearch"></td>
                </tr>
                <tr>
                    <td class="TdTitle">客户名称</td>
                    <td class="TdContentSearch">
                        <input id="CustName" searcher="SelCust"
                            name="CustName" class="easyui-searchbox" runat="server" data-options="editable:false" /><input id="CustID" style="width: 8px; height: 19px" type="hidden"
                                size="1" name="CustID" runat="server" /><input id="hiCustName" style="width: 12px; height: 19px" type="hidden"
                                    size="1" name="hiCustName" runat="server" /></td>
                    <td class="TdTitle">可选房号
                    </td>
                    <td class="TdContentSearch">
                        <select id="SelectRoomID" class="easyui-combobox" data-options="editable:false,panelHeight: 'auto'" name="SelectRoomID" onchange="javascript:SelectRoomID_OnChange();" runat="server">
                            <option selected></option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle">房屋编号</td>
                    <td class="TdContentSearch">
                        <input id="RoomSign" searcher="SelRoom"
                            name="RoomSign" class="easyui-searchbox" runat="server" data-options="editable:false" /><input id="RoomID" style="width: 8px; height: 22px" type="hidden"
                                size="1" name="RoomID" runat="server" /><input id="hiRoomSign" style="width: 8px; height: 22px" type="hidden"
                                    size="1" name="hiRoomSign" runat="server" /></td>
                    <td class="TdTitle">收据号码</td>
                    <td class="TdContent">
                        <input id="BillsSign" type="text"
                            name="BillsSign" runat="server" /></td>
                </tr>

                <tr>
                    <td class="TdTitle">收费日期</td>
                    <td class="TdContent" colspan="3">从<input id="EditBeginDate" class="Wdate" style="width: 40%; margin-left: 6px; margin-right: 6px" onclick="WdatePicker({ startDate: '%y-%M-01 00:00:00', dateFmt: 'yyyy-MM-dd', alwaysUseStartDate: true })" type="text" maxlength="50" name="EditBeginDate" runat="server">
                        到<input class="Wdate" id="EditEndDate" style="width: 40%; margin-left: 6px" onclick="WdatePicker({ startDate: '%y-%M-01 00:00:00', dateFmt: 'yyyy-MM-dd', alwaysUseStartDate: true })" type="text" maxlength="50" name="EditEndDate" runat="server">
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="4">
                        <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");
                $('#SelectRoomID').css("width", 150 + 'px');

                if ($("#hidCommId").val() != '0') {
                    $('.hid-tr').hide();
                }
            }
            InitFunction();

            function SelComm() {
                if ($("#hidCommId").val() != '0')
                    return;

                var w = $(window).width() * 0.7;
                HDialog.Open(w, 500, '../DialogNew/SelComm.aspx?IsCheck=0&isCommID=0', "选择管理项目", false, function callback(_Data) {
                    var arrRet = JSON.parse(_Data);
                    $("#CommID").val(arrRet.id);
                    $("#CommName").val(arrRet.name);
                });
            }

            function SelCust() {

                if ($("#CommID").val() == '') {
                    HDialog.Info("请选择项目");
                    return;
                }
                $('#CustName').searchbox("setValue", '');
                $('#CustID').val('');
                $('#RoomSign').searchbox("setValue", '');
                $('#RoomID').val('');
                $('#SelectRoomID').combobox({ data: [], valueField: 'RoomID', textField: 'RoomText' });


                var w = 700;
                var h = 400;

                var conent = "../DialogNew/CustDlg.aspx?CommID=" + $("#CommID").val();

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


                    $.tool.DataGet('Choose', 'CustRoomSigns', "CustID=" + data.CustID,
                        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 + "|" + Buildarea });

                                }
                                $('#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);
                                                    var buildArea = data[i].RoomID.split("|")[1];
                                                    $('#BuildArea').val(buildArea);
                                                    $('#CalcArea').val(buildArea);
                                                    $('#RoomID').val(data[i].RoomID.split("|")[0]);
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                });
                            }
                        },
                        function completeCallback() {
                        },
                        function errorCallback() {
                        });

                });
            }
            function SelRoom() {
                if ($("#CommID").val() == '') {
                    HDialog.Info("请选择项目");
                    return;
                }

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


                var conent = "../DialogNew/RoomDlg.aspx?CommID=" + $("#CommID").val();


                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);

                    $('#BuildArea').val(data.BuildArea);
                    $('#CalcArea').val(data.BuildArea);
                });
            }




            var columnReceipts = [[
                { field: 'ReceID', title: 'ReceID', width: 50, align: 'left', sortable: true, hidden: true },
                { field: 'CustName', title: '客户名称', width: 100, align: 'left', sortable: true },
                { field: 'RoomSign', title: '房屋编号', width: 100, align: 'left', sortable: true },
                { field: 'RoomName', title: '房屋名称', width: 100, align: 'left', sortable: true },
                { field: 'BillsSign', title: '票据号码', width: 100, align: 'left', sortable: true },
                { field: 'BillsAmount', title: '票据金额', width: 100, align: 'left', sortable: true },

                //{
                //    field: 'BillsSign', title: '票据号码', width: 100, align: 'left', sortable: true, formatter: function (value, row, index) {
                //        var str = "<a class=\"HrefStyle\"  href='#' onclick=\"ViewDetail('票据修改','" + row.ReceID + "');\">" + row.BillsSign + "</a>";
                //        return str;
                //    }
                //},
                { field: 'ChequeBill', title: '支/汇票号', width: 100, align: 'left', sortable: true },
                {
                    field: 'BillsDate', title: '收费日期', width: 120, align: 'left', sortable: true, formatter: function (value, row, index) {
                        var str = formatDate(row.BillsDate, "yyyy-MM-dd HH:mm:ss");
                        return str;
                    }
                },
                { field: 'ChargeMode', title: '收款方式', width: 100, align: 'left', sortable: true },
                { field: 'UserName', title: '收款人', width: 100, align: 'left', sortable: true },
                { field: 'ReceMemo', title: '备注', width: 100, align: 'left', sortable: true }




            ]];

            var columnPrecReceipts = [[
                { field: 'ReceID', title: 'ReceID', width: 50, align: 'left', sortable: true, hidden: true },
                { field: 'CustName', title: '客户名称', width: 100, align: 'left', sortable: true },
                { field: 'RoomSign', title: '房屋编号', width: 100, align: 'left', sortable: true },
                { field: 'RoomName', title: '房屋名称', width: 100, align: 'left', sortable: true },
                { field: 'BillsSign', title: '票据号码', width: 100, align: 'left', sortable: true },
                //{
                //    field: 'BillsSign', title: '票据号码', width: 100, align: 'left', sortable: true, formatter: function (value, row, index) {
                //        var str = "<a class=\"HrefStyle\"  href='#' onclick=\"ViewDetail('票据修改','" + row.ReceID + "');\">" + row.BillsSign + "</a>";
                //        return str;
                //    }
                //},
                { field: 'BillsAmount', title: '票据金额', width: 100, align: 'left', sortable: true },
                { field: 'ChequeBill', title: '支/汇票号', width: 100, align: 'left', sortable: true },
                {
                    field: 'BillsDate', title: '收费日期', width: 150, align: 'left', sortable: true, formatter: function (value, row, index) {
                        var str = formatDate(row.BillsDate, "yyyy-MM-dd HH:mm:ss");
                        return str;
                    }
                },
                { field: 'ChargeMode', title: '收款方式', width: 50, align: 'left', sortable: true },
                { field: 'UserName', title: '收款人', width: 100, align: 'left', sortable: true }



            ]];

            var columnRefundReceipts = [[

                { field: 'BillTypeName', title: '票据类别', width: 100, align: 'left', sortable: true },
                {
                    field: 'RefundBillSNum', title: '票据号码', width: 100, align: 'left', sortable: true, formatter: function (value, row, index) {
                        var str = "<a class=\"HrefStyle\"  href='#' onclick=\"ViewDetail('票据修改','" + row.ReceID + "');\">" + row.RefundBillSNum + "</a>";
                        return str;
                    }
                },
                { field: 'RefundDate', title: '退款日期', width: 100, align: 'left', sortable: true },
                { field: 'RefundMode', title: '退款方式', width: 100, align: 'left', sortable: true },
                { field: 'UserName', title: '退款人', width: 100, align: 'left', sortable: true }


            ]];


            var toolbar = [
                {
                    text: '筛选',
                    iconCls: 'icon-search',
                    handler: function () {
                        $('#SearchDlg').parent().appendTo($("form:first"))
                        $('#SearchDlg').dialog('open');

                    }
                },
                {
                    text: '流水认领',
                    iconCls: 'icon-add',
                    handler: function () {
                        var rows = $('#TableContainer').datagrid('getSelected');
                        console.log(rows);
                        if (rows == null) {
                            HDialog.Info('请选择票据!');
                            return;
                        }
                        else {
                            HDialog.Open('1300', '650', "../ChargesNew/SelPayNoticeLSDlg.aspx?Ram=" + Math.random() + "&IsLs=1", '流水选择', false, function (_data) {
                                var varReturn = _data;

                                if (varReturn.length > 0) {//**获得返回 刷新
                                    var hiDGrid = '[';
                                    var obj = JSON.parse(varReturn);

                                    var total = 0;
                                    $.each(obj.total.rows, function (key, item) {

                                        hiDGrid += '{"amount":"' + item.amount
                                            + '","id":"' + item.id
                                            + '","successTime":"' + item.successTime
                                            + '","wayCode":"' + item.wayCode
                                            + '","subject":"' + item.subject
                                            + '","mchNo":"' + item.mchNo
                                            + '","payOrderId":"' + item.payOrderId
                                            + '","RLamount":"' + item.可认领金额
                                            + '"},';

                                        total += parseFloat(item.可认领金额);
                                    });
                                    hiDGrid = hiDGrid.substr(0, hiDGrid.length - 1);
                                    hiDGrid += ']';

                                    $("#LsData").val(JSON.stringify(hiDGrid));
                                    console.log(JSON.stringify(hiDGrid));
                                    console.log(rows.ReceID);
                                    console.log(rows.BillsAmount);

                                    total = total.toFixed(2);

                                    console.log(total);

                                    console.log(rows.CustID);
                                    console.log(rows.RoomID);
                                    console.log(rows.CustName);
                                    console.log(rows.RoomSign);

                                    if (total != rows.BillsAmount) {
                                        HDialog.Info("流水认领金额与票据金额不相等!");
                                        return false;
                                    }

                                    //if (total > rows.BillsAmount) {

                                    //    HDialog.Prompt("流水认领金额大于票据金额是否进行快捷预存?", function a() {
                                    //        var w = $(window).width();
                                    //        var h = $(window).height();
                                    //        if (w < 1024) {
                                    //            w = 1024;
                                    //        }
                                    //        let precamount = ToDecimal(total - rows.BillsAmount, 2);
                                    //        console.log(precamount);
                                    //        var conent = "../ChargesNew/SinglePreStore.aspx?CustID=" + $("#CustID").val() + "&RoomID=" + $("#RoomID").val() + "&CustName=" + $("#CustName").val() + "&RoomSign=" + $("#RoomSign").val() + "&PrecAmount=" + precamount;
                                    //        HDialog.Open(600, 200, conent, '预存收款-快捷模式', false, function callback(_Data) {
                                    //            var row = JSON.parse(_Data);
                                    //            console.log(row);
                                    //        });
                                    //    });
                                    //    return false;
                                    //}

                                    HDialog.Prompt("确认认领?", function a() {

                                        $.tool.DataGet('Allinpay', 'LSRelate', 'ReceID=' + rows.ReceID + '&LsData=' + $("#LsData").val() + '&DrReceive=' + rows.ReceType,
                                            function Init() {
                                            },
                                            function callback(_Data) {
                                                HDialog.Info('流水认领成功！');
                                                LoadList();
                                            },
                                            function completeCallback() {
                                            },
                                            function errorCallback() {
                                            });
                                    });
                                }

                            });
                        }
                    }
                }
            ];


            function ViewDetail(title, ReceID) {

                var w = $(window).width();
                var h = $(window).height();

                var conent = '';
                var cmd = "CheckRepeal";

                if ($('#DrReceive').val() == "1") {
                    cmd = "CheckRepeal";
                }
                if ($('#DrReceive').val() == "2") {
                    cmd = "PreCostsReceiptsCheckEdit";
                }
                if ($('#DrReceive').val() == "3") {
                    cmd = "RefundFeesReceiptsCheckRepeal";
                }



                $.tool.DataGet('FeesReceipts', cmd, "ReceID=" + ReceID,
                    function Init() {
                    },
                    function callback(_Data) {
                        var r = _Data;

                        if (r.split('|')[0] == "true") {

                            if ($('#DrReceive').val() == "1") {
                                conent = '../ChargesNew/BillsEditManage.aspx?ReceID=' + ReceID;
                            }
                            if ($('#DrReceive').val() == "2") {
                                conent = '../ChargesNew/BillsPrecEditManage.aspx?ReceID=' + ReceID;
                            }
                            if ($('#DrReceive').val() == "3") {
                                conent = '../ChargesNew/BillsRefundEditManage.aspx?ReceID=' + ReceID;
                            }

                            HDialog.Open(w, h, conent, title, false, function callback(_Data) {
                                LoadList();
                            });
                        }
                        else {
                            HDialog.Info(r.split('|')[1] + "票据不能修改！");
                        }
                    },
                    function completeCallback() {
                    },
                    function errorCallback() {
                    });






            }

            function LoadList(init) {
                if (!init && $("#CommID").val() == '') {
                    HDialog.Info("请选择项目");
                    return;
                }
                var column = columnReceipts;

                if ($('#DrReceive').val() == "1") {
                    column = columnReceipts;
                }
                if ($('#DrReceive').val() == "2") {
                    column = columnPrecReceipts;
                }
                //if ($('#DrReceive').val() == "3") {
                //    column = columnRefundReceipts;
                //}

                $("#TableContainer").datagrid({
                    url: '/HM/M_Main/HC/DataPostControl.aspx',
                    method: "post",
                    nowrap: false,
                    pageSize: top.ListPageSize,
                    pageList: top.ListPageList,
                    columns: column,
                    fitColumns: true,
                    remoteSort: false,
                    singleSelect: true,
                    pagination: true,
                    width: "100%",
                    toolbar: toolbar,
                    sortOrder: "asc",
                    singleSelect: true,
                    selectOnCheck: false,
                    checkOnSelect: false,
                    rownumbers: true,
                    border: false,
                    toolbar: toolbar,
                    sortOrder: "asc",
                    onBeforeLoad: function (param) {

                        if ($('#DrReceive').val() == "0") {
                            param = $.JQForm.GetParam("FeesReceipts", "FeesBillReceipts", "TableContainer", param);
                        }

                        if ($('#DrReceive').val() == "1") {
                            param = $.JQForm.GetParam("FeesReceipts", "ReceiveFeesCancel", "TableContainer", param);
                        }
                        if ($('#DrReceive').val() == "2") {
                            param = $.JQForm.GetParam("FeesReceipts", "PreCostsReceipts", "TableContainer", param);
                        }
                        //if ($('#DrReceive').val() == "3") {
                        //    param = $.JQForm.GetParam("FeesReceipts", "RefundFeesReceiptsAll", "TableContainer", param);
                        //}
                    },
                    onLoadSuccess: function (data) {
                    }
                });

                $('#SearchDlg').dialog('close');
            }

            LoadList(true);

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


