
<div class="row form-group">
    <div class="col-xs-4">
        <div class="input-group">
            <span class="input-group-addon color-red">微信标题</span>
            <input name="housename" id="housename" type="text" value="{{result.name}}" class="form-control" >
        </div>
    </div>
    {% if house_type == 0 %}
        <div class="col-xs-4">
            <div class="input-group">
                <span class="input-group-addon color-red">均价</span>
                <input name="average_price" id="average_price" type="text" value="{{result.average_price}}" class="form-control">
                <span class="input-group-addon">元</span>
            </div>
        </div>
    {% endif %}
</div>
<div class="row form-group">
    <div class="col-xs-6">
        <div class="input-group">
            <span class="input-group-addon">标签</span>
            <input type="button" class="btn btn-success" id="addTagBtn" value="添加" />
        </div>
        <div id="mark" class="input-group" style="margin-left: 68px;margin-top: 10px;">
        </div>
    </div>
</div>

<script>
    $(document).ready(function () {
        {% set markOld = function('SearchDao::searchFeatureOld', houseId, 0)|json_encode() %}
        {% if markOld %}
            var data = {{ markOld }};
        $.each(data, function (i, item) {
            addTag(item.tag_id, item.name);
        });
        {% endif %}
        var tagArray = [];
        $('#addTagBtn').click(function(){
            init_modal_addTag(0, function (id, value) {
                tagArray = [];
                $('input[name="data[houseTag][]"]').each(function (index, item) {
                    tagArray.push(Number($(item).val()));
                });
                if(tagArray.indexOf(Number(id)) == -1){
                    addTag(id, value);
                }else{
                    alert('不能重复选择标签');
                }
            });
        });
        $("#mark").on("click",".featureCancel",function(){
            var removeItem = $(this).parent().parent().find("input").val();
            $.grep(tagArray, function(value) {
                return value != removeItem;
            });
            $(this).parent().parent().parent().remove();
        });
    });
    function addTag(id, value) {
        var houseTag = $("<input>").attr({"type": "hidden", "name": "data[houseTag][]", "value": id});
        var cancel = $("<span>").attr("aria-hidden", "true").addClass("glyphicon glyphicon-remove featureCancel ").css({"top":"3px","margin-left":"10px"});
        var span = $("<span>").attr("style", "margin-right:5px").addClass("label label-info").append(value);
        var h = $("<h4>");
        h.append(span.append(cancel));
        var divCol = $("<div>").append(houseTag).append(h).addClass("col-md-2").attr("style", "margin-bottom:10px");
        $("#mark").append(divCol);
    }
</script>