Blame view

public/js/home/coupons.page.js 2.02 KB
zhangxiaoru authored
1 2
// 不要使用es6
'use strict';
3
zzzzzzz authored
4 5 6 7 8 9 10
var $ = require('yoho-jquery'),
    Hammer = require('yoho-hammer'),
    ellipsis = require('yoho-mlellipsis'),
    loading = require('../plugin/loading');

var employ,
    statu = 0,
11
    page = 1,
zhangxiaoru authored
12 13

    // 防止重复请求
zzzzzzz authored
14
    AjaxFlag = 0;
15
zzzzzzz authored
16 17 18 19 20 21 22 23
var couponAJAX = function(statu, page) {
    if (AjaxFlag) {
        return;
    }
    AjaxFlag = 1;
    loading.showLoadingMask();
    $.ajax({
        type: 'POST',
zzzzzzz authored
24
        url: '/home/coupons',
zzzzzzz authored
25 26 27 28 29 30
        dataType: 'html',
        data: {
            status: statu,
            page: page
        },
        success: function(data) {
zzzzzzz authored
31 32
            if ($(data).find('.null').html()) {
                page === 1 && $('#employ').append($(data).find('.null'));
zzzzzzz authored
33 34 35 36 37
                AjaxFlag = 1;
                window.rePosFooter();
                loading.hideLoadingMask();
                return;
            }
zzzzzzz authored
38 39 40 41 42 43 44
            if (!$(data).find('.employ-main').html()) {
                AjaxFlag = 1;
                window.rePosFooter();
                loading.hideLoadingMask();
                return;
            }
            $('#employ').append($(data).find('.employ-main'));
zzzzzzz authored
45 46 47 48 49
            window.rePosFooter();
            loading.hideLoadingMask();
            AjaxFlag = 0;
        }
    });
zhangxiaoru authored
50
};
zzzzzzz authored
51 52

var scrollHandler = function() {
zzzzzzz authored
53
    if ($(window).scrollTop() + $(window).height() > $('body').height() - 100) {
zzzzzzz authored
54 55 56 57
        page++;
        couponAJAX(statu, page);
        return;
    }
zhangxiaoru authored
58
};
zzzzzzz authored
59 60

61
require('../common');
zzzzzzz authored
62 63 64 65 66 67 68 69 70 71 72

ellipsis.init();

$('.yoho-footer').css('border-top', '1px solid #e0e0e0');
$('.employ span').each(function(index) {
    employ = new Hammer($('.employ span')[index]);
    employ.on('tap', function(e) {
        $('.employ span').removeClass('active').eq(index).addClass('active');
        $('#employ').html(' ');
        statu = index;
        page = 1;
zzzzzzz authored
73
        AjaxFlag = 0;
zzzzzzz authored
74
        status === 1 && $('#employ').empty();
zzzzzzz authored
75 76 77 78 79 80 81 82
        couponAJAX(statu, page);
        window.rePosFooter();
    });
});

$(window).scroll(function() {
    window.requestAnimationFrame(scrollHandler);
});