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

<!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>
    <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" />
    <link href="../css/framesearch.css" type="text/css" rel="stylesheet" />
    <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>
    <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>
    <script type="text/javascript" src="../Jscript-Ui/JQForm/JQForm.js"></script>
    <script src="../jscript/jquery.tool.new.js" type="text/javascript"></script>
    <script type="text/javascript" src="../jscript/export.js"></script>
    <script type="text/javascript" src="../jscript/DatePicker/WdatePicker.js"></script>
</head>
<body style="overflow: hidden">
    <form id="frmForm" runat="server">
        <input id="IsFirstLoad" type="hidden" name="IsFirstLoad" value="1" />
        <input id="hidCommId" type="hidden" name="hidCommId" value="" runat="server" />
        <input id="CommIds" type="hidden" name="CommIds" value="" 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: 300px; padding: 10px;">
            <table class="DialogTable" id="SearchTable">
                <tr>
                    <td class="TdTitle">项目</td>
                    <td class="TdContentSearch" colspan="3">
                        <textarea name="CommNames" id="CommNames" style="width: 91.7%; height: 60px; border: 1px solid #cccccc; font-size: 12px; padding: 2px; resize: none;" runat="server"></textarea>
                    </td>
                </tr>
                <tr>
                    <td colspan="4" align="center"><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick=" JavaScript:ExcuteStatistics(); ">统计</a></td>
                </tr>
            </table>
        </div>

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

        <script src="../jscript/CloseAjaxCache.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                $("#CommNames").click(function () {
                    if ($("#hidCommId").val() != '' && $("#hidCommId").val() != '0') {
                        return;
                    }
                    HDialog.Open(700, 400, '../DialogNew/SelComm.aspx?IsCheck=1', "选择管理项目", false, function callback(_Data) {
                        var arrRet = JSON.parse(_Data);
                        $("#CommIds").val(arrRet.id);
                        $("#CommNames").val(arrRet.name);
                    });
                });

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

                LoadList();
            });

            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.open('./CommCustomerDataDetail_ToExcle.aspx?commIds=' + $("#CommIds").val());*/

                            // 创建隐藏表单
                            var form = $('<form></form>')
                                .attr('action', 'CommCustomerDataDetail_ToExcle.aspx')
                                .attr('method', 'post');

                            // 添加参数
                            $('<input>')
                                .attr('type', 'hidden')
                                .attr('name', 'strCommIDs')
                                .val($("#CommIds").val())
                                .appendTo(form);

                            // 提交表单并立即移除
                            form.appendTo('body').submit().remove();

                            //$.ajax({
                            //    type: "post",
                            //    url: "CommCustomerDataDetail_ToExcle.aspx",
                            //    data: { strCommIDs: $("#CommIds").val() },
                            //    //contentType: "application/json; charset=utf-8",
                            //    //dataType: "json",
                            //    xhr: function () {
                            //        var xhr = new window.XMLHttpRequest();
                            //        xhr.responseType = 'blob';
                            //        return xhr;
                            //    },
                            //    success: function (blob, status, xhr) {
                            //        // blob 就是文件内容
                            //        var link = document.createElement('a');
                            //        link.href = window.URL.createObjectURL(blob);
                            //        link.download = 'CustomerData.xlsx';
                            //        link.click();
                            //        window.URL.revokeObjectURL(link.href);
                            //    },
                            //    error: function (xhr, status, err) {
                            //        console.error('下载失败', err);
                            //    }
                            //});
                        }
                    }
                }
            ];

            var columns = [
                [
                    { field: 'OrganName', title: '区域', align: 'left', halign: 'center', sortable: true, width: 160, rowspan: 2 },
                    { field: 'CommName', title: '项目名称', align: 'left', halign: 'center', sortable: true, width: 200, rowspan: 2 },
                    { field: 'PromotionName', title: '项目推广名', align: 'left', halign: 'center', sortable: true, width: 200, rowspan: 2 },
                    { field: 'CommSourceName', title: '项目来源', align: 'center', sortable: true, width: 100, rowspan: 2 },
                    { title: '房屋信息', align: 'center', colspan: 14 },
                    { title: '业主（产权人）信息', align: 'center', colspan: 22 },
                    { title: '常住人员信息', align: 'center', colspan: 19 }
                ],
                [
                    // 房屋信息
                    { field: 'RegionName', title: '组团区域', align: 'left', halign: 'center', sortable: true, width: 150 },
                    { field: 'BuildName', title: '楼宇名称   ', align: 'left', halign: 'center', sortable: true, width: 100 },
                    { field: 'UnitName', title: '单元', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'RoomSign', title: '房屋编号', align: 'left', halign: 'center', sortable: true, width: 100 },
                    { field: 'LiveStateName', title: '入住状态', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'RoomStateName', title: '房屋状态', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'RoomTypeName', title: '房屋类型', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'PropertyUseNames', title: '使用性质', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'RoomOperation', title: '房屋业态', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'ProjectProperty', title: '项目属性', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'GetHouseDate', title: '集中交房时间（首日）', align: 'center', halign: 'center', sortable: true, width: 150 },
                    { field: 'ActualSubDate', title: '实际交房时间', align: 'center', halign: 'center', sortable: true, width: 150 },
                    { field: 'ParkNames', title: '车位编号', align: 'left', halign: 'center', sortable: true, width: 300 },
                    { field: 'CarSigns', title: '车牌号', align: 'left', halign: 'center', sortable: true, width: 300 },

                    // 业主（产权人）信息
                    { field: 'CustName', title: '业主名称', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustSex', title: '性别', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustNationality', title: '国籍', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustPaperName', title: '证件类型', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustPaperCode', title: '证件号码', align: 'center', halign: 'center', sortable: true, width: 150 },
                    { field: 'CustMobilePhone', title: '移动电话', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustOtherPhone', title: '其他电话', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustAddress', title: '联系地址', align: 'left', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustBirthday', title: '生日', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustWorkIndustry', title: '工作行业', align: 'left', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustWorkUnit', title: '工作单位', align: 'left', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustCustomerRating', title: '客户分级', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustIsVip', title: '是否为VIP客户', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustSpecialCustomerName', title: '特殊客户维护', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustIsCommittee', title: '是否为业委会成员', align: 'center', halign: 'center', sortable: true, width: 100 },
                    /*{ field: 'CustIsEnterpriseWeChat', title: '是否添加企业微信', align: 'center', halign: 'center', sortable: true, width: 100 },*/

                    { field: 'CustIsChildren', title: '是否有12周岁以内的孩子', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustSumComplaintVolume', title: '累计客诉量', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustComplaintVolume', title: '近半年客诉量', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustSurveyRating', title: '最近一次满意度调研评分', align: 'center', halign: 'center', sortable: true, width: 100 },

                    { field: 'CustLikes', title: '爱好', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustPet', title: '宠物', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'CustMemo', title: '备注', align: 'left', halign: 'center', sortable: true, width: 100 },

                    // 常住人员信息
                    { field: 'HoldName', title: '常住人姓名', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'HoldRelationshipName', title: '与户主关系', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'HoldSex', title: '性别', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'HoldNationality', title: '国籍', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'HoldPaperName', title: '证件类型', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'HoldPaperCode', title: '证件号码', align: 'center', halign: 'center', sortable: true, width: 150 },
                    { field: 'HoldMobilePhone', title: '移动电话', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'HoldOtherPhone', title: '其他电话', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'HoldAddress', title: '联系地址', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'HoldBirthday', title: '生日', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'HoldWorkIndustry', title: '工作行业', align: 'left', halign: 'center', sortable: true, width: 100 },
                    { field: 'HoldWorkUnit', title: '工作单位', align: 'left', halign: 'center', sortable: true, width: 100 },
                    //{ field: 'HoldCustomerRating', title: '客户分级', align: 'center', halign: 'center', sortable: true, width: 100 },
                    //{ field: 'HoldSpecialCustomerName', title: '特殊客户维护', align: 'center', halign: 'center', sortable: true, width: 100 },
                    /*{ field: 'HoldIsEnterpriseWeChat', title: '是否添加企业微信', align: 'center', halign: 'center', sortable: true, width: 100 },*/
                    { field: 'HoldLikes', title: '爱好', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'HoldPet', title: '宠物', align: 'center', halign: 'center', sortable: true, width: 100 },
                    /*{ field: 'HoldIsCommittee', title: '是否为业委会成员', align: 'center', halign: 'center', sortable: true, width: 100 },*/
                    { field: 'HoldIsPayer', title: '是否为缴费人', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'HoldPaymentHabits', title: '缴费习惯', align: 'center', halign: 'center', sortable: true, width: 100 },

                    {
                        field: 'LastPayment', title: '最近一次缴纳物业费时间', align: 'center', halign: 'center', sortable: true, width: 100 },

                    { field: 'HoldNoPayReasonRemark', title: '未缴费原因备注', align: 'center', halign: 'center', sortable: true, width: 100 },
                    { field: 'HoldMemo', title: '备注', align: 'left', halign: 'center', sortable: true, width: 100 },
                ]
            ];

            function LoadList() {
                $("#TableContainer").datagrid({
                    url: '/HM/M_Main/HC/DataPostControl.aspx',
                    method: "post",
                    title: '',
                    nowrap: false,
                    pageSize: 50,
                    pageList: [50, 100, 200],
                    columns: columns,
                    fitColumns: false,
                    remoteSort: false,
                    pagination: true,
                    width: "100%",
                    toolbar: toolbar,
                    sortOrder: "asc",
                    singleSelect: true,
                    selectOnCheck: false,
                    checkOnSelect: false,
                    rownumbers: true,
                    border: false,
                    sortOrder: "asc",
                    onBeforeLoad: function (param) {
                        param = $.JQForm.GetParam("CommCustomerDataDetail", "LoadData", "TableContainer", param);
                    },
                    onLoadSuccess: function (data) { }
                });
            }

            var ProgressInterval;

            function ExcuteStatistics() {
                if ($("#CommIds").val() == '') {
                    HDialog.Info("请选择项目,此项不能为空!");
                    return;
                }

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

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

            //获取进度
            function TakeProgress() {
                $.tool.DataPostNoLoading('CommCustomerDataDetail', 'TakeProgress', $('#frmForm').serialize(),
                    function Init() { },
                    function callback(_Data) {
                        var obj = JSON.parse(_Data);
                        if (obj.code == 200) {
                            if (obj.data == null || obj.data.length == 0) {
                                LoadList();
                                CloseProgress();
                            } else {
                                SetProgress(obj.data);
                                if (obj.data[0].Curr == 100) {
                                    $("#IsFirstLoad").val(0);
                                    LoadList();
                                    CloseProgress();
                                }
                            }
                        } else {
                            LoadList();
                            CloseProgress();
                        }
                    },
                    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) {
                var i = parseInt(Obj[0].Curr);
                $('#DivProgressBar').progressbar('setValue', Obj[0].Curr);
                $('#DivMsg').html(Obj[0].MessageInfo);
            }
        </script>
    </form>
</body>
</html>
