Authored by zzzzzzz

修改优惠券

@@ -3,20 +3,8 @@ @@ -3,20 +3,8 @@
3 const headerModel = require('../../../doraemon/models/header'), // 头部model 3 const headerModel = require('../../../doraemon/models/header'), // 头部model
4 model = require('../models/coupons'); 4 model = require('../models/coupons');
5 5
6 -const index = (req, res) => {  
7 - res.render('coupons', {  
8 - module: 'home',  
9 - page: 'coupons',  
10 - pageHeader: headerModel.setNav({  
11 - navTitle: '优惠券'  
12 - }),  
13 - title: '优惠券',  
14 - pageFooter: true,  
15 - });  
16 -};  
17 -  
18 // 处理Ajax请求,status为使用状态 6 // 处理Ajax请求,status为使用状态
19 -const couponData = (req, res, next) => { 7 +const index = (req, res, next) => {
20 model.couponData({ 8 model.couponData({
21 method: 'app.coupons.li', 9 method: 'app.coupons.li',
22 uid: req.user.uid, 10 uid: req.user.uid,
@@ -24,12 +12,21 @@ const couponData = (req, res, next) => { @@ -24,12 +12,21 @@ const couponData = (req, res, next) => {
24 page: req.body.page || 1, 12 page: req.body.page || 1,
25 limit: 10, 13 limit: 10,
26 }).then(result => { 14 }).then(result => {
27 - res.send(result);  
28 - res.end(); 15 + let options = {
  16 + module: 'home',
  17 + page: 'coupons',
  18 + pageHeader: headerModel.setNav({
  19 + navTitle: '优惠券'
  20 + }),
  21 + title: '优惠券',
  22 + pageFooter: true,
  23 + list: result,
  24 + };
  25 + req.body.page && (req.body.page !== '1' || req.body.status === '1') && (options.layout = false);
  26 + res.render('coupons', options);
29 }).catch(next); 27 }).catch(next);
30 }; 28 };
31 29
32 module.exports = { 30 module.exports = {
33 index, 31 index,
34 - couponData  
35 -}; 32 +};
@@ -4,26 +4,15 @@ @@ -4,26 +4,15 @@
4 const api = global.yoho.API; 4 const api = global.yoho.API;
5 5
6 const couponData = (params) => { 6 const couponData = (params) => {
7 - let used = (params.status === '1') ? '<i></i>' : '',  
8 - html = '';  
9 -  
10 return api.get('', params).then(result => { 7 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>`; 8 + if(result && result.data && result.data.info){
  9 + for(let item of result.data.info){
  10 + item.used = ((params.status === '1') ? true : false);
19 } 11 }
20 - return html;  
21 - } else {  
22 - return `<div class="null">  
23 - <i></i>  
24 - <p>您还没有优惠券!</p>  
25 - <a href="/product/new">随便逛逛</a>  
26 - </div>`; 12 + return result.data.info;
  13 + }
  14 + else{
  15 + return 0;
27 } 16 }
28 }); 17 });
29 }; 18 };
@@ -72,8 +72,7 @@ router.get('/favBrand', favorite.favfavBrand); @@ -72,8 +72,7 @@ router.get('/favBrand', favorite.favfavBrand);
72 router.post('/favoriteDel', favorite.favoriteDelete); 72 router.post('/favoriteDel', favorite.favoriteDelete);
73 73
74 // 优惠券 74 // 优惠券
75 -router.get('/coupons', auth, coupons.index);  
76 -router.post('/couponData', coupons.couponData); 75 +router.use('/coupons', coupons.index);
77 76
78 // 帮助中心 77 // 帮助中心
79 router.get('/help', help.index); 78 router.get('/help', help.index);
@@ -3,5 +3,26 @@ @@ -3,5 +3,26 @@
3 <span class="active">未使用</span> 3 <span class="active">未使用</span>
4 <span>已使用</span> 4 <span>已使用</span>
5 </div> 5 </div>
6 - <div id="employ" class="coupon-list"></div> 6 + <div id="employ" class="coupon-list">
  7 + {{#if list}}
  8 + {{#list}}
  9 + <div class="employ-main">
  10 + <span>{{money}}</span>
  11 + <p class="coupon-name">{{coupon_name}}</p>
  12 + <p>有效期:{{couponValidity}}</p>
  13 + {{#if used}}
  14 + <i></i>
  15 + {{/if}}
  16 + </div>
  17 + {{/list}}
  18 +
  19 + {{else}}
  20 + <div class="null">
  21 + <i></i>
  22 + <p>您还没有优惠券!</p>
  23 + <a href="/product/new">随便逛逛</a>
  24 + </div>
  25 +
  26 + {{/if}}
  27 + </div>
7 </div> 28 </div>
@@ -21,20 +21,27 @@ var couponAJAX = function(statu, page) { @@ -21,20 +21,27 @@ var couponAJAX = function(statu, page) {
21 loading.showLoadingMask(); 21 loading.showLoadingMask();
22 $.ajax({ 22 $.ajax({
23 type: 'POST', 23 type: 'POST',
24 - url: '/home/couponData', 24 + url: '/home/coupons',
25 dataType: 'html', 25 dataType: 'html',
26 data: { 26 data: {
27 status: statu, 27 status: statu,
28 page: page 28 page: page
29 }, 29 },
30 success: function(data) { 30 success: function(data) {
31 - if (!data) { 31 + if ($(data).find('.null').html()) {
  32 + page === 1 && $('#employ').append($(data).find('.null'));
32 AjaxFlag = 1; 33 AjaxFlag = 1;
33 window.rePosFooter(); 34 window.rePosFooter();
34 loading.hideLoadingMask(); 35 loading.hideLoadingMask();
35 return; 36 return;
36 } 37 }
37 - $('#employ').append(data); 38 + if (!$(data).find('.employ-main').html()) {
  39 + AjaxFlag = 1;
  40 + window.rePosFooter();
  41 + loading.hideLoadingMask();
  42 + return;
  43 + }
  44 + $('#employ').append($(data).find('.employ-main'));
38 window.rePosFooter(); 45 window.rePosFooter();
39 loading.hideLoadingMask(); 46 loading.hideLoadingMask();
40 AjaxFlag = 0; 47 AjaxFlag = 0;
@@ -64,6 +71,7 @@ $('.employ span').each(function(index) { @@ -64,6 +71,7 @@ $('.employ span').each(function(index) {
64 statu = index; 71 statu = index;
65 page = 1; 72 page = 1;
66 AjaxFlag = 0; 73 AjaxFlag = 0;
  74 + status === 1 && $('#employ').empty();
67 couponAJAX(statu, page); 75 couponAJAX(statu, page);
68 window.rePosFooter(); 76 window.rePosFooter();
69 }); 77 });
@@ -72,5 +80,3 @@ $('.employ span').each(function(index) { @@ -72,5 +80,3 @@ $('.employ span').each(function(index) {
72 $(window).scroll(function() { 80 $(window).scroll(function() {
73 window.requestAnimationFrame(scrollHandler); 81 window.requestAnimationFrame(scrollHandler);
74 }); 82 });
75 -  
76 -couponAJAX(statu, page);