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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <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>
    <script src="../jscript/format.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 type="text/javascript" src="../jscript/DatePicker/WdatePicker.js"></script>
    <style type="text/css">
        #SearchDlg {
            padding: 10px;
            width: 550px;
            height: 250px;
        }

        .SearchTable {
            width: 550px;
            height: auto;
        }

        .SearchTable .TdTitle {
            width: 15%;
        }

        .SearchTable .TdContent {
            width: 35%;
        }

        td {
            padding: 3px 0;
        }

        #CommNames {
            width: 91.7%;
            height: 60px;
            border: 1px solid #cccccc;
            font-size: 12px;
        }
    </style>
</head>
<body>
    <form id="frmForm" runat="server">
        <!-- 隐藏域 Start -->
        
        <input id="IsInitLoad" type="hidden" name="IsInitLoad" value="1" />
        <input id="CommID" name="CommID" value="" type="hidden" runat="server" />
        <!-- 隐藏域 End -->

        <!-- 进度条 Start -->
        <div class="datagrid-mask" style="height: 100%; width: 100%;"></div>
        <div class="datagrid-mask-msg" style='font-size: 12px; height: 55px; border: 1px solid #cccccc; z-index: 999999;'>
            <div id='DivProgressBar' class='easyui-progressbar' style='width: 200px; border: 1px solid #cccccc; margin-top: 10px;'></div>
            <div id='DivMsg' style='width: 200px; text-align: center; margin-top: 5px;'></div>
        </div>
        <!-- 进度条 End -->

        <!-- 筛选条件弹窗 Start -->
        <div id="SearchDlg" class="easyui-dialog" title="筛选条件" style="overflow: hidden;" data-options="iconCls:'icon-search',closed: true,modal:true">
            <table class="SearchTable">
                <tr>
                    <td class="TdTitle">项目名称</td>
                    <td class="TdContent" colspan="3">
                        <textarea id="CommNames" name="CommNames" onclick="SelComm();" runat="server" ru="server" readonly></textarea>
                        <input id="CommIDs" name="CommIDs" value="" type="hidden" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle">费用开始时间</td>
                    <td class="TdContentSearch">
                        <input id="StartFeesDueDate" name="StartFeesDueDate" class="Wdate" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" runat="server" style="width: 80%;" />
                    </td>
                    <td class="TdTitle">费用结束时间</td>
                    <td class="TdContentSearch">
                        <input id="EndFeesDueDate" name="EndFeesDueDate" class="Wdate" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" runat="server" style="width: 80%;" />
                    </td>
                </tr>
                 <tr>
                    <td class="TdTitle">收款截止时间</td>
                    <td class="TdContentSearch">
                       <input id="CutEndDate" name="CutEndDate" class="Wdate" onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" runat="server" style="width: 80%;" />
                    </td>
                    <td class="TdTitle">房屋状态</td>
                    <td class="TdContentSearch">
                        <input id="RoomStateNames" class="easyui-searchbox" searcher="SelRoomState" name="RoomStateNames" runat="server" />
                        <input id="RoomStates" type="hidden" name="RoomStates" runat="server" />
                        <input id="hiRoomStateNames" type="hidden" name="hiRoomStateNames" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="TdTitle">费用科目</td>
                    <td class="TdContentSearch">
                        <input id="CostNames" class="easyui-searchbox" searcher="SelCost" data-options="editable:false" name="CostNames" runat="server" style="width: 95%;" />
                        <input id="CostIDs" type="hidden" name="CostIDs" runat="server" />
                    </td>
                    <td class="TdTitle">账龄计算时间</td>
                    <td class="TdContentSearch">
                        <input type="text" class="Wdate" style="width: 100px;" onclick="WdatePicker({ startDate: '%y-%M', dateFmt: 'yyyy-MM', alwaysUseStartDate: true })" id="YearMonth"   name="YearMonth" />
                    </td>
                </tr>
                <tr>
                    <td colspan="4" style="text-align: center; padding-top: 5px;">
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="SearchData();">统计</a>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onclick="ResetFilter();">清空</a>
                    </td>
                </tr>
            </table>
        </div>
        <!-- 筛选条件弹窗 End -->

        <div id="TableContainer" style="width: 100%;"></div>
        <script type="text/javascript" src="../jscript/Cache.js"></script>
        <script src="../jscript/CloseAjaxCache.js" type="text/javascript"></script>
        <script type="text/javascript">

            $(function () {

                var currentMonthFirst = getCurrentMonthFirst();
                var currentMonthLast = getCurrentMonthLast();

                $("#StartFeesDueDate").val(currentMonthFirst);
                $("#EndFeesDueDate").val(currentMonthLast);
                $("#CutEndDate").val(currentMonthLast + " 23:59:59");

                InitFunction();
                LoadData();
            });

            function SelComm() {

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

            //选择费用项目
            function SelCost() {

                HDialog.Open('700', '450', "../dialogNew/MultiCorpCostDlg.aspx" + "?Ram=" + Math.random(), '收费项目选择', false, function (_data) {
                    var varReturn = _data;
                    if (varReturn != "") {//**获得返回 刷新
                        var varObjects = varReturn.split("\t");
                        $('#CostIDs').val(varObjects[0]);
                        $('#CostNames').searchbox('setValue', varObjects[1]);
                    }
                });
            }

            function SelRoomState() {

                var strRoomStates = "";
                var strCommIDs = $("#CommIDs").val();

                HDialog.Open('700', '450', "../dialogNew/MultiRoomStateDlg.aspx"
                    + "?RoomStates=" + strRoomStates + "&CommIDs=" + strCommIDs + "&Ram=" + Math.random(), '房屋状态选择', false, function (_data) {
                    var varReturn = _data;

                    if (varReturn != "") {//**获得返回 刷新
                        var varObjects = varReturn.split("\t");

                        $('#RoomStates').val(varObjects[0]);
                        $('#RoomStateNames').searchbox('setValue', varObjects[1]);
                        $('#hiRoomStateNames').val(varObjects[0]);
                    }

                });
            }

            //重置筛选条件
            function ResetFilter() {
               
                var currentMonthFirst = getCurrentMonthFirst();
                var currentMonthLast = getCurrentMonthLast();

                //$("#CommNames").val("");
                //$("#CommIDs").val("");

                $("#StartFeesDueDate").val(currentMonthFirst);
                $("#EndFeesDueDate").val(currentMonthLast);
                $("#CutEndDate").val(currentMonthLast + " 23:59:59");

                $("#CostIDs").val("");
                $("#CostNames").searchbox("setValue", "");

                $("#RoomStates").val("");
                $("#RoomStateNames").searchbox("setValue", "");

                $("#YearMonth").val("");

            }

            //获取当月最后一天
            function getCurrentMonthLast() {
                var date = new Date();
                var currentMonth = date.getMonth();
                var nextMonth = ++currentMonth;
                var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);
                var oneDay = 1000 * 60 * 60 * 24;
                var lastTime = new Date(nextMonthFirstDay - oneDay);
                var month = parseInt(lastTime.getMonth() + 1);
                var day = lastTime.getDate();
                if (month < 10) {
                    month = '0' + month
                }
                if (day < 10) {
                    day = '0' + day
                }
                return date.getFullYear() + '-' + month + '-' + day;
            }

            function getCurrentMonthFirst() {
                var date = new Date();
                var currentMonth = date.getMonth();

                var nextMonthFirstDay = new Date(date.getFullYear(), currentMonth, 1);
                
                var firstTime = new Date(nextMonthFirstDay);
                var month = parseInt(firstTime.getMonth() + 1);
                var day = firstTime.getDate();
                if (month < 10) {
                    month = '0' + month
                }
                if (day < 10) {
                    day = '0' + day
                }
                return date.getFullYear() + '-' + month + '-' + day;
            }

            //网格初始化
            function InitFunction() {
                var h = $(window).height();
                var w = $(window).width();
                $("#TableContainer").css("height", h + "px");
                $("#TableContainer").css("width", w + "px");
            }

            var frozenColumns = [[
                { field: '序号', title: '序号', align: 'left', sortable: true, width: 100 },
                { field: '区域名称', title: '区域名称', align: 'left', sortable: true, width: 150 },
                { field: '项目名称', title: '项目名称', align: 'left', sortable: true, width: 150  },
                { field: '房屋编号', title: '房屋编号', align: 'left', sortable: true, width: 150  }
            ]];

            var column = [
                [
                    { rowspan: 2, field: '入住状态', title: '入住状态', align: 'center', sortable: true, width: 100 },
                    { rowspan: 2, field: '房屋状态', title: '房屋状态', align: 'center', sortable: true, width: 100 },

                    { colspan: 9, title: '欠费情况分析' },
                    { colspan: 4, title: '日常缴费信息' }
                ], [
                    {
                        field: '欠费总额', title: '欠费总额', align: 'left', sortable: true, width: 120, formatter: function (value, row, index) {

                            return formatNumberRgx(value);
                        }
                    },
                    {
                        field: '前期欠费', title: '前期欠费', align: 'left', sortable: true, width: 120, formatter: function (value, row, index) {

                            return formatNumberRgx(value);
                        }
                    },
                    {
                        field: '本期欠费', title: '本期欠费', align: 'left', sortable: true, width: 120, formatter: function (value, row, index) {

                            return formatNumberRgx(value);
                        }
                    },
                    {
                        field: '欠费1', title: '欠费1至3月', align: 'left', sortable: true, width: 120, formatter: function (value, row, index) {

                            return formatNumberRgx(value);
                        }
                    },
                    {
                        field: '欠费2', title: '欠费4至6月', align: 'left', sortable: true, width: 120, formatter: function (value, row, index) {

                            return formatNumberRgx(value);
                        }
                    },
                    {
                        field: '欠费3', title: '欠费7至12月', align: 'left', sortable: true, width: 120, formatter: function (value, row, index) {

                            return formatNumberRgx(value);
                        }
                    },
                    {
                        field: '欠费4', title: '欠费1至2年', align: 'left', sortable: true, width: 120, formatter: function (value, row, index) {

                            return formatNumberRgx(value);
                        }
                    },
                    {
                        field: '欠费5', title: '欠费2至3年', align: 'left', sortable: true, width: 120, formatter: function (value, row, index) {

                            return formatNumberRgx(value);
                        }
                    },
                    {
                        field: '欠费6', title: '欠费3年以上', align: 'left', sortable: true, width: 120, formatter: function (value, row, index) {

                            return formatNumberRgx(value);
                        }
                    },
                    { field: '客户名称', title: '缴费人', align: 'left', sortable: true, width: 120 },
                    { field: '联系方式', title: '联系方式', align: 'left', sortable: true, width: 200 },
                    { field: '缴费习惯', title: '缴费习惯', align: 'left', sortable: true, width: 120 },
                    { field: '未缴费原因', title: '未缴费原因备注', align: 'left', sortable: true, width: 200 }
                ]
            ];

            var toolbar = [
                {
                    text: '筛选',
                    iconCls: 'icon-search',
                    handler: function () {
                        $('#SearchDlg').parent().appendTo($("form:first"));
                        $('#SearchDlg').dialog('open');
                    }
                }, '-',
                {
                    text: 'Excel导出',
                    iconCls: 'icon-page_white_excel',
                    handler: function () {
                        var rowData = $('#TableContainer').datagrid('getData');
                        if (rowData == '') {
                            HDialog.Info('请先生成报表');
                        }
                        else {
                            window.location.href = "CommFeesDebtsCutSearch_DetailToExcel.aspx";
                        }
                    }
                }
            ];

            var ProgressInterval;

            function SearchData() {
               
                if ($("#CutEndDate").val() == "") {
                    HDialog.Info("请选择收款截止时间");
                    return;
                }

                $("#IsInitLoad").val(-1);
                $("#SearchDlg").dialog("close");
                //启动任务
                StartTask();
                //展示进度
                ShowProgress();
                //获取执行情况进度
                ProgressInterval = setInterval("TakeProgress()", 1000);
            }

            function StartTask() {
                //启动一个任务
                $.tool.DataPostNoLoading('CommFeesDebtsCutSearch_Detail', 'StartTask', $('#frmForm').serialize(),
                    function Init() {
                    },
                    function callback(_Data) {
                    },
                    function completeCallback() {
                    },
                    function errorCallback() {
                    });
            }

            //加载数据
            function LoadData() {
                //加载已经统计了的数据
                $("#TableContainer").datagrid({
                    url: '/HM/M_Main/HC/DataPostControl.aspx',
                    method: "post",
                    nowrap: false,
                    pageSize: top.ListPageSize,
                    pageList: top.ListPageList,
                    columns: column,
                    frozenColumns: frozenColumns,
                    fitColumns: true,
                    remoteSort: false,
                    singleSelect: true,
                    pagination: true,
                    width: "100%",
                    toolbar: toolbar,
                    sortOrder: "asc",
                    singleSelect: true,
                    selectOnCheck: false,
                    checkOnSelect: false,
                    rownumbers: true,
                    border: false,
                    view: myview,
                    showFooter: true,
                    onBeforeLoad: function (param) {
                        param = $.JQForm.GetParam("CommFeesDebtsCutSearch_Detail", "LoadData", "TableContainer", param);
                    },
                    onLoadSuccess: function (data) {
                        $("#SearchDlg").dialog("close");
                        //$.tool.MergeEasyUiGrid("TableContainer", "片区名称");
                        //$.tool.MergeEasyUiGrid("TableContainer", "项目名称");
                        //$.tool.MergeEasyUiGrid("TableContainer", "客户名称");
                        
                        //加载页脚
                        $('#TableContainer').datagrid('reloadFooter', [
                            {
                                项目名称: "<span style='color:red'>累计合计</span>",
                                欠费总额: "<span style='color:red'>0</span>",
                                前期欠费: "<span style='color:red'>0</span>",
                                本期欠费: "<span style='color:red'>0</span>",
                                欠费1: "<span style='color:red'>0</span>",
                                欠费2: "<span style='color:red'>0</span>",
                                欠费3: "<span style='color:red'>0</span>",
                                欠费4: "<span style='color:red'>0</span>",
                                欠费5: "<span style='color:red'>0</span>",
                                欠费6: "<span style='color:red'>0</span>"
                            }
                        ]);
                        if (document.getElementById('IsInitLoad').value != "1") {
                            $.tool.DataPostNoLoading('CommFeesDebtsCutSearch_Detail', "LoadSumData", $('#frmForm').serialize(),
                                function Init() {
                                    //加载页脚
                                    $('#TableContainer').datagrid('reloadFooter', [
                                        {
                                            项目名称: "<span style='color:red'>累计合计</span>",
                                            欠费总额: "<span style='color:red'>0</span>",
                                            前期欠费: "<span style='color:red'>0</span>",
                                            本期欠费: "<span style='color:red'>0</span>",
                                            欠费1: "<span style='color:red'>0</span>",
                                            欠费2: "<span style='color:red'>0</span>",
                                            欠费3: "<span style='color:red'>0</span>",
                                            欠费4: "<span style='color:red'>0</span>",
                                            欠费5: "<span style='color:red'>0</span>",
                                            欠费6: "<span style='color:red'>0</span>"
                                        }
                                    ]);
                                },
                                function callback(_Data) {
                                    var Data = eval("(" + _Data + ")"); //转换为json对象
                                    if (Data.rows.length > 0) {
                                        var obj = Data.rows[0];
                                        //加载页脚
                                        $('#TableContainer').datagrid('reloadFooter', [
                                            {
                                                项目名称: "<span style='color:red'>累计合计</span>",
                                                欠费总额: "<span style='color:red'>" + obj["欠费总额"] + "</span>",
                                                前期欠费: "<span style='color:red'>" + obj["前期欠费"] + "</span>",
                                                本期欠费: "<span style='color:red'>" + obj["本期欠费"] + "</span>",
                                                欠费1: "<span style='color:red'>" + obj["欠费1"] + "</span>",
                                                欠费2: "<span style='color:red'>" + obj["欠费2"] + "</span>",
                                                欠费3: "<span style='color:red'>" + obj["欠费3"] + "</span>",
                                                欠费4: "<span style='color:red'>" + obj["欠费4"] + "</span>",
                                                欠费5: "<span style='color:red'>" + obj["欠费5"] + "</span>",
                                                欠费6: "<span style='color:red'>" + obj["欠费6"] + "</span>"
                                            }
                                        ]);
                                    }
                                },
                                function completeCallback() {
                                },
                                function errorCallback() {
                                    //加载页脚
                                    $('#TableContainer').datagrid('reloadFooter', [
                                        {
                                            项目名称: "<span style='color:red'>累计合计</span>",
                                            欠费总额: "<span style='color:red'>0</span>",
                                            前期欠费: "<span style='color:red'>0</span>",
                                            本期欠费: "<span style='color:red'>0</span>",
                                            欠费1: "<span style='color:red'>0</span>",
                                            欠费2: "<span style='color:red'>0</span>",
                                            欠费3: "<span style='color:red'>0</span>",
                                            欠费4: "<span style='color:red'>0</span>",
                                            欠费5: "<span style='color:red'>0</span>",
                                            欠费6: "<span style='color:red'>0</span>"
                                        }
                                    ]);
                                });
                        }
                    },
                    rowStyler: function (index, row) {
                        return 'height:20px;';
                    }
                });
            }

            //重写DataGrid,支持更改页脚样式
            var myview = $.extend({}, $.fn.datagrid.defaults.view, {
                renderFooter: function (target, container, frozen) {
                    var opts = $.data(target, 'datagrid').options;
                    var rows = $.data(target, 'datagrid').footer || [];
                    var fields = $(target).datagrid('getColumnFields', frozen);
                    var table = ['<table class="datagrid-ftable" cellspacing="0" cellpadding="0" border="0"><tbody>'];

                    for (var i = 0; i < rows.length; i++) {
                        var styleValue = opts.rowStyler ? opts.rowStyler.call(target, i, rows[i]) : '';
                        var style = styleValue ? 'style="' + styleValue + '"' : '';
                        table.push('<tr class="datagrid-row" datagrid-row-index="' + i + '"' + style + '>');
                        table.push(this.renderRow.call(this, target, fields, frozen, i, rows[i]));
                        table.push('</tr>');
                    }
                    table.push('</tbody></table>');
                    $(container).html(table.join(''));
                }
            });

            //获取进度
            function TakeProgress() {
                $.tool.DataPostNoLoading('CommFeesDebtsCutSearch_Detail', 'TakeProgress', $('#frmForm').serialize(),
                    function Init() {
                    },
                    function callback(_Data) {
                        var Obj = JSON.parse(_Data);
                        if (_Data == '[]') {
                            LoadData();
                            CloseProgress();
                        }
                        else {
                            SetProgress(Obj);
                            if (Obj[0].Curr == '100') {
                                $('#hiIsSQLData').val('1');
                                LoadData();
                                CloseProgress();
                            }
                            else {
                            }
                        }
                    },
                    function completeCallback() {
                    },
                    function errorCallback() {
                    });
            }

            //显示进度
            function ShowProgress() {
                var h = parseInt($(window).height()) + parseInt($(window).scrollTop());
                var ht = parseInt($(window).scrollTop());
                $(".datagrid-mask").css({ display: "block", width: "100%", height: h });
                $(".datagrid-mask-msg").css({ display: "block", left: ($(document.body).outerWidth(true) - 350) / 2, top: ht + 240 });
            }
            //关闭进度
            function CloseProgress() {
                clearInterval(ProgressInterval);
                $(".datagrid-mask").hide();
                $(".datagrid-mask-msg").hide();
            }
            //设置进度
            function SetProgress(Obj) {
                $('#DivProgressBar').progressbar('setValue', Obj[0].Curr);
                $('#DivMsg').html(Obj[0].MessageInfo);
            }

            function formatNumberRgx(num) {
                var parts = num.toString().split(".");
                parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
                return parts.join(".");
            };
        </script>
    </form>
</body>
</html>
