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

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.1/jquery.min.js"></script>
    <script src="../jscript/jquery.tool.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="../Jscript-Ui/jquery-easyui-1.4.1/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../Jscript-Ui/jquery-easyui-1.4.1/themes/icon.css" />
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.1/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 rel="stylesheet" type="text/css" href="../Jscript-Ui/jquery-easyui-1.4.1/demo/demo.css" />
    <link href="../css/framedialog_twocol.css" type="text/css" rel="stylesheet" />
    <script src="../jscript/Dialog.js" type="text/javascript"></script>
    <link href="../css/framesearch.css" type="text/css" rel="stylesheet" />
</head>
<body>
    <form id="FrmForm" runat="server">
        <div id="SearchDlg" class="easyui-dialog" title="筛选条件" data-options="iconCls:'icon-search',closed: true,modal:true"
            style="width: 500px; height: 200px;">
            <table style="width: 100%; font-size: 12px; font-family: 微软雅黑;">
                <tr>
                    <td class="TdTitle">支付订单号</td>
                    <td class="TdContentSearch">
                        <input id="payOrderId" style="width: 83%;" class="easyui-validatebox" name="payOrderId" runat="server" /></td>
                    <td class="TdTitle">商户号</td>
                    <td class="TdContentSearch">
                        <input id="mchNo" style="width: 83%;" class="easyui-validatebox" name="mchNo" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle">商品标题</td>
                    <td class="TdContentSearch">
                        <input id="subject" style="width: 83%;" class="easyui-validatebox" name="subject" runat="server" /></td>
                    <td class="TdTitle">支付金额</td>
                    <td class="TdContentSearch">
                        <input id="amount" style="width: 83%;" class="easyui-validatebox" name="amount" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle">可认领金额</td>
                    <td class="TdContentSearch">
                        <input id="amountBegin" style="width: 83%;" class="easyui-validatebox" name="amountBegin" runat="server" />
                    </td>
                    <td class="TdTitle">至</td>
                    <td class="TdContentSearch">
                        <input id="amountEnd" style="width: 83%;" class="easyui-validatebox" name="amountEnd" 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>
        <div id="MemoDlg" class="easyui-dialog" title="异常流水备注" data-options="closed: true,modal:true"
            style="width: 500px; height: 200px;">
            <table style="width: 100%; font-size: 12px; font-family: 微软雅黑;">
                <tr>
                    <td class="TdTitle"><span style="color: red;">*</span>备注</td>
                    <td class="TdContentSearch" colspan="3">
                        <textarea id="Memo" name="Memo" rows="5" style="width: 83%;"></textarea>
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle"></td>
                    <td class="TdContentSearch" colspan="3"></td>
                </tr>
                <tr>
                    <td align="center" colspan="4">
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="Save();">保存</a>
                    </td>
                </tr>

            </table>
        </div>
        <div style="width: 100%;" id="TableContainer">
        </div>

        <input type="hidden" id="CommID" name="CommID" />

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

            function getUrlParam(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
                var r = window.location.search.substr(1).match(reg); //匹配目标参数
                if (r != null) return unescape(r[2]); return null; //返回参数值
            }

            function InitTableHeight() {
                var h = $(window).height();
                $("#TableContainer").css("height", h);

            }
            InitTableHeight();

            var column = [[

                { field: 'CommName', title: '项目名称', width: 180, align: 'left', sortable: true },
                { field: 'mchNo', title: '商户号', width: 180, align: 'left', sortable: true },
                { field: 'payOrderId', title: '支付订单号', width: 180, align: 'left', sortable: true },
                { field: 'mchOrderNo', title: '商户订单号', width: 180, align: 'left', sortable: true },
                { field: 'wayCode', title: '支付方式', width: 100, align: 'left', sortable: true },
                { field: 'amount', title: '支付金额', width: 100, align: 'left', sortable: true },
                { field: 'successTime', title: '支付时间', width: 150, align: 'left', sortable: true },
                { field: 'subject', title: '商品标题', width: 150, align: 'left', sortable: true },
                { field: 'body', title: '商品描述', width: 180, align: 'left', sortable: true },
                { field: 'channelUser', title: '用户标识', width: 100, align: 'left', sortable: true },
                { field: 'createdAt', title: '创建时间', width: 150, align: 'left', sortable: true },
                { field: '已认领金额', title: '已认领金额', width: 150, align: 'left', sortable: true },
                {
                    field: '可认领金额', title: '可认领金额', width: 150, align: 'left', sortable: true,
                    editor: {
                        type: 'numberbox',
                        options: {
                            required: true,
                            precision: 2
                        }
                    }
                },
                { field: 'memo', title: '异常流水备注', width: 150, align: 'left', sortable: true }

            ]];

            var toolbar = [
                {
                    text: '异常流水备注',
                    iconCls: 'icon-save',
                    handler: function () {

                        $('#TableContainer').datagrid('acceptChanges');

                        var row = $('#TableContainer').datagrid('getSelected');
                        if (row == null) {
                            HDialog.Info('请选择数据！');
                            return;
                        }

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

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

                }, '-',
                {
                    text: '导出Excel',
                    iconCls: 'icon-page_white_excel',
                    handler: function () {
                        window.open("../ChargesNew/LSSearchBrowseExcel.aspx");
                    }
                }
            ];
            var editIndex = undefined;



            // 结束编辑的辅助函数
            function endEditing() {
                if (editIndex == undefined) {
                    return true;
                }

                if ($('#TableContainer').datagrid('validateRow', editIndex)) {
                    $('#TableContainer').datagrid('endEdit', editIndex);
                    editIndex = undefined;
                    return true;
                } else {

                    return false;
                }
            }

            function Save() {
                var row = $('#TableContainer').datagrid('getSelected');

                var strMemo = $("#Memo").val();
                console.log(row.id);
                if (strMemo != "") {
                    $.tool.DataGet('Allinpay', 'PayNoticeLSMemo', 'id=' + row.id + '&memo=' + strMemo,
                        function Init() {
                        },
                        function callback(_Data) {
                            HDialog.Info('保存成功！');
                            LoadList();
                        },
                        function completeCallback() {
                        },
                        function errorCallback() {
                        });
                } else {
                    HDialog.Info('请输入备注！');
                }
            }


            function LoadList(_Data, rows) {


                $("#TableContainer").datagrid({
                    url: '/HM/M_Main/HC/DataGetControl.aspx?Method=DataGet&Class=Allinpay&Command=PayNoticeLSSearchNew&' + $("#FrmForm").serialize(),
                    method: "get",
                    title: '',
                    nowrap: false,
                    pageSize: top.ListPageSize,
                    pageList: top.ListPageList,
                    loadMsg: '数据加载中,请稍候...',
                    nowrap: false,
                    columns: column,
                    fitColumns: true,
                    remoteSort: false,
                    singleSelect: true,
                    pagination: true,
                    width: "100%",
                    toolbar: toolbar,
                    rownumbers: true,
                    sortOrder: "asc",
                    border: false,
                    singleSelect: true,
                    selectOnCheck: false,
                    checkOnSelect: false,
                    onDblClickRow: function (rowIndex, rowData) {

                        if (editIndex != rowIndex) {
                            if (endEditing()) {
                                // 开始编辑该行
                                $('#TableContainer').datagrid('beginEdit', rowIndex);

                                // 1. 获取“可认领金额”列的编辑器
                                var editor = $('#TableContainer').datagrid('getEditor', {
                                    index: rowIndex,
                                    field: '可认领金额'
                                });

                                if (editor) {
                                    // 2. 获取该行的原始金额，并转换为数字
                                    var originalAmount = parseFloat(rowData['可认领金额']);

                                    // 3. 为编辑器绑定 onChange 事件
                                    $(editor.target).numberbox({
                                        onChange: function (newValue, oldValue) {
                                            var inputAmount = parseFloat(newValue);

                                            // 4. 校验：如果输入的是有效数字且大于原值
                                            if (!isNaN(inputAmount) && inputAmount > originalAmount) {
                                                HDialog.Info('输入金额不能超过可认领金额！');
                                                // 5. 将输入框的值恢复为上一个有效值
                                                $(this).numberbox('setValue', oldValue);
                                            }
                                        }
                                    });
                                }

                                editIndex = rowIndex;
                            } else {
                                $('#TableContainer').datagrid('selectRow', editIndex);
                            }
                        }

                    },
                    onLoadSuccess: function (data) {

                    }

                });
                $("#SearchDlg").dialog("close");
            }
            LoadList();

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