<div class="wrap">
    <h2>客户列表</h2>
    <form method="get" id="search_form">
        <input type="hidden" name="page" value="customerList">
        <div>
            <input type="hidden" name="hasSearch" value="1"/>
            {% import "selectOrganization.html" as macro %}
            {{ macro.selectOrganization("customer") }}
            <label for="status" class="hidden"></label>
            <select name="status" id="status">
                <option value="-1">状态</option>
                {% set customer_status_array = function('SearchDao::searchStatusType', 5) %}
                {% for item in customer_status_array %}
                <option {{ item.id == req.status ?"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>
                {% set customer_type_array = function('SearchDao::searchStatusType', 6) %}
                {% for item in customer_type_array %}
                <option {{ item.id == req.customer_type ?"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 == req.listCity ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
                {% endfor %}
            </select>
            <label for="listDistrict" class="hidden"></label>
            <select id="listDistrict" name="listDistrict">
                <option value="-1">区域</option>
                {% set district = function('SearchDao::searchCity', req.listCity) %}
                {% if district %}
                {% for item in district %}
                <option {{ item.id == req.listDistrict ?"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>
                {% set plate = function('SearchDao::searchCity', req.listCity, req.listDistrict) %}
                {% if plate %}
                {% for item in plate %}
                <option {{ item.id == req.listPlate ?"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="-1">总价</option>
                {% set dicTotalPrice = function('SearchDao::searchTotalPrice', req.listCity) %}
                {% if dicTotalPrice %}
                {% for item in dicTotalPrice %}
                <option {{ item.value == req.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 ="-1">月租</option>
                {% set dicRentalPrice = function('SearchDao::searchRentalPrice', req.listCity) %}
                {% if dicRentalPrice %}
                {% for item in dicRentalPrice %}
                <option {{ item.value == req.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>
                {% set buildProperty_array = function('SearchDao::searchBuildProperty') %}
                {% for item in buildProperty_array %}
                <option {{ item.id == req.buildProperty ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
                {% endfor %}
            </select>
            <label for="acreage" class="hidden"></label>
            <select id="acreage" name="acreage">
                <option value="-1">面积</option>
                {% set dicArea = function('SearchDao::searchArea', req.listCity) %}
                {% if dicArea %}
                {% for item in dicArea %}
                <option {{ item.value == req.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="{{ req.search_name }}">
            <input type="text" placeholder="请输入置业顾问" name="search_consultant_name" value="{{ req.search_consultant_name }}">
            <input type="text" placeholder="请输入电话" name="search_phone" value="{{ req.search_phone }}">
        </div>
        <div style="margin-top: 10px;">
            <label>日期:</label>
            <label for="search_min_time" class="hidden"></label>
            <input type="date" name="search_min_time" id="search_min_time" value="{{ req.search_min_time }}">
            —
            <label for="search_max_time" class="hidden"></label>
            <input type="date" name="search_max_time" id="search_max_time" value="{{ req.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('{{ req.demand_type|default(-1) }}');
        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');

        $('form').submit(function () {
            var organization = getOrganization('customer');
            var select = $('#customer_organization').find('select[data-depth]:not(.hidden)');
            if (select.length > 1 && organization == -1) {
                alert('请选择门店');
                return false;
            } else {
                $(this).append('<input type="hidden" name="organization" value="' + organization + '">');
            }
        });
    });
</script>