Authored by zzzzzzz

优惠券原始完成,待改进

'use strict';
const headerModel = require('../../../doraemon/models/header'); // 头部model
const headerModel = require('../../../doraemon/models/header'), // 头部model
model = require('../models/coupons');
const index = (req, res) => {
res.render('coupons', {
... ... @@ -13,7 +14,16 @@ const index = (req, res) => {
});
};
const couponData = (req, res) => {
const couponData = (req, res, next) => {
model.couponData({
method: 'app.coupons.li',
uid: 20000382,
status: req.body.status,
page: req.body.page || 1,
limit: 10,
}).then(result => {
res.send(result);
}).catch(next);
};
module.exports = {
... ...
"use strict";
const api = global.yoho.API;
const couponData = (params) => {
let used = (params.status === '1') ? '<i></i>' : '',
html = '';
return api.get('', params).then(result => {
if (result.data && result.data.info) {
for (let item of result.data.info) {
html += `<div class="employ-main">
<span>${item.money}</span>
<p class="coupon-name">${item.coupon_name}</p>
<p>有效期:${item.couponValidity}</p>
${used}
</div>`;
}
return html;
} else {
return `<div class="null">
<i></i>
<p>您还没有优惠券!</p>
<a href="/product/new">随便逛逛</a>
</div>`
}
});
}
module.exports = {
couponData
}
\ No newline at end of file
... ...
"use strict";
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer'),
ellipsis = require('yoho-mlellipsis'),
... ... @@ -5,12 +7,44 @@ var $ = require('yoho-jquery'),
var employ,
statu = 0,
page = 1;
page = 1,
//防止重复请求
AjaxFlag = 0,
//上滑不请求
direction = true;
require('../common');
ellipsis.init();
//判断滑动方向
$('body').on('touchstart', function(e) {
var touch = e.originalEvent,
startX = touch.changedTouches[0].pageX,
startY = touch.changedTouches[0].pageY;
$('body').on('touchmove', function(e) {
touch = e.originalEvent.touches[0] ||
e.originalEvent.changedTouches[0];
if (touch.pageX - startX > 10) {
$('body').off('touchmove');
} else if (touch.pageX - startX < -10) {
$('body').off('touchmove');
};
if (touch.pageY - startY > 10) {
direction = false;
} else if (touch.pageY - startY < -10) {
direction = true;
};
});
}).on('touchend', function() {
$('body').off('touchmove');
});
function couponAJAX(statu, page) {
return;
if (AjaxFlag) {
return;
}
AjaxFlag = 1;
loading.showLoadingMask();
$.ajax({
type: 'POST',
... ... @@ -24,6 +58,7 @@ function couponAJAX(statu, page) {
$('#employ').append(data);
window.rePosFooter();
loading.hideLoadingMask();
AjaxFlag = 0;
}
});
}
... ... @@ -43,7 +78,7 @@ $('.employ span').each(function(index) {
function scrollHandler() {
if ($(window).scrollTop() + $(window).height() > $('body').height() - 100) {
if (direction && ($(window).scrollTop() + $(window).height() > $('body').height() - 100)) {
page++;
couponAJAX(statu, page);
return;
... ... @@ -54,4 +89,4 @@ $(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
couponAJAX(statu, page);
couponAJAX(statu, page);
\ No newline at end of file
... ...
... ... @@ -93,7 +93,7 @@
width: 100%;
height: auto;
overflow: hidden;
position: absolute;
position: fixed;
left: 0;
top: 50%;
transform: translateY(-50%);
... ...