<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>邀请好友</title>
    <meta name="viewport" content="width=750,user-scalable=no,target-densitydpi=device-dpi">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="<?php echo RESOURCE_SITE_URL; ?>/mobile/invite_friend/css/main.css?<?php echo bonus_version(); ?>">
</head>

<body>
<div class="container">
    <div class="top">
        <div class="rules" id="rules">
            <span>查看规则</span>
        </div>
        <span class="label label_1">邀请好友得<span class="num">5</span>元红包</span>
        <span class="label label_2">好友邀请他人你也得<span class="num">1</span>元红包</span>
        <span class="label label_3">好友每下一单得<span class="num">3</span>元红包</span>
        <span class="label label_4">以此类推，多邀多赚</span>
    </div>
    <div class="bonus_content">
        <?php $output['tpl']->show(); ?>
    </div>
    <div class="pop" id="pop">
        <div class="rules_content" id="rules_content">
            <h3>邀请规则</h3>
            <div class="rules_list" id="rules_list">
                <p>
                    (1).通过您发出邀请链接，好友微信授权、注
                    册下载APP、登录后，您将获得5元100%红包，
                    累计叠加，上不封顶。好友邀请的好友以此递推，
                    按层级关系您也会获得1元,0.5元等红包。
                </p>
                <p>
                    (2).您的好友每下一单，您可获得3元100%回
                    礼红包。好友的好友下单，按层级关系您同样
                    获得100%不等金额红包。在层级关系中的任
                    意好友N次下单，您将获得N次红包。
                </p>
                <p>
                    (3).您可以通过分享红包、好物、文章等任意
                    链接，粘粉新用户注册，即可获得以上福利。
                    注意：
                    该红包可累计使用，有效期为30天，直接在订
                    单中折扣金额，系统默认减扣当前您可用的最
                    高红包金额；若您取消订单，红包金额会返还
                    ，若您退货则红包金额不返回。
                    如用户在活动期间存在违规行为（包括但不限
                    于机器作弊，刷IP）熊猫将有权取消用户的获
                    奖资格，并收回所有红包（含已使用的和未使
                    用的）或关闭相应订单，必要时追究法律责任
                    。如对本活动规则有任何疑问，请联系熊猫美
                    妆在线客服。
                </p>
                <p>
                    本次活动最终解释权归熊猫美妆所有。
                </p>
            </div>

            <span class="close_btn" id="close_btn">确定</span>
        </div>
    </div>
    <?php $output['tpl']->show_open(); ?>
</div>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL; ?>/mobile/bonus/js/zepto.min.js?<?php echo bonus_version(); ?>"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL; ?>/mobile/comm/layer.js?<?php echo bonus_version(); ?>"></script>
<script type="text/javascript">

    var isapp = <?php echo session_helper::isapp() ? 'true' : 'false'; ?>;
    if(!isapp) {
        document.getElementsByClassName('bonus_content')[0].setAttribute('style','padding-bottom:120px');
    }

    window.addEventListener('pageshow', function () {
        if (window.sessionStorage.getItem('Already_received')) {
            window.sessionStorage.removeItem('Already_received');
            window.location.reload(true);
        }
    });
    window.onload = function()
    {
        var window_no_scroll = function(e){
            if(e.target.nodeName == 'P' && (document.getElementById('rules_list').scrollHeight) > 600) {
                return;
            }
            e.preventDefault();
        };
        document.getElementById('rules').addEventListener('click',function(e){
            document.getElementById('pop').style.display = 'block';
            window.addEventListener('touchmove',window_no_scroll);
        });
        document.getElementById('close_btn').addEventListener('touchend',function(e){
            e.preventDefault();
            document.getElementById('pop').style.display = 'none';
            window.removeEventListener('touchmove',window_no_scroll);
        });
        $('.open_bonus_btn').on('click',function(){
            $(this).css('opacity',0);
            $('.open_bonus_link .bonus_top').addClass('open_bonus');
            var grab_url='<?php echo $output['tpl']->bonus_url(); ?>';
            window.sessionStorage.setItem('Already_received',true);
            setTimeout(function(){
                window.location.href=grab_url;
            },500);
        });
        $('.call_btn').on('touchend',function(e){
            e.preventDefault();
            if($(this).hasClass('called')) {
                $(this).off('touchend');
                return;
            }
            $(this).addClass('called');
            var user = $(this).attr('data-user');
            var self = $(this);
            var host = window.location.protocol + "//" + window.location.host;
            $.ajax({
                type: "get",
                async: false,
                url: host + "/mobile/index.php?act=invite_friend&op=call_user&client_type=ajax&user=" + user,
                dataType: "jsonp",
                jsonp: "callback",
                jsonpCallback: "flightHandler",
                success: function(res)
                {
                    if(res.code == 200) {
                        alert('今日召唤成功，每人每日限召唤一次～');
                        self.off('touchend');
                    }
                    else {
                        self.removeClass('called');
                        alert(res.message);
                    }
                }
            });
        });

        (function() {
            var locked = false;
            window.addEventListener('scroll', function(ev){
                locked || (locked = true, window.addEventListener('touchend', stopTouchendPropagation, true));
            }, true);
            function stopTouchendPropagation(ev){
                ev.stopPropagation();
                window.removeEventListener('touchend', stopTouchendPropagation, true);
                locked = false;
            }
        })();
    }
</script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js?<?php echo bonus_version(); ?>"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL; ?>/mobile/comm/wx_share.js?<?php echo bonus_version(); ?>"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL; ?>/mobile/comm/bridge.js?<?php echo bonus_version(); ?>"></script>

<script>

    if(isMobile.iOS()) {
        init_ios_bridge(function(bridge) { });
        $('#download_app').attr('href','itms-apps://itunes.apple.com/app/id945609424');
    } else if (isMobile.Android) {
        init_android_bridge();
        $('#download_app').attr('href','http://p.lrlz.com/data/upload/package/xmmz_release.apk');
    } else {
        $('#download_app').attr('href','javascript:void(0)');
    }

    var url         = "<?php echo $output['tpl']->share_url(); ?>";
    var title = "<?php echo $output['tpl']->share_title(); ?>";
    var img_url     = "<?php echo $output['tpl']->share_image(); ?>";
    var sub_title   = "<?php echo $output['tpl']->share_subtitle(); ?>\n\n点击领取";

    weiXinShare.init({
        title:title,
        desc:sub_title,
        link:url,
        imgUrl:img_url
    });

    var jsonobject = {
        action:"view_init",
        params: {
            can_invite:true, //为兼容之前版本，保留
            can_share:true,
            title:title,
            sub_title:sub_title,
            img_url:img_url,
            url:url
        }
    };
    call_native_handler('on_native_click',JSON.stringify(jsonobject));
</script>
</body>
</html>