my-reward.page.js 2.07 KB
'use strict';
require('activity/my-reward.page.css');

let $ = require('yoho-jquery'),
    yoho = require('yoho-app');

let page = 2,
    searching = false,
    winH = $(window).height();

// 获取推送消息开启状态
function getStatus() {

    yoho.invokeMethod('get.usernotificationstatus', {}, function(res) {
        if (parseInt(res, 10) === 1 || res === '1') {
            $('.state').find('b').html('已开启');
        } else if (parseInt(res, 10) === 0) {
            $('.state').find('b').html('去开启');
        }
    });
}

if (yoho.isApp) {

    // 提供给APP调取刷新
    yoho.ready(function() {
        yoho.addNativeMethod('refreshInfoPushState', function() {
            getStatus();
        });
    });
}

// 点击开启状态跳转APP设置
$('.state').click(function() {
    yoho.invokeMethod('go.appsetting');
});

// 活动规则展开与收起
$('.title').click(function() {
    if ($(this).find('i').hasClass('down')) {
        $('.detail').css('height', 'auto');
        $(this).find('i').removeClass('down').html('');
    } else {
        $('.detail').css('height', '0px');
        $(this).find('i').addClass('down').html('');
    }
});

// 奖励列表数据
function moreList() {
    if (searching) {
        return;
    }

    searching = true;

    $.ajax({
        type: 'GET',
        url: '/activity/reward-list',
        data: {
            page: page
        },
        success: function(data) {
            if (data === '') {
                return true;
            }

            $('.reward-list').append(data);

            searching = false;
            page++;
        },
    });
}

function scrollHandler() {

    // 当scroll到3/4$goodsContainer高度后继续请求下一页数据
    if ($(window).scrollTop() + winH >
        $(document).height() - 0.25 * $('.reward-list').height()) {
        moreList();
    }
}

// srcoll to load more
$(window).scroll(function() {
    window.requestAnimationFrame(scrollHandler);
});

$(function() {
    if (yoho.isApp) {
        yoho.ready(function() {
            getStatus();
        });
    }
});