<%@include file="/WEB-INF/common/layouts/common.jsp" %>
<%@ page language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <title>批量转移客户</title>
</head>
<body>
<link rel="stylesheet" type="text/css" href="${static_common}/jquery-ui/jquery-ui.min.css"/>
<div id="loadingDialog" style="display: none;">
    <div class="progress" id="prog_out">
        <div class="bar" style="width: 0%;" id="prog_in"></div>
    </div>
    已导入<span id="complete">0</span>条
</div>
<div id="confirmDialog" style="display: none" title="">

</div>
<link rel="stylesheet" href="${static_common}/jquery.qtip.custom/jquery.qtip.min.css" type="text/css">
<script href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/i18n/defaults-*.min.js"></script>
<script src="${static_common}/jquery-ui/jquery-ui.min.js" type="text/javascript"></script>
<script src="${static_common }/script/jquery/bootstrap-select.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css">
<!-- 面包屑 begin -->
<div class="row-fluid">
    <div class="span12">
        <ul class="breadcrumb">
            <li><a href="/house365-hgs-web/">首页</a>
                <span class="divider" style="color:#26a0da;font-weight:bold;"> >批量转移客户 </span>
            </li>
        </ul>
    </div>
    <input type="hidden" id="markIds" name="markIds" value=""/>
</div>

<form id="filterForm" class="form-inline filterForm" action="${ctx}/transfercustomer/count" method="post"
      style="margin: 11px 0 6px 0;position: relative"><div style="width: 100%;background-color: #E4E4E4">筛选客户</div>
    <span style="margin-left: 100px;display: inline-block;position: absolute;bottom: 25px;left:326px;">
        <button type="button" class="btn btn-primary btn-sm" onclick="checkForm()">搜索</button>
    </span>
    <div class="row-fluid" style="border-style: solid;border-width: thin;border-color: #d5d5d5;padding: 20px;margin-bottom: 20px;line-height: 43px;">
        <div class="span12">
            <div class="row-fluid">
                <div class="span6 control-group">
                    <label class="control-label">置业顾问<span style="color: red;">*</span>:</label>
                    <div class="controls" style="width: 78%">
                        <input type="text" id="chooseManagerName" class="span4"/>
                        <input type="hidden" id="managerId"
                               name="managerId" class="required span4"
                               value="${managerName}"/>
                    </div>
                    <div style="display: flex;align-items: center;position: relative;top: -6px;left: 20px;">
                            购房意向：<select style="width: 6rem" name="buyIntention" id="buyIntention">
                            <option value="all">
                                全部
                            </option>
                            <option value=""
                                    <c:if test="${'' eq param['search_EQ_buyIntention']}">selected="selected"</c:if>>
                                待定
                            </option>
                            <option value="1"
                                    <c:if test="${'1' eq param['search_EQ_buyIntention']}">selected="selected"</c:if>>
                                A
                            </option>
                            <option value="2"
                                    <c:if test="${'2' eq param['search_EQ_buyIntention']}">selected="selected"</c:if>>
                                B
                            </option>
                            <option value="3"
                                    <c:if test="${'3' eq param['search_EQ_buyIntention']}">selected="selected"</c:if>>
                                C
                            </option>
                            <option value="4"
                                    <c:if test="${'4' eq param['search_EQ_buyIntention']}">selected="selected"</c:if>>
                                D
                            </option>
                        </select>&nbsp;&nbsp;&nbsp;&nbsp;
                            客户状态：<select style="width: 6rem" name="projectStatus" id="projectStatus">
                            <option value="">
                                全部
                            </option>
                            <option value="1"
                                    <c:if test="${'1' eq param['search_EQ_projectStatus']}">selected="selected"</c:if>>
                                约看
                            </option>
                            <option value="2"
                                    <c:if test="${'2' eq param['search_EQ_projectStatus']}">selected="selected"</c:if>>
                                到访
                            </option>
                            <option value="3"
                                    <c:if test="${'3' eq param['search_EQ_projectStatus']}">selected="selected"</c:if>>
                                认筹
                            </option>
                            <option value="4"
                                    <c:if test="${'4' eq param['search_EQ_projectStatus']}">selected="selected"</c:if>>
                                认购
                            </option>
                            <option value="5"
                                    <c:if test="${'5' eq param['search_EQ_projectStatus']}">selected="selected"</c:if>>
                                签约
                            </option>
                            <option value="6"
                                    <c:if test="${'6' eq param['search_EQ_projectStatus']}">selected="selected"</c:if>>
                                退房
                            </option>
                        </select>&nbsp;&nbsp;&nbsp;&nbsp;
                    </div>
                </div>

            </div>




            回访记录：<input type="text" id="callbackLog" style="border: 1px solid #d5d5d5;width: 8rem" name="callbackLog" value="${param['callbackLog']}"
                        class="m-wrap small" placeholder="回访记录">
            </select>&nbsp;&nbsp;&nbsp;
            是否星标：<select style="width: 6rem" name="isStar" id="isStar">
            <option value=""
                    <c:if test="${'' eq param['search_EQ_isStar']}">selected="selected"</c:if>>
                全部
            </option>
            <option value="1"
                    <c:if test="${'1' eq param['search_EQ_isStar']}">selected="selected"</c:if>>
                是
            </option>
            <option value="0"
                    <c:if test="${'0' eq param['search_EQ_isStar']}">selected="selected"</c:if>>
                否
            </option>
            </select>
        </div>
    </div>
