<%@ 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/basic.css">
    <script src="${ctxwxsta}/js/flexible.js"></script>

    <title>推广产品</title>
</head>
<body id="contain">
<div class="contain">
    <div class="bai-head">
        <span>推广产品</span>
        <a href="/weixin/share/shareIndex;" class="left">
            <img src="/static/weixin/images/head-left.png"/>
        </a>
    </div>
    <div class="administer-head">
        <input id="searchText"  type="text" placeholder="请输入产品名称/产品分类">
        <span class="head-remove"></span>
        <a href="javascript:;" id="search" class="head-serach">搜索</a>
    </div>
    <div id="wrapper" class="inferiors-cont adminuster-wed">
        <div class="administer wrapper-product" id="scroller">
            <%--<div id="qaz">--%>
                <%--<span>可销售产品</span>--%>
                <%--&lt;%&ndash;<c:if test="${flag}">&ndash;%&gt;--%>
                    <%--&lt;%&ndash;<span style="float:right">&ndash;%&gt;--%>
                         <%--&lt;%&ndash;<a  href="/weixin/activity/activityListOnline" class="zhan" style="text-decoration: underline">展会活动管理</a>&ndash;%&gt;--%>
                    <%--&lt;%&ndash;</span>&ndash;%&gt;--%>
                <%--&lt;%&ndash;</c:if>&ndash;%&gt;--%>

            <%--</div>--%>
            <ul class="optional-product share-product" id="assigned-list">
                <%--<li>--%>
                    <%--<div class="select-content assigned-content">--%>
                        <%--<div class="select-left">--%>
                            <%--<p>风评产品</p>--%>
                            <%--<span>安保无忧全年意外险计划四</span>--%>
                            <%--<i>有效期: 2017-12-12至2018-12-12</i>--%>
                        <%--</div>--%>
                        <%--<div class="select-right assigned-right">--%>
                            <%--<p class="active">15%</p>--%>
                            <%--<span>收入比例</span>--%>
                            <%--<b class="share">分享</b>--%>
                        <%--</div>--%>
                    <%--</div>--%>
                <%--</li>--%>
                <%--<li>--%>
                    <%--<div class="select-content assigned-content">--%>
                        <%--<div class="select-left">--%>
                            <%--<p>风评产品</p>--%>
                            <%--<span>安保无忧全年意外险计划四</span>--%>
                            <%--<i>有效期: 2017-12-12至2018-12-12</i>--%>
                        <%--</div>--%>
                        <%--<div class="select-right assigned-right">--%>
                            <%--<p class="active">15%</p>--%>
                            <%--<span>收入比例</span>--%>
                            <%--<b>不支持分享</b>--%>
                        <%--</div>--%>
                    <%--</div>--%>
                <%--</li>--%>
            </ul>
            <div id="pullUp">
                <span class="pullUpLabel">上拉加载更多...</span>
            </div>
            <p id="ert"></p>
        </div>
    </div>

</div>

<script src="/static/weixin/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="/static/weixin/js/iscroll.js"></script>
<script type="text/javascript" src="/static/weixin/js/basicOne.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 src="/static/weixin/common/clipboard.min.js"></script>
<script type="text/javascript" src="/static/weixin/js/g.js"></script>
<script type="text/javascript" src="/static/weixin/js/shareProduct.js"></script>
<style>
    .disableBtn{
        color:gray !important;
        border: 1px !important;
    }
</style>
<script>
    var p = { limit: 5, offset: 0 ,product_type:${p.product_type}};
    var gurl = '${url}';
    var blbUrl = '${blbUrl}';
    var recommendCode = '${recommendCode}';

    $("#search").click(function(){
        $("#assigned-list").html("");
        p = { limit: 5, offset: 0, product_type:${p.product_type} };
        p.search  = $("#searchText").val().trim();
        getData();
        myScroll.refresh();
    });

    function getData(){
        g_ajax("/weixin/share/query",p ,function(json){
            var el, li, i;
            var rows = json.rows;
            var total = json.total;
            el = document.getElementById('assigned-list');
            if( rows.length==0 ) { //长度为空，或者小于limit条数，说明是已经到最后了
//                $(".pullUpLabel").html("没有更多了");
                $("#pullUp").hide();
                $("#ert").text('数据已经加载完了！').show();
                return;
            }else{
                p.offset += p.limit;
            }
            for(var i in rows){
                li = document.createElement('li');
                var url  = gurl+"/"+rows[i].product_id+"?recommendCode="+recommendCode;
                var fee = rows[i].fee==undefined?"-":rows[i].fee+"%";

                //控制分享按钮的样式，是保险才可以分享
                var isSupportShareCls = "disableBtn", text="不支持分享";
                if(rows[i].productName==6){
                    isSupportShareCls = "sharebtn"; //分享
                    text = "分享";
                    //如果是资源方，跳过，使用正常默认的
                    if("${p.weixin_login_company_type}"!='4'){
                      //如果不是资源方，就链接到活动创建的地方
                        if(rows[i].product_code!=undefined && rows[i].product_code.indexOf("ZZX")>=0){ //众安展责险分享
//                            isSupportShareCls="specialZAZZX";
                            url=blbUrl+"weixin/product/win/list"+"?recommendCode="+recommendCode;
//                             isSupportShareCls = "disableBtn", text="不支持分享";
                            //要分享，变手机端、
                        }
                    }
                }
//                var text = rows[i].productName==6?"分享":"不支持分享"; //只有保险支持分享
                li.innerHTML =
                    '<div class="select-content assigned-content">'
                    + '<div class="select-left" style="margin-top:0.5rem">'
                    + '<p>'+rows[i].label+'</p>'
                    + '<span>'+rows[i].name+'</span>'
                    // + '<i>创建时间: '+rows[i].createTime+'</i>'
                    + '</div>'
                    + '<div class="select-right assigned-right">'
                    + '<p class="active">'+fee+'</p>'
                    + '<span>收入比例</span>'
                    + '<b class="share '+isSupportShareCls+'" proId="'+rows[i].product_id+'" val="'+url+'" pro="'+rows[i].name+'">'+text+'</b>'
                    + '</div>'
                    + '</div>';
                // console.log(li)
//                console.log(li)
                el.appendChild(li, el.childNodes[0]);
            }
        },false);
    }
    function pullUpAction () {
        getData();
        myScroll.refresh();		// 数据加载完成后，调用界面更新方法 Remember to refresh when contents are loaded (ie: on ajax completion)
    }

    $(document).ready(function(){
        getData(); //初始化加载

        //展责险特殊处理
//        $("#assigned-list").on("click",".specialZAZZX",function(){
//            window.location.href=gurl+"/weixin/product/win/list";
//        });


        var sel="";
        //分享连接
        var clipboard = new Clipboard('.sharebtn', {
            text: function (value) {
                var v = $(value).attr('val');
                sel  =  $(value).attr('pro');
                return v;
            }
        });
        clipboard.on('success', function(e) {
            layer.open({content:"<span style='color:gray'>"+sel+"</span>分享链接已经拷贝，可以通过QQ或微信发送粘帖链接",btn: '我知道了'});
        })

        function getWin(msg,btn){
//            <div class="block-mask"></div>
        }

    });
</script>
</body>
</html>