<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!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/weChat/css/public.css">
    <link rel="stylesheet" href="/static/weChat/css/bai_basic.css">
    <script src="/static/weChat/js/flexible.js"></script>
    <title>搜索-结果页</title>
</head>
<body id="container">
<div class="lian-search">
    <div class="search">
        <div class="search-back">
            <a href="/weixin/product/win/search">
                <img src="/static/weChat/images/yellow-back.png" />
            </a>
        </div>
        <input id="searchText" type="text" placeholder="请输入关键词搜索" value=""/>
        <div class="serach-error">
            <img src="/static/weChat/images/remove-error.png" />
        </div>
    </div>
    <div class="lian-cancel">
        <a href="/weixin/product/win/list">取消</a>
    </div>
</div>

<h2 class="search-number">共搜索到<i id="searchNum">0</i>条结果</h2>

<div id="wrapper" class="product-results">
    <div class="administer" id="scroller">
        <div class="insurance-list">
            <ul id="product">
               <%-- <li>
                    <a href="">
                        <div class="insur-head">
                            <div class="head-img"></div>
                            <div class="head-right">
                                <h2>众安展会综合责任保险计划一众安展会综合责任保险计划一</h2>
                                <p>保障期限：1年</p>
                                <span>灰色空间带饭还是看大家水灰色空间带饭还是看大家水灰色空间带饭还是看大家水电费灰色空间返回抗生素东方航空收到反馈生死看淡交话费考试</span>
                            </div>
                        </div>
                        <div class="insur-cont">
                            <p>
                                <span>展会场馆方财产损失责任</span>
                                <i>50万元</i>
                            </p>
                            <p>
                                <span>第三者人身损害责任</span>
                                <i>100万元</i>
                            </p>
                            <p>
                                <span>雇主责任</span>
                                <i>150万</i>
                            </p>
                        </div>
                        <p class="head-money">
                            ￥450.00
                            <i>起</i>
                        </p>
                    </a>
                </li>
                --%>
            </ul>
        </div>
        <div id="pullUp">
            <span class="pullUpLabel">上拉加载更多...</span>
        </div>
        <p id="ert"></p>
    </div>
</div>
</body>
<script src="/static/weChat/js/jquery-1.8.3.min.js"></script>
<script src="/static/weChat/common/layer_mobile/layer.js"></script>
<link rel="stylesheet" href="/static/weChat/common/layer_mobile/need/right.css">
<script src="/static/weChat/js/weixin_g.js"></script>
<script src="/static/weChat/js/basic.js"></script>
<script src="/static/weChat/js/iscroll.js"></script>
<script src="/static/weChat/js/product-result.js"></script>
<script>

    l_length = $('.search input').val().length;
    if(l_length >= 1){
        $('.serach-error').show();
    }

    //搜索框的变化
    $(".lian-search").find('input').on('input propertychange',function(){
        var re_length = $(this).val().length;
        if(re_length >=1 ){
            $('.serach-error').show();
            $('.search-content').show();
        }else{
            $('.serach-error').hide();
            $('.search-content').hide();
        }
    });

    $('.serach-error').click(function () {
        $(".lian-search input").val('');
        $(this).hide();
        $('.search-content').hide();
    });

    $('#serach-histroy h2 span').click(function () {
        $('#serach-histroy ul').remove();
    });


    //分页查询开始
    var p = { limit: 5, offset: 0 };
    <%--var gurl = '${url}';--%>
    <%--var recommendCode = '${recommendCode}';--%>

    function searchHandler(){
        $("#product").html("");
        p = { limit: 5, offset: 0 };
        p.search  = $("#searchText").val().trim();
        getData();
        myScroll.refresh();
    }

    //搜索功能
    $("#search").click(searchHandler);

    function chgMoney(money){
        if(money>=10000){
            return (money/10000)+"万";
        }else{
            return money;
        }
    }

    function getData(){
        g_ajax("/weixin/product/query",p ,function(json){
            var el, li, i;
            var rows = json.rows;
            var total = json.total;
            $("#searchNum").html(total);
            el = document.getElementById('product');
            if( rows==undefined || rows.length==0 ) { //长度为空，或者小于limit条数，说明是已经到最后了
                $("#pullUp").hide();
                $("#ert").text('数据已经加载完了！').show();
                return;
            }else{
                p.offset += p.limit;
            }
            for(var i in rows){
                li = document.createElement('li');
                var responses = "";
                var res = rows[i].responsesList;
                if(res!=""){
                    for( var idx in res ){
                        responses += '<p><span>'+res[idx].show_name+'</span><i>'+chgMoney(res[idx].insurance_amount_max)+'元</i></p>';
                    }
                }
                li.innerHTML =
                    '<a href="/weixin/product/win/detail?pro_primary_id='+rows[i].pro_primary_id+'">'
                    +'<div class="insur-head">'
                    +'<div class="head-img" style="background:url('+rows[i].company_logo+')  no-repeat center center;background-size: 100% auto;"></div>'
                    +'<div class="head-right">'
                    +'<h2>'+ rows[i].insurance_name +'</h2>'
                    +'<p>保障期限：1年</p>'
                    +'<span>'+rows[i].intro+'</span>'
                    +'</div>'
                    +'</div>'
                    +'<div class="insur-cont">'
                    + responses
                    +'</div>'
                    +'<p class="head-money">'
                    + '￥'+rows[i].fixed_premium
                    +'<i> 起</i>'
                    +'</p>'
                    +'</a>'
                el.appendChild(li, el.childNodes[0]);
            }
        },false);
    }
    function pullUpAction () {
        getData();
        myScroll.refresh();		// 数据加载完成后，调用界面更新方法 Remember to refresh when contents are loaded (ie: on ajax completion)
    }

    $("#searchText").click(function(){
        location.href = '/weixin/product/win/search';
    });

    $(document).ready(function(){;
        $("#product").html("");
        p = { limit: 5, offset: 0 };
        p.search = '${keyword}';
        $("#searchText").val(p.search);
        getData(); //初始化加载
    });







</script>
</html>