<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js?<?php echo bonus_version(); ?>"></script>
        <title>限时购</title>
        <link rel="stylesheet" href="<?php echo RESOURCE_SITE_URL; ?>/mobile/activity/css/count_down.css?<?php echo bonus_version(); ?>"/>
    </head>
    <body>
        <div class="maincontent" id="count_goods_box">
            <div class="count_down_content">
                <div class="time_box">
                    <div class="hour" id="hour"></div>
                    <span>:</span>
                    <div class="min" id="min"></div>
                    <span>:</span>
                    <div class="second" id="second"></div>
                </div>
                <h3>
                    <?php
                        $price_cent = intval($output['goods_price'] * 100 + 0.5);
                        if($price_cent > 0) {
                            $promotion_cent = intval($output['goods_promotion_price'] * 100 + 0.5);
                            $discount = intval(($promotion_cent / $price_cent) * 100 + 0.5) / 10;
                            echo( "{$discount}");
                            echo '<span style="font-size:0.6rem;padding-left:0.12rem;vertical-align: middle;font-weight: 600;">折</span>';
                        } else {
                            echo("点击进入");
                        }
                    ?>
                </h3>
                <div class="count_goods_name"><?php echo($output['goods_name']); ?> </div>
                <div class="count_goods_price">
                    <span class="gount_price">￥<?php echo($output['goods_promotion_price']); ?></span>
                    <span class="purchase_price"><?php echo($output['goods_price']); ?></span>
                </div>
            </div>
            <div class="count_down_image">
                <img src="<?php echo ($output['goods_image_url']); ?>" alt="限时购"/>
            </div>
            <input type="hidden" id="server_local_time" value="<?php echo $output['local_time']; ?>"/>
            <input type="hidden" id="server_start_time" value="<?php echo $output['act_time']; ?>"/>
        </div>
        <script src="<?php echo RESOURCE_SITE_URL; ?>/mobile/activity/js/zepto.min.js?<?php echo bonus_version(); ?>"></script>
        <script src="<?php echo RESOURCE_SITE_URL; ?>/mobile/activity/js/app_count_down.js?<?php echo bonus_version(); ?>"></script>
    </body>

    <script type="text/javascript">
        function init_ios_bridge(callback)
        {
            if (window.WebViewJavascriptBridge) {
                return callback(WebViewJavascriptBridge);
            }

            if (window.WVJBCallbacks) {
                return window.WVJBCallbacks.push(callback);
            }

            window.WVJBCallbacks = [callback];
            var WVJBIframe = document.createElement('iframe');
            WVJBIframe.style.display = 'none';
            WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
            document.documentElement.appendChild(WVJBIframe);
            setTimeout(function() {
                document.documentElement.removeChild(WVJBIframe);
            }, 0);
        }

        function init_android_bridge()
        {
            if (window.WebViewJavascriptBridge)
            {
                WebViewJavascriptBridge.init();
            }
            else
            {
                document.addEventListener(
                    'WebViewJavascriptBridgeReady'
                    , function() {
                        WebViewJavascriptBridge.init();},
                    false);
            }
        }

        function call_native_handler(handler, data)
        {
            if (window.WebViewJavascriptBridge)
            {
                window.WebViewJavascriptBridge.callHandler(handler,
                    data,
                    null);
            }
            else
            {
                document.addEventListener(
                    'WebViewJavascriptBridgeReady'
                    , function()
                    {
                        window.WebViewJavascriptBridge.callHandler(
                            handler,
                            data,
                            null,
                            false);
                    }
                );
            }
        }
        function register_js_hander(name,callback)
        {
            if (window.WebViewJavascriptBridge)
            {
                window.WebViewJavascriptBridge.registerHandler(name,
                    callback);
            }
            else
            {
                document.addEventListener(
                    'WebViewJavascriptBridgeReady'
                    , function()
                    {
                        window.WebViewJavascriptBridge.registerHandler(name,callback);
                    }
                );
            }
        }

        var isMobile = {
            Android: function() {
                return navigator.userAgent.match(/Android/i);
            },
            BlackBerry: function() {
                return navigator.userAgent.match(/BlackBerry/i);
            },
            iOS: function() {
                return navigator.userAgent.match(/iPhone|iPad|iPod/i);
            },
            Opera: function() {
                return navigator.userAgent.match(/Opera Mini/i);
            },
            Windows: function() {
                return navigator.userAgent.match(/IEMobile/i);
            },
            any: function() {
                return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
            }
        };

        if(isMobile.iOS()) {
            init_ios_bridge(function(bridge) { });
        } else {
            init_android_bridge();
        }
        register_js_hander('on_js_click',function(data,callback) {
            callback('{"action":"groupbuy","params":null}');
        });

        $('#count_goods_box').on('click',function() {
            call_native_handler('on_native_click','{"action":"groupbuy","params":null}');
        });

        var server_time = parseInt($('#server_local_time').val());
        var start_time  = parseInt($('#server_start_time').val());
        var countDowner = new CountDowner();
        countDowner.init(server_time,start_time);

        setInterval(function ()
        {
            if(countDowner.isEnd() == false) {
                countDowner.run();
            } else {
                location.reload();
            }
        },1000);

    </script>
</html>