<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%@ include file="/WEB-INF/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <link rel="stylesheet" href="/static/weixin/css/public.css">
    <link rel="stylesheet" href="/static/weixin/css/wechat_add_new.css">
    <link rel="stylesheet" href="/static/weixin/css/basic.css">
    <script src="/static/weixin/js/flexible.js"></script>
    <title>城市选择</title>
    <style>
        .sd_city_selection .select_content ul {
            min-height: 80px !important;
        }
        #wrapper{
            overflow: auto;
            top: 1.1rem;
        }
        /*.administer-head {*/
            /*padding: 0.31333rem 0.32rem;*/
        /*}*/
    </style>
</head>
<body id="contain">
<div class="contain">
    <div class="bai-head">
        <span>城市选择</span>
        <a href="/weixin/bill/bill-condition?product_type=${p.product_type}" class="left">
            <img src="/static/weixin/images/head-left.png"/>
        </a>
    </div>
    <div class="administer-head">
        <input id="keyword" type="text" placeholder="请输入关键字搜索">
        <span class="head-remove"></span>
        <a id="searchBtn" class="head-serach">搜索</a>
    </div>
        <div id="wrapper" class="sd_city_selection">
            <div class="select_provice select_content">
                <h2>省份</h2>
                <ul class="provice_content">

                </ul>
            </div>
            <div class="select_city select_content">
                <h2>城市</h2>
                <ul class="city_content">

                </ul>
            </div>
        </div>

</div>
</body>
<script src="/static/weixin/js/jquery-1.8.3.min.js"></script>
<script src="/static/weixin/common/layer_mobile/layer.js"></script>
<link rel="stylesheet" href="/static/weixin/common/layer_mobile/need/right.css">
<script src="/static/weixin/common/jquery.formHelper.js"></script>
<script type="text/javascript" src="/static/weixin/js/g.js"></script>
<script>
    function initEvent(){
        // 搜索框的变化
        $(".administer-head input").focus(function(){
            $('.administer-head input').css({"transition":"all ease-in .5s","width":"84.85%"});
            $(this).siblings('.head-serach').css({"right":'3.2%'});
            re_length = $(this).val().length;
            if(re_length >=1 ){
                $(".administer-head").find('.head-remove').css({"opacity":'1'});
            }
        }).blur(function(){
            sd_width = Math.ceil($('.administer-head .head-serach').width())+10;
            $('.administer-head input').css({"transition":"all ease-in .5s","width":"100%"});
            $(this).siblings('.head-serach').css({"right":-sd_width+'px'});
            $(".administer-head").find('.head-remove').css({"opacity":'0'});
        });
        $(".administer-head").find('input').on('input propertychange',function(){
            re_length = $(this).val().length;
            if(re_length >=1 ){
                $(".administer-head").find('.head-remove').css({"opacity":'1'});
            }else{
                $(".administer-head").find('.head-remove').css({"opacity":'0'});
            }
        });
        $(".administer-head .head-remove").unbind("click").click(function () {
            $(this).siblings('input').val('').focus();
        });

        //点击省份
        $('.select_content ul.provice_content li span').unbind("click").click(function () {
            $('.select_content ul.provice_content li span').removeClass('on');
            $(this).addClass('on');
            provice_name = $(this).text();
            province_id  = $(this).attr("pid");
//            console.log('选中的省份:',provice_name);
            sessionStorage.setItem("sel_region",JSON.stringify({region_name:provice_name,region_id:province_id}));
            window.location.href="/weixin/bill/bill-condition?product_type=${p.product_type}";
        });

        //点击城市
        $('.select_content ul.city_content li span').unbind("click").click(function () {
            $('.select_content ul.city_content li span').removeClass('on');
            $(this).addClass('on');
            city_name = $(this).text();
            city_id  = $(this).attr("pid");
//            console.log('选中的城市:',city_name);
            sessionStorage.setItem("sel_region",JSON.stringify({region_name:city_name,region_id:city_id}));
            window.location.href="/weixin/bill/bill-condition?product_type=${p.product_type}";
        });

        $("#searchBtn").unbind("click").click(function(){
            refresh();
        });
    }(initEvent())


    /**
     * 刷新页面
     */
    function refresh(){
        g_ajax("/weixin/bill/get-area-info",{keyword:$("#keyword").val()},function(json){
            console.log(json)
            var provinces="", cities="";
            //省份
            for(var i in json.province){
                var row = json.province[i];
                provinces +="<li><span pid='"+row.province_id+"'>"+row.province+"</span></li>";
            }
            $(".provice_content").html(provinces);
            //城市
            for(var i in json.city){
                var row = json.city[i];
                cities +="<li><span pid='"+row.citytype_id+"'>"+row.citytype+"</span></li>";
            }
            $(".city_content").html(cities);
            initEvent();
        });
    }(refresh())



</script>
</html>