{% 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;">
                <select id="consultCity">
                    <option value="-1"> 城市</option>
                    {% for item in city %}
                    <option value="{{ item.id }}">{{ item.value }}</option>
                    {% endfor %}
                </select>
                <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){


        $("#myConsultant").on("shown.bs.modal",function(){
            setConsultantCity();
        });
//        $("#myConsultant").find("select").change(function(){
//            searchConsultant(consulCityId,consultantName);
//        });

        //添加置业顾问弹出层中搜索框的搜索内容
        $("#searchConsult").click(function(){
            $("#consultantList").find("li").remove();
            var consulCityId = $("#consultCity").val();
            var consultantName = $("#consultantName").val();
            searchConsultant(consulCityId,consultantName);
        });

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

    }
    function setConsultantCity(){
        var city = $("#consultCity");
        var consultantName =$("#consultantName").val();
        if($("#baseCity").length>0){
            var consultCity = $("#baseCity").val();
            city.val(consultCity);
            searchConsultant(consultCity,consultantName);
        }else{
            var consultCity = city.val();
        }
        city.change(function(){
            var consultCity = city.val();
            searchConsultant(consultCity,consultantName);
        })

    }
    function searchConsultant(consulCityId,consultantName){
        $.ajax({
            type: "GET",
            url: "/tospur/wp-admin/admin-ajax.php",
            data: "action=searchConsultant&consulCityId="+consulCityId+"&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 %}