{% import "macro.html" as macro %}
<!DOCTYPE HTML>
<html>
<head>
    {% set title = houseId?"修改客户":"添加客户" %}
    <meta charset="utf-8">
    <title>{{ title }}</title>
    <script>
        var i = 0;
    </script>
</head>
<body>
<h2 class="title">{{ title }}</h2>
<div class="alert alert-danger" role="alert" id="error" style="display:none;"></div>
<form action="" method="POST" enctype="multipart/form-data" id="customerForm" class="form-inline">
    <div class="row">
        <div class="col-md-11">
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active">
                    <a href="#customer" aria-controls="customer" 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>
                {% if role != 'zygw' %}
                <li role="presentation">
                    <a href="#addConsultant" aria-controls="addConsultant" role="tab" data-toggle="tab">置业顾问</a>
                </li>
                {% endif %}
            </ul>
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="customer">
                    {% include 'customerDetail.html' %}
                    <hr>
                    {% include 'customerDemand.html' %}
                    <hr>
                    {% include 'customerInfo.html' %}
                </div>
                <div role="tabpanel" class="tab-pane" id="customer_tracking">
                    {% if role == 'zygw' %}
                    {% include 'save_customer_tracking.html' %}
                    {% endif %}
                    {{ macro.customer_tracking_list(houseId, 2) }}
                </div>
                {% if role == 'zygw' %}
                <input type="hidden" name="data[recConsultant][]" value="{{ consultant_id }}">
                {% else %}
                <div role="tabpanel" class="tab-pane" id="addConsultant">
                    {% include 'addConsultant.html' %}
                </div>
                {% endif %}
            </div>
            {% if houseId %}
            <label for="houseId" class="hidden"></label>
            <input type="hidden" name="houseId" id="houseId" value="{{ houseId }}">
            {% endif %}
        </div>
        <div class="col-md-1">
            <input type="submit" id="submit" class="button action" style="position: fixed;">
            {% if role != 'zygw' %}
            <div class="row" style="position: fixed;top:50px;">
                <select id="status" name="status">
                    {% for item in status %}
                    <option {{ item.id == result.status?"selected":"" }} value={{ item.id }}>{{ item.value }}</option>
                    {% endfor %}
                </select>
            </div>
            {% endif %}
        </div>
    </div>
</form>
{% include 'recConsultant.html' %}
{{ block('recConsultant') }}
<script>
    (function($){
        $(document).ready(function(){
            $("#baseCity").change(function(){
                setCity("baseCity","baseAreaId","basePlateId");
            });
            $("#baseAreaId").change(function(){
                setArea("baseCity","baseAreaId","basePlateId");
            });

            var error = $('#error');
            $('#customerForm').validate({
                onkeyup: false,
                onfocusout: false,
                ignore: [],
                errorClass: "my-error-class",
                rules: {
                    name: 'required',
                    phone: 'required',
                    description: 'required',
                    baseCity: {
                        min: 0
                    },
                    baseAreaId: {
                        min: 0
                    },
                    basePlateId: {
                        min: 0
                    },
                    status: {
                        min: 0
                    }
                },
                messages: {
                    name: '请输入姓名',
                    phone: '请输入电话',
                    description: '请输入跟进说明',
                    baseCity: '请选择城市',
                    baseAreaId: '请选择区域',
                    basePlateId: '请选择板块',
                    status: '请选择状态'
                },
                errorLabelContainer: error,
                submitHandler: function (form) {
                    var consultantImg = $('#consultantImg');
                    if (consultantImg.length == 1 && consultantImg.find('p').length == 0) {
                        error.html('<label class="my-error-class">请选择置业顾问</label>');
                        error.show();
                    } else {
                        form.submit();
                    }
                }
            });


            {% if result is not null %}
            var json = {
                'character': '{{ result.character }}',
                'origin': '{{ result.origin }}',
                'payment_mode': '{{ result.payment_mode }}',
                'rent': '{{ result.rent }}',
                'tenancy': '{{ result.tenancy }}',
                'propertyRight': '{{ result.propertyRight }}',
                'decoration': '{{ result.decoration }}',
                'age': '{{ result.age }}',
                'faceto': '{{ result.faceto }}',
                'bedroom': '{{ result.bedroom }}',
                'hall': '{{ result.hall }}',
                'bathroom': '{{ result.bathroom }}'
            };
            revertOption(json);
            {% endif %}
        });
    })(jQuery);
</script>

</body>
</html>