Authored by 沈志敏

优惠券优化

... ... @@ -21,7 +21,10 @@ const index = (req, res, next) => {
title: '优惠券',
pageFooter: true,
list: result,
used: req.body.status === '1' ? true : false,
localCss: true
};
req.body.page && (req.body.page !== '1' || req.body.status === '1') && (options.layout = false);
res.render('coupons', options);
}).catch(next);
... ...
... ... @@ -6,12 +6,8 @@ const api = global.yoho.API;
const couponData = (params) => {
return api.get('', params).then(result => {
if (result && result.data && result.data.info) {
for (let item of result.data.info) {
item.used = ((params.status === '1') ? true : false);
}
return result.data.info;
}
else {
} else {
return 0;
}
});
... ...
... ... @@ -10,7 +10,7 @@
<span>{{money}}</span>
<p class="coupon-name">{{coupon_name}}</p>
<p>有效期:{{couponValidity}}</p>
{{#if used}}
{{#if ./used}}
<i></i>
{{/if}}
</div>
... ... @@ -25,4 +25,5 @@
{{/if}}
</div>
<div id="employ2" class="coupon-list">
</div>
\ No newline at end of file
... ...
// 不要使用es6
'use strict';
require('home/_coupons.css');
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer'),
ellipsis = require('yoho-mlellipsis'),
loading = require('../plugin/loading');
fastclick = require('yoho-fastclick'),
ellipsis = require('yoho-mlellipsis');
var employ,
var $employ = $('#employ'),
$employ2 = $('#employ2'),
statu = 0,
page = 1,
dic = {},
AjaxFlag = 0; // 防止重复请求
require('../common');
ellipsis.init();
// 防止重复请求
AjaxFlag = 0;
dic[statu + '_' + page] = true;
fastclick.attach(document.body);
var couponAJAX = function(statu, page) {
if (AjaxFlag) {
if (AjaxFlag || dic[statu + '_' + page]) {
return;
}
var employDom = statu === 0 ? $employ : $employ2;
AjaxFlag = 1;
loading.showLoadingMask();
$.ajax({
type: 'POST',
url: '/home/coupons',
... ... @@ -28,55 +35,50 @@ var couponAJAX = function(statu, page) {
page: page
},
success: function(data) {
dic[statu + '_' + page] = true; // tab切换时,防止频繁请求
if ($(data).find('.null').html()) {
page === 1 && $('#employ').append($(data).find('.null'));
if (page === 1) {
employDom.append($(data).find('.null'));
}
AjaxFlag = 1;
window.rePosFooter();
loading.hideLoadingMask();
return;
}
if (!$(data).find('.employ-main').html()) {
AjaxFlag = 1;
window.rePosFooter();
loading.hideLoadingMask();
return;
}
$('#employ').append($(data).find('.employ-main'));
window.rePosFooter();
loading.hideLoadingMask();
employDom.append($(data).find('.employ-main'));
AjaxFlag = 0;
}
});
};
var scrollHandler = function() {
if ($(window).scrollTop() + $(window).height() > $('body').height() - 100) {
page++;
couponAJAX(statu, page);
return;
}
};
require('../common');
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').each(function(index, el) {
$(el).on('click', function() {
$('.employ span').removeClass('active').eq(index).addClass('active');
$('#employ').html(' ');
if (index === 0) {
$employ.removeClass('hide');
$employ2.addClass('hide');
} else {
$employ.addClass('hide');
$employ2.removeClass('hide');
}
statu = index;
page = 1;
AjaxFlag = 0;
status === 1 && $('#employ').empty();
couponAJAX(statu, page);
window.rePosFooter();
});
});
var scrollHandler = function() {
if ($(window).scrollTop() + $(window).height() > $('body').height() - 100) {
page++;
couponAJAX(statu, page);
return;
}
};
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
... ...