Authored by zzzzzzz

优惠券原始完成,待改进

1 'use strict'; 1 'use strict';
2 -const headerModel = require('../../../doraemon/models/header'); // 头部model 2 +const headerModel = require('../../../doraemon/models/header'), // 头部model
  3 + model = require('../models/coupons');
3 4
4 const index = (req, res) => { 5 const index = (req, res) => {
5 res.render('coupons', { 6 res.render('coupons', {
@@ -13,7 +14,16 @@ const index = (req, res) => { @@ -13,7 +14,16 @@ const index = (req, res) => {
13 }); 14 });
14 }; 15 };
15 16
16 -const couponData = (req, res) => { 17 +const couponData = (req, res, next) => {
  18 + model.couponData({
  19 + method: 'app.coupons.li',
  20 + uid: 20000382,
  21 + status: req.body.status,
  22 + page: req.body.page || 1,
  23 + limit: 10,
  24 + }).then(result => {
  25 + res.send(result);
  26 + }).catch(next);
17 }; 27 };
18 28
19 module.exports = { 29 module.exports = {
  1 +"use strict";
  2 +
  3 +const api = global.yoho.API;
  4 +
  5 +const couponData = (params) => {
  6 + let used = (params.status === '1') ? '<i></i>' : '',
  7 + html = '';
  8 + return api.get('', params).then(result => {
  9 + if (result.data && result.data.info) {
  10 + for (let item of result.data.info) {
  11 + html += `<div class="employ-main">
  12 + <span>${item.money}</span>
  13 + <p class="coupon-name">${item.coupon_name}</p>
  14 + <p>有效期:${item.couponValidity}</p>
  15 + ${used}
  16 + </div>`;
  17 + }
  18 + return html;
  19 + } else {
  20 + return `<div class="null">
  21 + <i></i>
  22 + <p>您还没有优惠券!</p>
  23 + <a href="/product/new">随便逛逛</a>
  24 + </div>`
  25 + }
  26 + });
  27 +}
  28 +
  29 +module.exports = {
  30 + couponData
  31 +}
  1 +"use strict";
  2 +
1 var $ = require('yoho-jquery'), 3 var $ = require('yoho-jquery'),
2 Hammer = require('yoho-hammer'), 4 Hammer = require('yoho-hammer'),
3 ellipsis = require('yoho-mlellipsis'), 5 ellipsis = require('yoho-mlellipsis'),
@@ -5,12 +7,44 @@ var $ = require('yoho-jquery'), @@ -5,12 +7,44 @@ var $ = require('yoho-jquery'),
5 7
6 var employ, 8 var employ,
7 statu = 0, 9 statu = 0,
8 - page = 1; 10 + page = 1,
  11 + //防止重复请求
  12 + AjaxFlag = 0,
  13 + //上滑不请求
  14 + direction = true;
  15 +
  16 +require('../common');
9 17
10 ellipsis.init(); 18 ellipsis.init();
11 19
  20 +//判断滑动方向
  21 +$('body').on('touchstart', function(e) {
  22 + var touch = e.originalEvent,
  23 + startX = touch.changedTouches[0].pageX,
  24 + startY = touch.changedTouches[0].pageY;
  25 + $('body').on('touchmove', function(e) {
  26 + touch = e.originalEvent.touches[0] ||
  27 + e.originalEvent.changedTouches[0];
  28 + if (touch.pageX - startX > 10) {
  29 + $('body').off('touchmove');
  30 + } else if (touch.pageX - startX < -10) {
  31 + $('body').off('touchmove');
  32 + };
  33 + if (touch.pageY - startY > 10) {
  34 + direction = false;
  35 + } else if (touch.pageY - startY < -10) {
  36 + direction = true;
  37 + };
  38 + });
  39 +}).on('touchend', function() {
  40 + $('body').off('touchmove');
  41 +});
  42 +
12 function couponAJAX(statu, page) { 43 function couponAJAX(statu, page) {
13 - return; 44 + if (AjaxFlag) {
  45 + return;
  46 + }
  47 + AjaxFlag = 1;
14 loading.showLoadingMask(); 48 loading.showLoadingMask();
15 $.ajax({ 49 $.ajax({
16 type: 'POST', 50 type: 'POST',
@@ -24,6 +58,7 @@ function couponAJAX(statu, page) { @@ -24,6 +58,7 @@ function couponAJAX(statu, page) {
24 $('#employ').append(data); 58 $('#employ').append(data);
25 window.rePosFooter(); 59 window.rePosFooter();
26 loading.hideLoadingMask(); 60 loading.hideLoadingMask();
  61 + AjaxFlag = 0;
27 } 62 }
28 }); 63 });
29 } 64 }
@@ -43,7 +78,7 @@ $('.employ span').each(function(index) { @@ -43,7 +78,7 @@ $('.employ span').each(function(index) {
43 78
44 79
45 function scrollHandler() { 80 function scrollHandler() {
46 - if ($(window).scrollTop() + $(window).height() > $('body').height() - 100) { 81 + if (direction && ($(window).scrollTop() + $(window).height() > $('body').height() - 100)) {
47 page++; 82 page++;
48 couponAJAX(statu, page); 83 couponAJAX(statu, page);
49 return; 84 return;
@@ -54,4 +89,4 @@ $(window).scroll(function() { @@ -54,4 +89,4 @@ $(window).scroll(function() {
54 window.requestAnimationFrame(scrollHandler); 89 window.requestAnimationFrame(scrollHandler);
55 }); 90 });
56 91
57 -couponAJAX(statu, page); 92 +couponAJAX(statu, page);
@@ -93,7 +93,7 @@ @@ -93,7 +93,7 @@
93 width: 100%; 93 width: 100%;
94 height: auto; 94 height: auto;
95 overflow: hidden; 95 overflow: hidden;
96 - position: absolute; 96 + position: fixed;
97 left: 0; 97 left: 0;
98 top: 50%; 98 top: 50%;
99 transform: translateY(-50%); 99 transform: translateY(-50%);