
<div class="wrap">
    <h2>租房房列表</h2>
    <form id="scores-filter" method="POST">
        <!-- For plugins, we also need to ensure that the form posts back to our current page -->
        <input type="hidden" name="page" value="{{page}}"/>
        <input type="hidden" name="hasSearch" value="1"/>
        <select id="listCity" name="listCity">
            {% if hasSearch and options.cityName %}
            <option value="{{options.cityId}}"> {{options.cityName}}</option>
            {% else %}
            <option value="0"> 城市</option>
            {% endif %}
        </select>
        <select id="listDistrict" name="listDistrict">
            {% if hasSearch and options.districtName %}
            <option value="{{options.districtId}}"> {{options.districtName}}</option>
            {% else %}
            <option value="0">区域</option>
            {% endif %}
        </select>
        <select  id="listPlate" name="listPlate">
            {% if hasSearch and options.districtName and options.plateName %}
            <option value="{{options.plateId}}">{{options.plateName}}</option>
            {% else %}
            <option value="0">板块</option>
            {% endif %}
        </select>
        <select id="totalPrice" name="totalPrice">
            {% if hasSearch and totalPrice %}
            <option value="{{totalPrice}}"> {{totalPrice}}</option>
            {% else %}
            <option value ="">价格</option>
            {% endif %}
        </select>
        <select id="buildProperty" name="buildProperty">
            {% if hasSearch and buildProperty %}
            <option value="{{buildPropertyId}}"> {{buildProperty}}</option>
            {% else %}
            <option value="0"> 房型</option>
            {% endif %}
        </select>
        <select id="acreage" name="acreage">
            {% if hasSearch and acreage %}
            <option value="{{acreage}}"> {{acreage}}</option>
            {% else %}
            <option value ="">面积</option>
            {% endif %}
        </select>
        <select name="status" name="status">
            {% if hasSearch and status %}
            {% for item in status %}
            <option value="{{ item.status_id }}">{{ item.status_name }}</option>
            {% endfor %}
            {% else %}
            <option value="-1">状态</option>
            {% endif %}
            <option value="0">未审核</option>
            <option value="1">审核</option>
            <option value="2">自售</option>
            <option value="3">他售</option>
            <option value="4">无效</option>
            <option value="5">重激活</option>
        </select>
        <input type="text" placeholder="请出入楼盘名/地段名搜索" name="searchText">
        <input type="submit" id="submit" class="button action" value="搜索">
        <!-- Now we can render the completed list table -->
        {{function("addRentTable")}}
    </form>
</div>
<script>
    (function ($) {
        $(document).ready(function(){
            //获取城市信息AJAX
            var listCity = $("#listCity");
            var room = $("#room");
            var buildProperty =$("#buildProperty");
            $.ajax({
                type: "GET",
                url: "/tospur/wp-admin/admin-ajax.php",
                data: "action=serachCity",
                success:function(data){
                    addOption(data,listCity)
                }
            })
            //获取类型信息AJAX
            $.ajax({
                type: "GET",
                url: "/tospur/wp-admin/admin-ajax.php",
                data: "action=searchRoom",
                success:function(data){
                    addOption(data,room)
                }
            })
            //获取房型信息AJAX
            $.ajax({
                type: "GET",
                url: "/tospur/wp-admin/admin-ajax.php",
                data: "action=searchBuildProperty",
                success:function(data){
                    addOption(data,buildProperty)
                }
            })


            $("#listCity").change(function(){
                var listCityId = $("#listCity").val();
                var district =$("#listDistrict");
                var acreage =$("#acreage");
                var totalPrice = $("#totalPrice");
                $('#listDistrict').find('option:not(:first-child)').remove();
                $('#listPlate').find('option:not(:first-child)').remove();
                $.ajax({
                    type: "GET",
                    url: "/tospur/wp-admin/admin-ajax.php",
                    data: "action=serachCity&cityId="+listCityId,
                    success:function(json){
                        addOption(json,district);
                    }
                });
                //面积
                $.ajax({
                    type: "GET",
                    url: "/tospur/wp-admin/admin-ajax.php",
                    data: "action=searchArea&cityId="+listCityId,
                    success:function(json){
                        for(var i = 0; i <=json.length-1; i++){
                            var id = json[i]["id"];
                            var value = json[i]["value"];
                            var Option = $("<option>").attr({"value": value}).append(value);
                            $("#acreage").append(Option);
                        }
                    }
                });
                //城市联动房子价格
                $.ajax({
                    type: "GET",
                    url: "/tospur/wp-admin/admin-ajax.php",
                    data: "action=searchUnitPriceRange&cityId="+listCityId,
                    success:function(json){
                        for(var i = 0; i <=json.length-1; i++){
                            var id = json[i]["id"];
                            var value = json[i]["value"];
                            var Option = $("<option>").attr({"value": value}).append(value);
                            $("#totalPrice").append(Option);
                        }
                    }
                });
            })

            $("#listDistrict").change(function(){
                var listCityId = $("#listCity").val();
                var listDistrict = $("#listDistrict").val();
                var listPlate = $("#listPlate");
                $('#listPlate').find('option:not(:first-child)').remove();
                $.ajax({
                    type: "GET",
                    url: "/tospur/wp-admin/admin-ajax.php",
                    data: "action=serachCity&cityId="+listCityId+"&districtId="+listDistrict,
                    success:function(json){
                        addOption(json,listPlate);
                    }
                });
            })

            function addOption(json,select){
                for(var i = 0; i <=json.length-1; i++){
                    var id = json[i]["id"];
                    var value = json[i]["value"];
                    var Option = $("<option>").attr({"value": id}).append(value);
                    select.append(Option);
                }
            }
        });
    })(jQuery);
</script>
