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


<!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" />
    <script src="../jscript/CloseAjaxCache.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Jscript-Ui/JQForm/JQForm.js"></script>
    <script src="../jscript/DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="../jscript/Dialog.js" type="text/javascript"></script>
    <script src="../jscript/DateFormat.js" type="text/javascript"></script>
    <style type="text/css">
        .SearchTable {
            width: 600px;
            height: auto;
        }

            .SearchTable .TdTitle {
                width: 15%;
            }

            .SearchTable .TdContent {
                width: 35%;
            }

        .ContainerLeft {
            float: left;
            overflow-y: auto;
            border-right: 1px solid #cccccc;
        }

        .ContainerRight {
            float: left;
            overflow: auto;
        }

        .toolbarLeft {
            float: left;
            overflow-y: auto;
            width: 49.7%;
        }

        .toolbarRight {
            float: left;
            width: 49.7%;
            overflow: auto;
        }

        .subtotal {
            font-weight: bold;
        }

        #CommNames {
            width: 91.7%;
            height: 60px;
            border: 1px solid #cccccc;
            font-size: 12px;
            padding: 2px;
            resize: none;
        }
    </style>
</head>
<body>
    <form id="frmForm" runat="server">
        <div class="datagrid-toolbar toolbarLeft" id="divttFine">
            <table cellspacing="0" cellpadding="0">
                <tr>
                    <td>
                        <a href="javascript:void(0)" onclick="Search(); " class="l-btn l-btn-small l-btn-plain" id="search">
                            <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">筛选</span><span class="l-btn-icon icon-search">&nbsp;</span></span></a>

                        <a href="javascript:void(0)" onclick="ExcelPrint(); " class="l-btn l-btn-small l-btn-plain">
                            <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">导出</span><span class="l-btn-icon icon-page_white_excel">&nbsp;</span></span></a>

                        <a href="javascript:void(0)" onclick="PayAccountFinAndBank(); " class="l-btn l-btn-small l-btn-plain" id="Account1">
                            <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">自动对账</span><span class="l-btn-icon icon-add">&nbsp;</span></span></a>

                        <a href="javascript:void(0)" onclick="PayAccountFinAndBank2(); " class="l-btn l-btn-small l-btn-plain" id="Account2">
                            <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">手工复核</span><span class="l-btn-icon icon-add">&nbsp;</span></span></a>
                    </td>
                </tr>
            </table>
        </div>

        <div class="datagrid-toolbar toolbarRight" id="divttBank">
            <table cellspacing="0" cellpadding="0">
                <tr>
                    <td>
                        <a href="javascript:void(0)" onclick="Search2(); " class="l-btn l-btn-small l-btn-plain">
                            <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">查询</span><span class="l-btn-icon icon-search"></span></span></a>
                        <a href="javascript:void(0)" onclick="ToExcel(); " class="l-btn l-btn-small l-btn-plain">
                            <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">导出Excel</span><span class="l-btn-icon icon-page_white_excel">&nbsp;</span></span></a>
                    </td>
                </tr>
            </table>
        </div>

        <div id="ContainerLeft" class="ContainerLeft">
            <div id="TableContainerFinance" style="background-color: #cccccc;">
            </div>
        </div>

        <div id="ContainerRight" class="ContainerRight">
            <div id="TableContainerBank" style="background-color: #cccccc;">
            </div>
        </div>

        <div id="SearchDlg" class="easyui-dialog" title="筛选条件" data-options="iconCls:'icon-search',closed: true,modal:true"
            style="width: 800px; height: 300px;">
            <table class="DialogTable" style="width: 100%; font-size: 12px; font-family: 微软雅黑;">
                <tr>
                    <td class="TdTitle">项目名称
                    </td>
                    <td colspan="3">
                        <textarea id="CommNames" name="CommNames" runat="server" ru="server" onclick="SelComm();"></textarea>
                        <input id="CommIDs" size="1" type="hidden" name="CommIDs" runat="server" />
                        <input id="hidCommId" size="1" type="hidden" name="hidCommId" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle">客户名称</td>
                    <td class="TdContentSearch">
                        <input id="CustName" name="CustName" type="text" class="easyui-validatebox" style="border: 1px #cccccc solid;" />
                    </td>
                    <td class="TdTitle">房屋编号</td>
                    <td class="TdContentSearch">
                        <input id="RoomSign" name="RoomSign" type="text" class="easyui-validatebox" style="border: 1px #cccccc solid;" />
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle">订单生成时间起</td>
                    <td class="TdContentSearch">
                        <input class="Control_IteminputNoStyle" id="PaySuccessDateBg" name="PaySuccessDateBg" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd', skin: 'default' })" format="date" readonly="readonly" style="border: 1px #cccccc solid;" runat="server" />
                    </td>
                    <td class="TdTitle">订单生成时间止</td>
                    <td class="TdContentSearch">
                        <input class="Control_IteminputNoStyle" id="PaySuccessDateEnd" name="PaySuccessDateEnd" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd', skin: 'default' })" format="date" readonly="readonly" style="border: 1px #cccccc solid;" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle">支付完成时间起</td>
                    <td class="TdContentSearch">
                        <input class="Control_IteminputNoStyle" id="PayTimeBg" name="PayTimeBg" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd', skin: 'default' })" format="date" readonly="readonly" style="border: 1px #cccccc solid;" runat="server" />
                    </td>
                    <td class="TdTitle">支付完成时间止</td>
                    <td class="TdContentSearch">
                        <input class="Control_IteminputNoStyle" id="PayTimeEnd" name="PayTimeEnd" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd', skin: 'default' })" format="date" readonly="readonly" style="border: 1px #cccccc solid;" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle">业务订单号</td>
                    <td class="TdContentSearch">
                        <input id="OrderSN" name="OrderSN" type="text" class="easyui-validatebox" onchange="OrderSNChange()" style="border: 1px #cccccc solid;" />
                    </td>
                    <td class="TdTitle"></td>
                    <td class="TdContentSearch"></td>
                </tr>

                <tr>
                    <td align="center" colspan="4">
                        <a href="javascript:void(0)" onclick="LoadList(); " class="easyui-linkbutton" data-options="iconCls:'icon-search'">
                            <span class="l-btn-text">查询</span></a>
                        <a href="javascript:void(0)" onclick="FinanceClear(); " class="easyui-linkbutton" data-options="iconCls:'icon-filter'">
                            <span class="l-btn-text">清空</span></a>
                    </td>
                </tr>
            </table>
        </div>

        <div id="SearchDlg2" class="easyui-dialog" title="筛选条件" data-options="iconCls:'icon-search',closed: true,modal:true"
            style="width: 800px; height: 300px;">
            <table class="DialogTable" style="width: 100%; font-size: 12px; font-family: 微软雅黑;">
                <tr>
                    <td class="TdTitle">商户号</td>
                    <td class="TdContentSearch">
                        <input id="shh" name="shh" type="text" class="easyui-validatebox" style="border: 1px #cccccc solid;" />
                    </td>
                    <td class="TdTitle">交易单号</td>
                    <td class="TdContentSearch">
                        <input class="Control_IteminputNoStyle" id="jydh" name="jydh" style="border: 1px #cccccc solid;" />
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle">交易完成时间起</td>
                    <td class="TdContentSearch">
                        <input class="Control_IteminputNoStyle" id="timeEndBg" name="timeEndBg" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd', skin: 'default' })" format="date" readonly="readonly" style="border: 1px #cccccc solid;" runat="server" />
                    </td>
                    <td class="TdTitle">交易完成时间止</td>
                    <td class="TdContentSearch">
                        <input class="Control_IteminputNoStyle" id="timeEndEnd" name="timeEndEnd" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd', skin: 'default' })" format="date" readonly="readonly" style="border: 1px #cccccc solid;" runat="server" />
                    </td>
                </tr>

                <tr>
                    <td class="TdTitle">订单号</td>
                    <td class="TdContentSearch">
                        <input id="ddh" name="ddh" type="text" class="easyui-validatebox" onchange="ddhChange()" style="border: 1px #cccccc solid;" />
                    </td>
                </tr>

   
                <tr>
                    <td align="center" colspan="4">
                        <a href="javascript:void(0)" onclick="LoadList(); " class="easyui-linkbutton" data-options="iconCls:'icon-search'">
                            <span class="l-btn-text">查询</span></a>
                        <a href="javascript:void(0)" onclick="BankClear(); " class="easyui-linkbutton" data-options="iconCls:'icon-filter'">
                            <span class="l-btn-text">清空</span></a>
                    </td>
                </tr>
            </table>
        </div>

        <div id="SearchDlg3" class="easyui-dialog" title="对账确认" data-options="iconCls:'icon-search',closed: true,modal:true"
            style="width: 350px; height: 150px;">
            <table class="DialogTable">

                <tr>
                    <td class="TdTitle">备注</td>

                    <td class="TdContentSearch" colspan="3">
                        <input class="Control_ItemInput" id="Memo" name="Memo" runat="server"></td>
                </tr>
                <tr>
                    <td align="center" colspan="4">
                        <a href="#" id="search2" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="ok();">确定</a>
                </tr>
            </table>
        </div>

        <script type="text/javascript">

            function Search() {
                $('#SearchDlg').parent().appendTo($("form:first"))
                $('#SearchDlg').dialog('open');
            }

            function Search2() {
                $('#SearchDlg2').parent().appendTo($("form:first"))
                $('#SearchDlg2').dialog('open');
            }

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

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

            function InitFunction() {
                var h = $(window).height();
                $("#TableContainerFinance").css("height", h /2 - 1 + "px");
                $("#TableContainerBank").css("height", h / 2 + "px");

                var w = $(window).width();
                $("#TableContainerFinance").css("width", w + "px");
                $("#TableContainerBank").css("width", w + "px");

                $("#divttFine").css("width", w + "px");
                $("#divttBank").css("width", w + "px");
            }
            InitFunction();

            function FinanceClear() {
                $('#PaySuccessDateBg').val('');
                $('#PaySuccessDateEnd').val('');
                $('#timeEndBg').val('');
                $('#timeEndEnd').val('');
                $('#PayTimeBg').val('');
                $('#PayTimeEnd').val('');
                $('#CustName').val('');
                $('#RoomSign').val('');
                $('#OrderSN').val('');
            }

            function BankClear() {
                $('#timeEndBg').val('');
                $('#timeEndEnd').val('');
                $('#shh').val('');
                $('#yjdh').val('');
                $('#ddh').val('');
            }

            //导出
            function ExcelPrint() {
                var url = '../ChargesNew/AllinPayAccountExcel.aspx?' + 'random=' + Math.random();
                window.open(url);
            }

            function GetParamet() {
                var str = "&PaySuccessDateBg=" + $("#PaySuccessDateBg").val();
                str += "&PaySuccessDateEnd=" + $("#PaySuccessDateEnd").val();
                str += "&PayTimeBg=" + $("#PayTimeBg").val();
                str += "&PayTimeEnd=" + $("#PayTimeEnd").val();
                str += "&CustName=" + $("#CustName").val();
                str += "&RoomSign=" + $("#RoomSign").val();
                str += "&OrderSN=" + $("#OrderSN").val();
                str += "&timeEndBg=" + $("#timeEndBg").val();
                str += "&timeEndEnd=" + $("#timeEndEnd").val();
                str += "&shh=" + $("#shh").val();
                str += "&jydh=" + $("#jydh").val();
                str += "&ddh=" + $("#ddh").val();

                return encodeURI(str);
            }

            function PaySuccessDateBgChange() {
                $('#timeEndBg').val($('#PaySuccessDateBg').val());
            }

            function PaySuccessDateEndChange() {
                $('#timeEndEnd').val($('#PaySuccessDateEnd').val());
            }

            function timeEndBgChange() {
                $('#PaySuccessDateBg').val($('#timeEndBg').val());
            }

            function timeEndEndChange() {
                $('#PaySuccessDateEnd').val($('#timeEndEnd').val());
            }

            function BusinessTradeNoChange() {
                $('#BankBusinessTradeNo').val($('#BusinessTradeNo').val());
            }

            function BankBusinessTradeNoChange() {
                $('#BusinessTradeNo').val($('#BankBusinessTradeNo').val());
            }

            function OrderSNChange() {
                $('#ddh').val($('#OrderSN').val());
            }

            function ddhChange() {
                $('#OrderSN').val($('#ddh').val());
            }

            //对账
            function PayAccountFinAndBank() {
                $.tool.DataGet('Allinpay', 'AllinpayPayAccount', 'random=' + Math.random() + GetParamet(),
                    function Init() {
                    },
                    function callback(_Data) {
                        HDialog.Info("对账成功" + _Data + "条数据");
                        LoadList();
                    },
                    function completeCallback() {
                    },
                    function errorCallback() {
                    });
            }

            function PayAccountFinAndBank2() {

                $('#SearchDlg3').parent().appendTo($("form:first"))
                $('#SearchDlg3').dialog('open');

            }

            function ok() {
                var row = $("#TableContainerFinance").datagrid("getChecked");
                if (row == null || row.length == 0) {
                    HDialog.Info('请选择天问的流水数据！');
                    return;
                }
                if (row.length > 1) {
                    HDialog.Info('请选择一条数据操作！');
                    return;
                }

                var row2 = $("#TableContainerBank").datagrid("getChecked");
                if (row2 == null || row2.length == 0) {
                    HDialog.Info('请选择第三方对账明细！');
                    return;
                }

                var PaymentOrderId = row[0].Id;
                var CommID = row[0].CommID;
                var OrderSN = row[0].OrderSN;

                var jydh = row2[0].jydh;
                var Memo = $("#Memo").val();

                $.tool.DataGet('Allinpay', 'AllinpayPayAccount_Action', 'random=' + Math.random() + '&PaymentOrderId=' + PaymentOrderId + '&OrderSN=' + OrderSN + '&jydh=' + jydh + '&CommID=' + CommID + '&Memo=' + Memo,
                    function Init() {
                    },
                    function callback(_Data) {
                        HDialog.Info('手动对账成功！');
                        LoadList();
                    },
                    function completeCallback() {
                    },
                    function errorCallback() {
                    });

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

            function ToExcel() {
                window.open("../ChargesNew/AllinPayAccountBankExcel.aspx?shh=" + $("#shh").val() + "&jydh=" + $("#jydh").val() + "&timeEndBg=" + $("#timeEndBg").val() + "&timeEndEnd=" + $("#timeEndEnd").val() + "&ddh=" + $("#ddh").val());
            }

            var frozenColumns;
            frozenColumns = [[
                /*{ field: 'ck', checkbox: true },*/
                { field: 'CommName', title: '项目', width: 150, align: 'left', sortable: true },
                { field: 'CustName', title: '客户名称', width: 120, align: 'left', sortable: true },
            ]];

            var columnFinance;
            columnFinance = [[
                { field: 'RoomSign', title: '房屋编号', width: 150, align: 'left', sortable: true },
                { field: 'OrderSN', title: '业务订单号', width: 180, align: 'left', sortable: true },
                { field: 'DueAmount', title: '应付总金额', width: 100, align: 'left', sortable: true },
                {
                    field: 'CreateTime', title: '订单生成时间', width: 180, align: 'left', sortable: true,
                    formatter: function (value, row, index) {
                        var str = formatDate(row.CreateTime, "yyyy-MM-dd HH:mm:ss");
                        return str;
                    }
                },
                {
                    field: 'PayTime', title: '支付时间', width: 180, align: 'left', sortable: true,
                    formatter: function (value, row, index) {
                        var str = formatDate(row.PayTime, "yyyy-MM-dd HH:mm:ss");
                        return str;
                    }
                },

                { field: 'PaidAmount', title: '已支付金额', width: 100, align: 'left', sortable: true },
                {
                    field: 'IsSuccName', title: '是否下帐', width: 100, align: 'left', sortable: true,
                    formatter: function (value, row, index) {
                        if (row.StateName == "已支付已下账") {
                            return '是';
                        } else {
                            return '否';
                        }
                    }
                },
                { field: 'StateName', title: '交易状态', width: 100, align: 'left', sortable: true },
                { field: 'ChargeMode', title: '收款方式', width: 200, align: 'left', sortable: true }
            ]];

            var columnBank;
            columnBank = [[
                /*{ field: 'ck', checkbox: true },*/
                { field: 'shh', title: '商户号', width: 180, align: 'left', sortable: true },
                { field: 'mdmc', title: '门店名称', width: 150, align: 'left', sortable: true },
                {
                    field: 'jyrq', title: '交易日期', width: 150, align: 'left', sortable: true, sortable: true,
                    formatter: function (value, row, index) {
                        var str = formatDate(row.jyrq, "yyyy-MM-dd");
                        return str;
                    }
                },
                { field: 'jysj', title: '交易时间', width: 150, align: 'left', sortable: true },
                { field: 'jylx', title: '交易类型', width: 120, align: 'left', sortable: true },
                { field: 'cplx', title: '产品类型', width: 120, align: 'left', sortable: true },
                { field: 'jydh', title: '交易单号', width: 150, align: 'left', sortable: true },
                { field: 'ddh', title: '订单号', width: 150, align: 'left', sortable: true },
                { field: 'jyje', title: '交易金额', width: 100, align: 'left', sortable: true }, 
                { field: 'jywcrq', title: '交易完成日期', width: 100, align: 'left', sortable: true },
                { field: 'sxf', title: '手续费', width: 100, align: 'left', sortable: true },
                { field: 'jsje', title: '结算金额', width: 100, align: 'left', sortable: true }
            ]];

            function LoadList() {
                $("#TableContainerFinance").datagrid({
                    url: '/HM/M_Main/HC/DataPostControl.aspx',
                    method: "post",
                    pageSize: top.ListPageSize,
                    pageList: top.ListPageList,
                    nowrap: false,
                    columns: columnFinance,
                    frozenColumns: frozenColumns,
                    fitColumns: false,
                    singleSelect: true,
                    rownumbers: true,
                    border: false,
                    pagination: true,
                    width: "100%",
                    checkOnSelect: true,
                    selectOnCheck: true,
                    toolbar: '#divttFine',
                    showFooter: true,
                    sortOrder: "asc",
                    onBeforeLoad: function (param) {
                        param = $.JQForm.GetParam("Allinpay", "GetTwPaymentOrder", "TableContainerFinance", param);
                    },
                    onLoadSuccess: function (data) {
                        $('#SearchDlg').dialog('close');
                    },
                    rowStyler: function (index, row) {
                    }
                });
                $("#TableContainerBank").datagrid({
                    url: '/HM/M_Main/HC/DataPostControl.aspx',
                    method: "post",
                    pageSize: top.ListPageSize,
                    pageList: top.ListPageList,
                    nowrap: false,
                    columns: columnBank,
                    fitcolumns: false,
                    singleSelect: true,
                    rownumbers: true,
                    border: false,
                    pagination: true,
                    width: "100%",
                    checkOnSelect: true,
                    selectOnCheck: true,
                    toolbar: '#divttBank',
                    showFooter: true,
                    sortOrder: "asc",
                    onBeforeLoad: function (param) {
                        param = $.JQForm.GetParam("Allinpay", "GetAllinpayOrder", "TableContainerBank", param);
                    },
                    onLoadSuccess: function (data) {
                        $('#SearchDlg2').dialog('close');
                    },
                    rowStyler: function (index, row) {
                    }
                });
            }
            LoadList();

            function GetQueryString(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]); return null;
            }
        </script>
    </form>
</body>
</html>
