
<div class="row form-group">
    <div class="col-xs-4">
        <label for="housename" class="col-xs-5 control-label" >微信标题:</label>
        <p class="col-xs-7">
            <input name="housename" id="housename" type="text" value="{{result.name}}" class="form-control" >
        </p>
    </div>
    {% if house_type == 0 %}
        <div class="col-xs-4">
            <label for="average_price" class="col-xs-5 control-label">均价:</label>
            <p class="col-xs-6">
                <input name="average_price" id="average_price" type="text" value="{{result.average_price}}" class="form-control">
            </p>
            <p class="col-xs-1" style="margin-top: 10px">
                &nbsp;元
            </p>
        </div>
    {% endif %}
</div>
<table class="form-table">
    <tbody >
    <tr>
        <th style="width:11.9%"><label for="mark" style="margin-left: 42px">标签:</label></th>
        <td>
            <div id="mark" class="row">
            </div>
            <button type="button" class="button action" id="addTagBtn">
                标签
            </button>
        </td>
    </tr>
    </tbody>
</table>

<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('不能重复选择标签');
                }
            });
        });
    });
    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 ");
        var span = $("<span>").attr("style", "margin-right:5px").append(value);
        var divCol = $("<div>").append(houseTag).append(span).append(cancel).addClass("col-md-3").attr("style", "margin-bottom:10px");
        $("#mark").append(divCol);
    }
</script>