<table class="form-table">
    <tbody>
        <tr>
            <th style="width: 63px;box-sizing: content-box;"
                {% if (page == 'view_house' or page == 'sale_detail') %}
                    class=""
                {% elseif (house_type == 0 or house_type == 1 or house_type == 2 or page == 'customer') %}
                    class="color-red"
                {% endif %}
            >
                <label>置业顾问:</label>
            </th>
            <td>
                <div id="consultantImg">
                </div>
                {% if role == 'jl' %}
                <button type="button" class="btn btn-success" data-toggle="modal" data-target="#myConsultant" id="recConsultantBt">
                    选择置业顾问
                </button>
                {% endif %}
            </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).parent().parent().remove();
                if( $("#consultantImg > div").length == 0){
                    $("#subsidiaryId").remove();
                }
            });

        });
        //点击模态框中的置业顾问后显示
        function addConsultant(data){
            var div = $("<div>").css({"display":"inline-block","margin-right":"10px"});
            var p1 = $("<p>");
            var img = $("<img>").attr({"src":data.imageUrl,"height":100,"width":100});
            p1.append(img);
            div.append(p1);
            var p2 = $("<p>").css({"margin-top":"3px"});
            var label = $("<label>").html(data.name);
            p2.append(label);
            if ('{{role}}' == 'jl') {
                var cancel = $("<input>").attr({
                    "type": "button",
                    "value": "删除"
                }).addClass("btn btn-info btn-xs consultantCancel").css({"float":"right"});
                p2.append(cancel);
            }
            div.append(p2);
            var recommendConsultant = $("<input>").attr({"type":"hidden","name":"data[recConsultant][]","value":data.id});
            div.append(recommendConsultant);
            var subsidiaryId = $("<input>").attr({"type":"hidden","value":data.subsidiaryId,"id":"subsidiaryId"});
            $("#consultantImg").append(div);
            if($("#consultantImg > div").length == 0){
                $("#consultantImg").append(subsidiaryId);
            }
            {% if (house_type == 1 or house_type == 2 or page == 'customer' or page == 'view_house') %}
            controlCommand("consultantImg",1,1);
            {% endif %}
        }

    })(jQuery);

</script>