<!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/ugc/css/main.css?<?php echo bonus_version(); ?>">
</head>

<body>
<div class="result_list">
    <div class="my_result">
        <?php $answer = $output['answer']; if(!empty($answer)) { ?>
            <div class="answer_collect">
                <p class="all_question_num">本次答题总计<span class="letter_pro"><?php $answer = $output['answer']; echo $answer['total_num'];?></span>题</p>
                <p class="right_question_num">您答对了<span class="letter_pro"><?php $answer = $output['answer']; echo $answer['correct_num'];?></span>题</p>
            </div>
            <div class="my_score">
                <p><span class="letter_pro"><?php $answer = $output['answer']; echo $answer['score'];?></span>分</p>
            </div>
            <div class="rank">
                <?php $scale = $output['scale'];
                    if($scale != false) {
                        echo "<p>您的智慧已经远远超过了<span class=\"letter_pro\">{$scale}%</span>的人</p>";
                    } else {
                        echo "<p>为了彰显您的智慧，分享给好友一起答题吧～</p>";
                    }
                ?>
            </div>
        <?php } else { ?>
            <div class="my_result_null">您尚未答题</div>
        <?php } ?>
    </div>

    <div class="br"></div>
    <div class="other_bonus_reslut">
    </div>
</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 special_id = <?php echo $output['special_id']; ?>;

    $(function ()
    {
        var getTime = function (time)
        {
            var date = '';
            var location = parseInt(new Date().getTime() / 1000);
            var diffHour = parseInt((location - time) / 60 / 60);
            var diffMinutes = parseInt((location - time) / 60);
            if (diffHour <= 0) {
                if (diffMinutes >= 0 && diffMinutes < 5) {
                    date = "刚刚";
                }
                else {
                    date = diffMinutes + "分钟前";
                }
            }
            if (diffHour < 24 && diffHour > 0) {
                date = diffHour + '小时前';
            }
            if (diffHour >= 24) {
                var milliseconds = time * 1000;//秒变微秒
                var dat = new Date(milliseconds);//生成日期
                var month = dat.getMonth() + 1;    //取得月
                var date1 = dat.getDate(); //取得天
                var hour = dat.getHours();//取得小时
                var minutes = dat.getMinutes();//取得分钟
                if (hour < 10) {
                    hour = '0' + dat.getHours();
                }
                if (minutes < 10) {
                    minutes = '0' + dat.getMinutes();
                }
                date = month + '月' + date1 + '日' + hour + ':' + minutes;
            }
            return date;
        };

        var Item = function (obj, index, datas, is_king)
        {
            var king = '';
            if (is_king) {
                king = '<span class="king_icon"></span>';
            }
            var result = datas;
            var exHtml = function (item)
            {
                var html = '<div class="item">' +
                                '<div class="user_index">' +
                                    +index + '.' +
                                '</div>' +
                                '<div class="user_msg">' +
                                    '<div class="user_img">' +
                                        '<img src="' + result.avatar + '">' + king +
                                    '</div>' +
                                    '<div class="user_pro">' +
                                        '<p class="user_name">' + result.nickname + '</p>' +
                                        '<p class="answer_time">' + getTime(result.answer_time) + '</p>' +
                                    '</div>' +
                                '</div>' +
                                '<div class="score">' +
                                    '<span class="letter_pro">' + result.score + '</span>分' +
                                '</div>' +
                                '<div class="bonus_label">' +
                                    '<p>' + result.amount + '元</p>' +
                                    '<div class="scale"><span class="border">' + result.bonus_rate + '<i class="ratio_icon"></i></span></div>' +
                                '</div>' +
                            '</div>';
                return html;
            };
            this.exportHTML = function () {
                obj.append(exHtml(result));
            }
        };

        var host = (function () {
            return window.location.protocol + "//" + window.location.host;
        })();

        var page = 1;
        var isLoad = false;
        var index = 1;
        var getData = function ()
        {
            isLoad = true;
            var url = host + '/mobile/index.php?act=member_ugc&op=answers&client_type=ajax&special_id=' + special_id + '&curpage=' + page;
            $.ajax({
                type: "get",
                async: false,
                url: url,
                dataType: "jsonp",
                jsonp: "callback",
                jsonpCallback: "flightHandler",
                success: function (data)
                {
                    var datas = data.datas;
                    isLoad = false;
                    if (data.code !== 200) {
                        alert(data.message);
                    }
                    for (var i = 0; i < datas.answers.length; i++)
                    {
                        if (index < 4) {
                            new Item($('.other_bonus_reslut'), index, datas.answers[i], true).exportHTML();
                        }
                        else {
                            new Item($('.other_bonus_reslut'), index, datas.answers[i]).exportHTML();
                        }
                        index++;
                    }

                    if (datas['mobile_page'].hasmore) {
                        $(window).on('scroll',function(){
                            var scrollTop = $(this).scrollTop();
                            var scrollHeight = $(document).height();
                            var windowHeight = $(this).height();
                            if ((scrollTop + windowHeight) - scrollHeight > -250 && isLoad == false) {
                                getData();
                            }
                        });
                        page++;
                    }
                    else {
                        $(window).unbind('scroll');
                    }
                }
            });
        };

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