{% block recConsultant %}
<div class="modal fade" id="myConsultant" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body" style="height: 300px;overflow: auto;">
                {% import "selectOrganization.html" as macro %}
                {{ macro.selectOrganization("consultant") }}
                <input type="text" placeholder="请出入置业顾问姓名搜索" id="consultantName" class="form-control">
                <button type="button" class="button action" id="searchConsult">搜索</button>
                <ul id="consultantList">
                </ul>
            </div>
        </div>
    </div>
</div>
<script>

    function close_modal_consultantList(){
        $("#myConsultant").modal('hide');
    }
    function init_modal_myConsultantList(callback){
        //添加置业顾问弹出层中搜索框的搜索内容
        $("#searchConsult").click(function(){
            $("#consultantList").find("li").remove();
            var consultantName = $("#consultantName").val();
            var organizationId = getOrganization();
            if(organizationId == -1 && consultantName == ""){
                alert("请选择部门")
            }
            searchConsultant(organizationId,consultantName);
        });

        $("#consultantList").on("click",".consultantImg",function(){
            callback($(this).data());
        });

    }

    function searchConsultant(organizationId,consultantName){
        $.ajax({
            type: "GET",
            url: "/tospur/wp-admin/admin-ajax.php",
            data: "action=searchConsultant&organizationId="+organizationId+"&consultantName="+consultantName,
            success:function(json){
                $("#consultantList").find("li").remove();
                if(json){
                    for(var i = 0; i <=json.length-1; i++){
                        var item =  json[i];
                        var name = item["name"];
                        var imgUrl = item["imageUrl"];
                        var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100,"style":"margin-right:50px"});
                        var li = $("<li>").attr("id",item["id"]).append(img).append(name).addClass("consultantImg").data(item);
                        $("#consultantList").append(li);
                    }
                }
            }
        });
    }
</script>
{% endblock %}