<div class="wrap">
    <h2>客户列表</h2>
    <form method="get">
        <input type="hidden" name="page" value="customerList">
        <div id="search_form">
            <input type="hidden" name="hasSearch" value="1"/>
            <label for="status" class="hidden"></label>
            <select name="status" id="status">
                <option value="-1">状态</option>
                {% for item in status %}
                <option {{ item.id == status_id ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
                {% endfor %}
            </select>
            <label for="customer_type" class="hidden"></label>
            <select name="customer_type" id="customer_type">
                <option value="-1">客户类型</option>
                {% for item in customer_type %}
                <option {{ item.id == customer_type_id ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
                {% endfor %}
            </select>
            <label for="demand_type" class="hidden"></label>
            <select name="demand_type" id="demand_type">
                <option value="-1">需求类型</option>
                <option value="0">新房</option>
                <option value="1">二手房</option>
                <option value="2">租房</option>
            </select>
            <label for="listCity" class="hidden"></label>
            <select id="listCity" name="listCity">
                <option value="-1"> 城市</option>
                {% for item in city %}
                <option {{ item.id == cityId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
                {% endfor %}
            </select>
            <label for="listDistrict" class="hidden"></label>
            <select id="listDistrict" name="listDistrict">
                <option value="-1">区域</option>
                {% if district %}
                {% for item in district %}
                <option {{ item.id == districtId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
                {% endfor %}
                {% endif %}
            </select>
            <label for="listPlate" class="hidden"></label>
            <select id="listPlate" name="listPlate">
                <option value="-1">板块</option>
                {% if plate %}
                {% for item in plate %}
                <option {{ item.id == plateId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
                {% endfor %}
                {% endif %}
            </select>
            <label for="totalPrice" class="hidden"></label>
            <select id="totalPrice" name="totalPrice" class="hidden">
                <option value="">总价</option>
                {% if dicTotalPrice %}
                {% for item in dicTotalPrice %}
                <option {{ item.value == totalPrice ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option>
                {% endfor %}
                {% endif %}
            </select>
            <label for="rentalPrice" class="hidden"></label>
            <select id="rentalPrice" name="rentalPrice" class="hidden">
                <option value ="">月租</option>
                {% if dicRentalPrice %}
                {% for item in dicRentalPrice %}
                <option {{ item.value == rentalPrice ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option>
                {% endfor %}
                {% endif %}
            </select>
            <label for="buildProperty" class="hidden"></label>
            <select id="buildProperty" name="buildProperty">
                <option value="-1">房型</option>
                {% for item in buildProperty %}
                <option {{ item.id == buildPropertyId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
                {% endfor %}
            </select>
            <label for="acreage" class="hidden"></label>
            <select id="acreage" name="acreage">
                <option value="">面积</option>
                {% if acreage %}
                {% for item in dicArea %}
                <option {{ item.value == acreage ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option>
                {% endfor %}
                {% endif %}
            </select>
        </div>
        <div style="margin-top: 10px;">
            <input type="text" placeholder="请输入姓名" name="search_name" value="{{ search_name }}">
            <input type="text" placeholder="请输入置业顾问" name="search_consultant_name" value="{{ search_consultant_name }}">
            <input type="text" placeholder="请输入电话" name="search_phone" value="{{ search_phone }}">
        </div>
        <div style="margin-top: 10px;">
            <span>日期</span>
            <label for="search_min_time" class="hidden"></label>
            <input type="date" name="search_min_time" id="search_min_time" value="{{ search_min_time }}">
            —
            <label for="search_max_time" class="hidden"></label>
            <input type="date" name="search_max_time" id="search_max_time" value="{{ search_max_time }}">
            <input type="submit" id="submit" class="button action" value="搜索">
        </div>
    </form>
    <form method="post">
        {{ function("addCustomerTable") }}
        <input type="hidden" name="allot_consultant_id" id="allot_consultant_id">
    </form>
</div>
{% include 'recConsultant.html' %}
{{ block('recConsultant') }}
<script>
    $(document).ready(function () {
        var demand_type_select = $('#demand_type');
        demand_type_select.val('{{ demand_type }}');
        search_form_set_page();

        var acreage = $("#acreage");
        var totalPrice = $("#totalPrice");
        var rentalPrice = $("#rentalPrice");
        var listCity = $('#listCity');
        listCity.change(function () {
            var cityId = $('#listCity').val();
            setCity('listCity', 'listDistrict', 'listPlate');
            acreage.find('option:not(:first-child)').remove();
            totalPrice.find('option:not(:first-child)').remove();
            rentalPrice.find('option:not(:first-child)').remove();
            //面积
            searchAcreage(cityId, acreage);
            setTotalOrRentalPrice(demand_type_select, cityId);
        });
        //设置区域
        $('#listDistrict').change(function () {
            setArea('listCity', 'listDistrict', 'listPlate');
        });

        demand_type_select.change(function () {
            totalPrice.find('option:not(:first-child)').remove();
            rentalPrice.find('option:not(:first-child)').remove();
            setTotalOrRentalPrice($(this), listCity.val());
        });

        setTotalOrRentalPrice(demand_type_select, listCity.val());

        function setTotalOrRentalPrice(self, cityId) {
            var demand_type = self.val();
            if (demand_type == 0 || demand_type == 1) {
                totalPrice.removeClass('hidden');
                rentalPrice.addClass('hidden');
                searchTotalPrice(cityId, totalPrice);
            } else if (demand_type == 2) {
                rentalPrice.removeClass('hidden');
                totalPrice.addClass('hidden');
                searchRentalPrice(cityId, rentalPrice);
            }else{
                rentalPrice.addClass('hidden');
                totalPrice.addClass('hidden');
            }
        }

        allot_consultant('customerlist');
    });
</script>