</form>

<form id="dealForm" class="form-inline filterForm" action="" method="post" style="margin: 11px 0 6px 0;position: relative">
    <div style="width: 100%">
    <div style="width: 100%;background-color: #E4E4E4">处理客户</div>
    <div id="dealDiv" class="row-fluid" style="display: none"><br/>
        <div class="span12">
            共找到<span id="countnum"></span>条客户,可以选择以下两项批量操作

            <br/><br/>
        </div>
        <div class="span12">
            <span style="margin-left: 10px;">
                <button type="button" class="btn btn-primary btn-sm"
                    onclick="transfer()">转移客户</button>
            </span>
            <span style="margin-left: 10px;">
                <button type="button" class="btn btn-primary btn-sm"
                    onclick="remove2Sea()">移入公海</button>
            </span>
        </div>
    </div>
    </div>
</form>
<%--<script language="javascript" type="text/javascript"--%>
        <%--src="${ctx}/resources/script/My97DatePicker/WdatePicker.js"></script>--%>
<%--<script language="javascript" type="text/javascript"--%>
        <%--src="${ctx}/resources/jquery.qtip.custom/jquery.qtip.min.js"></script>--%>
<script type="text/javascript">
    var managername = "${managername}" == "" ? "请选择安家顾问" : "${managername}";
    var contextName = $("#managerName").val();
    var count = 0;
    var $form = $("#filterForm");
    $(function () {
        // 加载直销顾问
        $("#chooseManagerName").select2({
            placeholder: contextName,
            // 输入几个字符开始联想
            minimumInputLength: 1,
            // 最大返回记录数
            minimumResultsForSearch: 10,
            maximumSelectionLength: 1,
            minimumSelectionLength: 1,
            containerCssClass: "chosen, chosen-with-diselect",
            query: function (query) {
                $.ajax({
                    timeout: 1000,
                    url: "${ctx}/user/getManagerByPid",
                    type: "GET",
                    data: {
                        managername: query.term,
                    },
                    dataType: "json",
                    success: function (data, status) {
                        var pageData = {
                            results: []
                        };
                        $.each(data.data.list, function (i, item) {
                            pageData.results.push({
                                id: item.id,
                                text: item.realName
                            });
                        });
                        query.callback(pageData);
                    },
                    error: function () {
                        var pageData = {
                            results: []
                        };
                        query.callback(pageData);
                    }
                });
            }
        });

        $.ajaxSetup({
            async: false
        });

        $("#chooseManagerName").change(function () {
            var chooseHouse = $(this).val();
            if (chooseHouse) {
                var houses = chooseHouse.split("@#");
                var managerName = houses[0];
//                var buildingId = houses[1];
                $("#managerId").val(managerName);
            }
        });
    });



    function checkForm(){
        var managerId = $("#managerId").val();
        var buyIntention = $("#buyIntention").val();
        var projectStatus = $("#projectStatus").val();
        var callbackLog = $("#callbackLog").val();
        var isStar = $("#isStar").val();
        if(!managerId){
            alert("请先选择安家顾问");
            return false;
        }
//        $('#filterForm').submit();
        $.ajax({
            url: "${ctx}/transfercustomer/count",
            type: "GET",
            data: {
                managerId: managerId,
                buyIntention: buyIntention,
                projectStatus: projectStatus,
                callbackLog: callbackLog,
                isStar: isStar,
            },
            dataType: "json",
            success: function (data) {
                var form = document.getElementById("dealDiv");
                form.style.display = "block";
                var countnum = document.getElementById("countnum");
                countnum.innerText = data;
                count = data;
            },
            error: function () {
                alert("系统异常,请联系管理员");
            }
        });

    }

    function remove2Sea() {

        if (count == 0) {
            alert("当前搜索客户为0!");
            return false;
        }
        if (count > 500) {
            alert("查询数据为"+count+"条,系统本次支持操作500条客户");
            count = 500;
        }
        var managerId = $("#managerId").val();
        var buyIntention = $("#buyIntention").val();
        var projectStatus = $("#projectStatus").val();
        var callbackLog = $("#callbackLog").val();
        var isStar = $("#isStar").val();
        //
        House365Util.createModal("提示", "是否将"+count+"条客户全部移入公海？", function () {
            doRemove(managerId,buyIntention,projectStatus,callbackLog,isStar);

        });
        $(".modal").css("width", "560px");
    }


    function transfer() {

        if (count == 0) {
            alert("当前搜索客户为0,无需转移!");
            return false;
        }
        if (count > 500) {
            alert("查询数据为"+count+"条,系统本次支持操作500条客户");
            count = 500;
        }
        var managerId = $("#managerId").val();
        var buyIntention = $("#buyIntention").val();
        var projectStatus = $("#projectStatus").val();
        var callbackLog = $("#callbackLog").val();
        var isStar = $("#isStar").val();
        //选择弹框
        House365Util.createRemoteModal("客户转移", "${ctx}/customer/assignManager?multyassign=1&customerCount="+count, null, function () {
            var userIds = "";
            if ($("#custom-headers").find("option:selected").length == 0) {
                alert("分派人员不可为空!");
                return false;
            }

            $("#custom-headers").find("option:selected").each(function () {
                userIds = userIds + $(this).val() + ",";
            });
            doImport(userIds, managerId, buyIntention, projectStatus, callbackLog, isStar);
            <%--$.ajax({--%>
                <%--url: '${ctx}/transfercustomer/assign',--%>
                <%--data: {"userIds": userIds, "managerId": managerId,"buyIntention": buyIntention, "projectStatus": projectStatus,"callbackLog": callbackLog, "isStar": isStar},--%>
                <%--type: "GET",--%>
                <%--success: function (data) {--%>
                    <%--if (data.result == '1') {--%>
<%--//                        window.location.reload();--%>
                        <%--alert("111");--%>
                    <%--} else {--%>
                        <%--alert("操作失败，" + data.msg);--%>
                        <%--alert("111");--%>
                    <%--}--%>
                <%--}--%>
            <%--});--%>

            return true;
        });
        $(".modal").css("width", "560px");
    }


    function doImport(userIds, managerId, buyIntention, projectStatus, callbackLog, isStar) {

        $("#loadingDialog").dialog({
            dialogClass: "no-close",
            autoOpen: false,
            width: 1000,
            modal: true,
            show: {
                effect: "blind",
                duration: 100
            },
            hide: {
                effect: "explode",
                duration: 100
            }
        }).dialog("open");

        var sitv = setInterval(function () {
            var prog_url = "${ctx}/transfercustomer/getLoadData?count="+count+"&managerId="+managerId;
            $.getJSON(prog_url, function (res) {
                $('#prog_in').width(res.entity + '%'); //改变进度条进度，注意这里是内层的div，res是后台返回的进度
                $('#complete').text(res.total);
                if (res.entity == 100) {
                    $("#loadingDialog").dialog("close");
                    clearInterval(sitv);
//                    var span = document.getElementById("ui-id-2");
//                    span.innerText="提示";
                    $("#confirmDialog").text("客户转移完毕！");
                    $("#confirmDialog").dialog({
                        dialogClass: "no-close",
                        autoOpen: false,
                        modal: true,
                        show: {
                            effect: "blind",
                            duration: 100
                        },
                        hide: {
                            effect: "explode",
                            duration: 100
                        },
                        buttons: [
                            {
                                text: "确认",
                                click: function () {
                                    $(this).dialog("close");
                                    window.location.reload();
                                    return true;
                                }
                            }
                        ]
                    }).dialog("open");
                }
            });
        }, 900);

        $.ajax({
            url: "${ctx}/transfercustomer/turn",
            type: "POST",
            data: {
                userIds:userIds,
                managerId: managerId,
                buyIntention: buyIntention,
                projectStatus: projectStatus,
                callbackLog: callbackLog,
                isStar: isStar,
                count: count
            },
            async: true,
            success: function (response) {
            }
        });
    }


    function doRemove(managerId, buyIntention, projectStatus, callbackLog, isStar) {

        $("#loadingDialog").dialog({
            dialogClass: "no-close",
            autoOpen: false,
            width: 1000,
            modal: true,
            show: {
                effect: "blind",
                duration: 100
            },
            hide: {
                effect: "explode",
                duration: 100
            }
        }).dialog("open");

        var sitv2 = setInterval(function () {
            var prog_url = "${ctx}/transfercustomer/getRemoveData?count="+count+"&managerId="+managerId;
            $.getJSON(prog_url, function (res) {
                $('#prog_in').width(res.entity + '%'); //改变进度条进度，注意这里是内层的div，res是后台返回的进度
                $('#complete').text(res.total);
                if (res.entity == 100) {
                    $("#loadingDialog").dialog("close");
                    clearInterval(sitv2);
                    $("#confirmDialog").text("转移公海完毕！");
                    $("#confirmDialog").dialog({
                        dialogClass: "no-close",
                        autoOpen: false,
                        modal: true,
                        show: {
                            effect: "blind",
                            duration: 100
                        },
                        hide: {
                            effect: "explode",
                            duration: 100
                        },
                        buttons: [
                            {
                                text: "确认",
                                click: function () {
                                    $(this).dialog("close");
                                    window.location.reload();
                                    return true;
                                }
                            }
                        ]
                    }).dialog("open");
                }
            });
        }, 500);

        $.ajax({
            url: '${ctx}/transfercustomer/batchRemove',
            data: {
                "managerId": managerId,
                "buyIntention": buyIntention,
                "projectStatus": projectStatus,
                "callbackLog": callbackLog,
                "isStar": isStar,
                "count": count
            },
            type: "POST",
            async: true,
            success: function (data) {
                if (data.result == '1') {
                    setTimeout("window.location.reload()", 1000);
                } else {
                    alert("操作失败，" + data.msg);
                }
            }
        });
    }
</script>



</body>
</html>
