<%@ 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>
        .administer-head{
            top: 1.1033rem !important;
        }
    </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 class="sd_distributor">
        <ul>
            <%--<li>--%>
                <%--<a href="javascript:;">--%>
                    <%--<p>厦门市一级分销商</p>--%>
                    <%--<i></i>--%>
                <%--</a>--%>
            <%--</li>--%>
            <%----%>
        </ul>
    </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();
        });

        //分销商选择时
        $('.sd_distributor ul li').unbind("click").click(function () {
            $('.sd_distributor ul li').removeClass('on');
            $(this).addClass('on');
            var companyName = $(this).find('p').text();//选中的分销商的名字
            var companyId = $(this).find('p').attr("cid");//选中的分销商的名字
//            console.log('选中的名字是:',distributor_name);
            sessionStorage.setItem("sel_company",JSON.stringify({company_name:companyName,company_id:companyId}));
            window.location.href="/weixin/bill/bill-condition?product_type=${p.product_type}";

        });
    }(initEvent())

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

    /**
     * 刷新页面
     */
    function refresh(){
        g_ajax("/weixin/bill/get-low-level-company-by-current-company",{keyword:$("#keyword").val()},function(json){
            console.log(json)
            var str  = "";
            <%--str+= '<li>'--%>
                <%--+ '	<a href="javascript:;">'--%>
                <%--+ '		<p cid="${p.weixin_login_company_id}">${p.weixin_login_company_name}</p>'--%>
                <%--+ '		<i></i>'--%>
                <%--+ '	</a>'--%>
                <%--+ '</li>';--%>
            for(var i in json){
                var row  = json[i];
                str+= '<li>'
                    + '	<a href="javascript:;">'
                    + '		<p cid="'+row.id+'">'+row.companyName+'</p>'
                    + '		<i></i>'
                    + '	</a>'
                    + '</li>';
            }
            //g_getRegion(code)
            $(".sd_distributor ul").html(str);
            initEvent();
        });
    }(refresh())
    
</script>
</html>