Authored by zhangxiaoru

recom

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