<!DOCTYPE HTML>
<html>
<head>
    {% set title = houseId?"修改新房房源":"添加新房房源" %}
    <meta charset="utf-8">
    <title>{{title}}</title>
    <style>
        .form-horizontal label.control-label{
            text-align: left;
            float: left;
            margin-right: 10px;
            width: 65px;
        }
        .form-horizontal span select{
            display: inline;
        }
    </style>
</head>
<body>
<script>
    var i = 0
</script>
<h2 class="title">{{title}}</h2>
<div class="alert alert-danger" role="alert" id="messageBox1" style="display:none;">

</div>
<form action="" method="POST" enctype="multipart/form-data" id="newHouse" class="form-horizontal">
    <div class="row">
        <div class="col-xs-10">
            <!-- Nav tabs -->
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active">
                    <a href="#info" aria-controls="info" role="tab" data-toggle="tab">基本信息</a>
                </li>
                <li role="presentation">
                    <a href="#mainHouse" aria-controls="mainHouse" role="tab" data-toggle="tab">其他信息</a>
                </li>
                <li role="presentation">
                    <a href="#customer_tracking" aria-controls="customer_tracking" role="tab" data-toggle="tab">房源跟进</a>
                </li>
            </ul>
            <!-- Tab panes -->
            <div class="tab-content">

                    <div role="tabpanel" class="tab-pane active" id="info">
                        {% if (house_type==1 or house_type == 2)%}
                            {% include 'houseInfo.html' %}
                        {% else %}
                            {% include 'newHouseInfo.html' %}
                        {% endif %}

                    </div>
                <div role="tabpanel" class="tab-pane" id="mainHouse">
                    <br/>
                    {% include 'mainHouse.html' %}
                    <br/>
                    {% include 'photos.html' %}
                    <br/>
                    {% include 'addRecHouse.html' %}
                    <br/>
                    {% include 'addConsultant.html' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="customer_tracking">
                    {% include 'save_customer_tracking.html' %}
                    {% import "macro.html" as macro %}
                    {{ macro.customer_tracking_list(houseId, 1) }}
                </div>
            </div>
            <input type="text" name="type" value="1" hidden="hidden">
            {% if houseId %}
            <input type="text" name="houseId" value="{{houseId}}" hidden="hidden">
            {% endif %}
        </div>
        <div  class="col-xs-2">
            <div  class="row" style="position: fixed;">
                {% if canEdit %}
                    {% if houseId %}
                        {% if canApproval %}
                            {% if result.approval != -2 %}
                                <select  name="status">
                                    <option value="{{result.approval}}">通过</option>
                                    <option value="-2">退回</option>
                                </select>
                            {% else %}
                                <input type="hidden" name="status" value="{{result.status}}">
                            {% endif %}
                        {% else %}
                            <select  name="status" >
                                {% for item in status %}
                                    <option {{ item.id == result.status?"selected":"" }} value={{item.id}}>{{item.value}}</option>
                                {% endfor %}
                            </select>
                        {% endif %}
                    {% endif %}
                    <input type="submit" id="submit" class="button action">
                {% endif %}
            </div>

        </div>
    </div>
</form>

<!-- Modal -->
<!-- 推荐房源弹出层 -->
{% include 'recommendHouse.html' %}
{{ block('recommendHouse') }}
<!-- 置业顾问弹出层 -->
{% include 'recConsultant.html' %}
{{ block('recConsultant') }}
<!-- 特色房源弹出层 -->
{% include 'addTag.html' %}
{{ block('addTag') }}

<script>
    (function($){
        $(document).ready(function(){
            $("#baseCity").change(function(){
                setCity("baseCity","baseAreaId","basePlateId");
            });
            $("#baseAreaId").change(function(){
                setArea("baseCity","baseAreaId","basePlateId");
            });
            {% if result is not null %}
            var json = {"decoration":"{{result.decoration}}"};
            revertOption(json);
            {% endif %}
            var rulesJson = {
                housename:'required',
                average_price:'required',
                mark:'required',
                community_name:'required',
                address:'required',
                covered_area:'required',
                property_money:'required',
                latest_news:'required',
                overview:'required',
                baseCity:{
                    citySelectcheck: true
                },
                baseAreaId:{
                    areaSelectcheck: true
                },
                basePlateId:{
                    plateSelectcheck: true
                },
                baseRoom:{
                    roomSelectcheck:true
                }

            };
            {% if not canApproval %}
                rulesJson.description = 'required';
            {% endif %}


            $('#newHouse').validate({
                onkeyup: false,
                onfocusout: false,
                ignore: [],
                errorClass: "my-error-class",
                rules: rulesJson,
                messages: {
                    housename:'请输入楼盘名称',
                    community_name:'请输入小区名称',
                    mark:'请输入标签',
                    average_price:'请输入均价',
                    address:'请输入地址',
                    description:'请输入跟进说明',
                    covered_area:'请输入建筑面积',
                    property_money:'请输入物业费',
                    latest_news:'请输入最新动态',
                    overview:'请输入楼盘概述'
                },
                errorContainer: "#messageBox1",
                errorLabelContainer: "#messageBox1",
                submitHandler: function (form) {
                    if($("#photosTbody > tr").length == 0){
                        alert("请选择房源相册");
                        return false;
                    }
                    if($("#consultantImg > p").length == 0){
                        alert("请选择置业顾问");
                        return false;
                    }
                    form.submit();
                }
            });
            jQuery.validator.addMethod('citySelectcheck', function (value) {
                return (value != '-1');
            },"请选择城市");
            jQuery.validator.addMethod('areaSelectcheck', function (value) {
                return (value != '-1');
            },"请选择区域");
            jQuery.validator.addMethod('plateSelectcheck', function (value) {
                return (value != '-1');
            },"请选择板块");
            jQuery.validator.addMethod('roomSelectcheck', function (value) {
                return (value != '-1');
            },"请选择建筑类型");

        });
    })(jQuery);

</script>

</body>
</html>