<table class="form-table">
    <tbody>
        <tr>
            <th style="width:11.7%"><label for="periphery" style="margin-left: 30px">置业顾问:</label></th>
                <td>
                    <div id="consultantImg">
                    </div>
                    <button type="button" class="button action" data-toggle="modal" data-target="#myConsultant" id="recConsultantBt">
                        选择置业顾问
                    </button>
                </td>
        </tr>
    </tbody>
</table>

<script>
    (function($){
        {% if consultant %}
            var data = {{ consultant|json_encode()}};
            $.each(data,function(i,item){
            addConsultant(item);
        });
        {% endif %}
        $(document).ready(function(){
            //添加置业顾问

            init_modal_myConsultantList(addConsultant);

            $("#consultantImg").on("click",".consultantCancel",function(){
                $(this).parents("p").remove();
                if( $("#consultantImg > p").length == 0){
                    $("#subsidiaryId").remove();
                }
            });

        });
        //点击模态框中的置业顾问后显示
        function addConsultant(data){
            var row = $("<div>").addClass("row").css("margin-bottom","10px");
            var left = $("<div>").addClass("col-md-3");
            var img = $("<img>").attr({"src":data.imageUrl,"height":100,"width":100,"style":"margin-right:50px"});
            left.append(img);
            var mid = $("<div>").addClass("col-md-3");
            var label = $("<label>").append(data.name);
            mid.append(label);
            var right = $("<div>").addClass("col-md-3");
            var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("button action consultantCancel");
            right.append(cancel);
            var recommendConsultant = $("<input>").attr({"type":"hidden","name":"data[recConsultant][]","value":data.id});
            row.append(left).append(mid).append(right);
            var p = $("<p>").append(row).append(recommendConsultant);
            var subsidiaryId = $("<input>").attr({"type":"hidden","value":data.subsidiaryId,"id":"subsidiaryId"});
            if($("#consultantImg > p").length == 0){
                $("#consultantImg").append(p).append(subsidiaryId);
            }else{
                $("#consultantImg").append(p);
            }
            {% if (house_type == 1 or house_type == 2 or page == 'customer') %}
            controlCommand("consultantImg",1,1);
            {% endif %}
        }

    })(jQuery);

</script>