Authored by zzzzzzz

个人中心消息重构

@@ -19,6 +19,7 @@ const _getList = (req, res, next) => { @@ -19,6 +19,7 @@ const _getList = (req, res, next) => {
19 pageFooter: true, 19 pageFooter: true,
20 list: result, 20 list: result,
21 }; 21 };
  22 +
22 req.body.page && req.body.page !== '1' && (options.layout = false); 23 req.body.page && req.body.page !== '1' && (options.layout = false);
23 res.render('message', options); 24 res.render('message', options);
24 }).catch(next); 25 }).catch(next);
@@ -32,6 +33,8 @@ const _msgDetail = (req, res, next) => { @@ -32,6 +33,8 @@ const _msgDetail = (req, res, next) => {
32 uid: req.user.uid, 33 uid: req.user.uid,
33 }).then(result => { 34 }).then(result => {
34 let options = { 35 let options = {
  36 + module: 'home',
  37 + page: 'message',
35 pageHeader: headerModel.setNav({ 38 pageHeader: headerModel.setNav({
36 navTitle: '我的消息' 39 navTitle: '我的消息'
37 }), 40 }),
@@ -39,6 +42,7 @@ const _msgDetail = (req, res, next) => { @@ -39,6 +42,7 @@ const _msgDetail = (req, res, next) => {
39 pageFooter: true, 42 pageFooter: true,
40 info: result, 43 info: result,
41 }; 44 };
  45 +
42 res.render('message-detail', options); 46 res.render('message-detail', options);
43 }).catch(next); 47 }).catch(next);
44 }; 48 };
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 3
4 const moment = require('moment'); 4 const moment = require('moment');
5 const api = global.yoho.API; 5 const api = global.yoho.API;
  6 +const helpers = global.yoho.helpers;
6 7
7 // 格式化时间 8 // 格式化时间
8 const _formatTime = (time) => { 9 const _formatTime = (time) => {
@@ -12,6 +13,7 @@ const _formatTime = (time) => { @@ -12,6 +13,7 @@ const _formatTime = (time) => {
12 // 获取列表页 13 // 获取列表页
13 const _list = (result) => { 14 const _list = (result) => {
14 let final = []; 15 let final = [];
  16 +
15 if (result.data && result.data.list) { 17 if (result.data && result.data.list) {
16 // PHP排序了,应该不用 18 // PHP排序了,应该不用
17 for (let item of result.data.list) { 19 for (let item of result.data.list) {
@@ -28,31 +30,23 @@ const _list = (result) => { @@ -28,31 +30,23 @@ const _list = (result) => {
28 30
29 // 获取生日信息 31 // 获取生日信息
30 const _getBirthCouponById = (uid) => { 32 const _getBirthCouponById = (uid) => {
31 - let arr = [];  
32 return api.get('', { 33 return api.get('', {
33 method: 'app.promotion.queryBirthCoupon', 34 method: 'app.promotion.queryBirthCoupon',
34 uid: uid, 35 uid: uid,
35 couponType: 4, 36 couponType: 4,
36 }).then(result => { 37 }).then(result => {
37 - if (result && result['data']) {  
38 - for (let item of result['data']) {  
39 - arr.push({  
40 - 'id': item['id'] ? item['id'] : '',  
41 - 'remark': item['couponName'] ? item['couponName'] : '',  
42 -  
43 - // 'useTime': item['body']['use_time'] ? item['body']['use_time'] : '',  
44 - // 'pickTime': item['body']['collar_time'] ? item['body']['collar_time'] : '',  
45 - 'canPick': true  
46 - });  
47 - } 38 + if (result && result.data) {
  39 + return result.data;
  40 + } else {
  41 + return [];
48 } 42 }
49 - return arr;  
50 }); 43 });
51 }; 44 };
52 45
53 // 获取详情页 46 // 获取详情页
54 const _detail = (result, id, couponData) => { 47 const _detail = (result, id, couponData) => {
55 let final = {}; 48 let final = {};
  49 +
56 if (result.data && result.data.list) { 50 if (result.data && result.data.list) {
57 for (let item of result.data.list) { 51 for (let item of result.data.list) {
58 if (item.id === Number(id) && item.type !== 'showGetCoin' && item.type !== 'notice') { 52 if (item.id === Number(id) && item.type !== 'showGetCoin' && item.type !== 'notice') {
@@ -61,35 +55,46 @@ const _detail = (result, id, couponData) => { @@ -61,35 +55,46 @@ const _detail = (result, id, couponData) => {
61 final.time = `${item.create_date} ${_formatTime(item.create_time * 1000)}`; // 时间 55 final.time = `${item.create_date} ${_formatTime(item.create_time * 1000)}`; // 时间
62 56
63 // 判断消息类型 57 // 判断消息类型
64 - switch (item['type']) { 58 + switch (item.type) {
65 case 'pullCoupon': 59 case 'pullCoupon':
66 // 领取生日券消息 60 // 领取生日券消息
67 - final['coupons'] = couponData; // 获取优惠券信息 61 + final.coupons = [];
  62 + for (let coupon of couponData) {
  63 + final.coupons.push({
  64 + id: coupon.id ? coupon.id : '',
  65 + remark: coupon.couponName ? coupon.couponName : '',
  66 + useTime: item.body.use_time ? item.body.use_time : '',
  67 + pickTime: item.body.collar_time ? item.body.collar_time : '',
  68 + canPick: true
  69 + });
  70 + }
68 break; 71 break;
69 case 'button': 72 case 'button':
70 // 促销活动 73 // 促销活动
71 - final['sale'] = {  
72 - 'image': item['body']['image'] ? item['body']['image'] : '',  
73 - 'content': item['body']['text'] ? item['body']['text'] : '',  
74 - 'btnLink': item['body']['pc_link'] ? item['body']['pc_link'] : '',  
75 - 'btnName': item['body']['button_text'] ? item['body']['button_text'] : '', 74 + final.sale = {
  75 + image: item.body.image ? item.body.image : '',
  76 + content: item.body.text ? item.body.text : '',
  77 + btnLink: item.body.pc_link ? item.body.pc_link : '',
  78 + btnName: item.body.button_text ? item.body.button_text : '',
76 }; 79 };
77 break; 80 break;
78 case 'pushCoupon': 81 case 'pushCoupon':
79 // 查看优惠券 82 // 查看优惠券
80 - final['coupons'] = [];  
81 - final['coupons'].push({  
82 - 'remark': item['body']['coupon_name'] ? item['body']['coupon_name'] : '',  
83 - 'useTime': item['body']['time'] ? item['body']['time'] : '',  
84 - 'id': item['body']['inboxId'] ? item['body']['inboxId'] : '',  
85 - 'price': item['body']['price'] ? item['body']['price'] : '',  
86 - //'url' : Helpers::url('/home/coupons', array('t' => microtime(true))) 83 + final.coupons = [];
  84 + final.coupons.push({
  85 + remark: item.body.coupon_name ? item.body.coupon_name : '',
  86 + useTime: item.body.time ? item.body.time : '',
  87 + id: item.body.inboxId ? item.body.inboxId : '',
  88 + price: item.body.price ? item.body.price : '',
  89 + url: helpers.urlFormat('/home/coupons', {
  90 + t: (new Date().getTime()) / 1000,
  91 + }),
87 }); 92 });
88 break; 93 break;
89 default: 94 default:
90 // 普通文本 95 // 普通文本
91 - final['text'] = {  
92 - 'content': item['body']['content'] ? item['body']['content'] : '', 96 + final.text = {
  97 + content: item.body.content ? item.body.content : '',
93 }; 98 };
94 break; 99 break;
95 } 100 }
@@ -105,11 +110,11 @@ const getList = (params) => { @@ -105,11 +110,11 @@ const getList = (params) => {
105 method: 'app.inbox.getlist', 110 method: 'app.inbox.getlist',
106 page: params.page || 1, 111 page: params.page || 1,
107 size: params.size || 10, 112 size: params.size || 10,
108 - uid: params.uid || 123, 113 + uid: params.uid,
109 }).then(result => { 114 }).then(result => {
110 if (params.msgid) { 115 if (params.msgid) {
111 // 绕的一比 116 // 绕的一比
112 - return _getBirthCouponById(params.uid || 20000382).then(couponData => { 117 + return _getBirthCouponById(params.uid).then(couponData => {
113 return _detail(result, params.msgid, couponData); 118 return _detail(result, params.msgid, couponData);
114 }); 119 });
115 } else { 120 } else {
@@ -122,15 +127,14 @@ const getList = (params) => { @@ -122,15 +127,14 @@ const getList = (params) => {
122 const delMsg = (params) => { 127 const delMsg = (params) => {
123 return api.get('', { 128 return api.get('', {
124 method: 'app.inbox.delmessage', 129 method: 'app.inbox.delmessage',
125 - uid: params.uid || 20000382, 130 + uid: params.uid,
126 id: params.msgid, 131 id: params.msgid,
127 }).then(result => { 132 }).then(result => {
128 if (result && result.code === 200) { 133 if (result && result.code === 200) {
129 return { 134 return {
130 code: 200 135 code: 200
131 }; 136 };
132 - }  
133 - else { 137 + } else {
134 return { 138 return {
135 code: 400, 139 code: 400,
136 message: '出错啦~', 140 message: '出错啦~',
@@ -143,24 +147,17 @@ const delMsg = (params) => { @@ -143,24 +147,17 @@ const delMsg = (params) => {
143 const pickCoupon = (params) => { 147 const pickCoupon = (params) => {
144 return api.get('', { 148 return api.get('', {
145 method: 'app.promotion.getCoupon', 149 method: 'app.promotion.getCoupon',
146 - uid: params.uid || 20000382, 150 + uid: params.uid,
147 couponId: params.couponId, 151 couponId: params.couponId,
148 }).then(result => { 152 }).then(result => {
149 if (result && result.code === 200) { 153 if (result && result.code === 200) {
150 return { 154 return {
151 code: 200 155 code: 200
152 }; 156 };
153 - }  
154 - else if (result.code === 401) {  
155 - return {  
156 - code: 401,  
157 - message: '优惠券已经领取',  
158 - };  
159 - }  
160 - else { 157 + } else {
161 return { 158 return {
162 - code: 400,  
163 - message: '出错啦~', 159 + code: result.code,
  160 + message: result.message,
164 }; 161 };
165 } 162 }
166 }); 163 });
@@ -72,7 +72,7 @@ router.get('/favBrand', favorite.favfavBrand); @@ -72,7 +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.use('/coupons', coupons.index); 75 +router.use('/coupons', auth, coupons.index);
76 76
77 // 帮助中心 77 // 帮助中心
78 router.get('/help', help.index); 78 router.get('/help', help.index);
@@ -88,8 +88,9 @@ router.post('/savesuggest', suggest.saveSuggest); @@ -88,8 +88,9 @@ router.post('/savesuggest', suggest.saveSuggest);
88 88
89 89
90 // 消息 90 // 消息
91 -router.use('/message', message.index);  
92 -router.post('/ajaxDelMes', message.ajaxDelMes);  
93 -router.post('/pickCoupon', message.pickCoupon); 91 +router.use('/message', auth, message.index);
  92 +router.get('/messageDetail', auth, message.index);
  93 +router.post('/ajaxDelMes', auth, message.ajaxDelMes);
  94 +router.post('/pickCoupon', auth, message.pickCoupon);
94 95
95 module.exports = router; 96 module.exports = router;
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 {{#if isNotReaded}} 5 {{#if isNotReaded}}
6 <strong></strong> 6 <strong></strong>
7 {{/if}} 7 {{/if}}
8 - <p><a href="//m.yohobuy.com/home/message?id={{id}}">{{title}}</a></p> 8 + <p><a href="//m.yohobuy.com/home/messageDetail?id={{id}}">{{title}}</a></p>
9 <span>{{time}}</span> 9 <span>{{time}}</span>
10 <i class="iconfont del">&#xe621;</i> 10 <i class="iconfont del">&#xe621;</i>
11 </div> 11 </div>
1 -// 消息列表 by acgpiano 1 +// 消息列表 by acgpiano
2 2
3 var $ = require('yoho-jquery'), 3 var $ = require('yoho-jquery'),
4 loading = require('../plugin/loading'), 4 loading = require('../plugin/loading'),
5 dialog = require('./dialog'); 5 dialog = require('./dialog');
6 6
7 var $page = $('.massage-page'), 7 var $page = $('.massage-page'),
8 - page = 1,  
9 - stopLoading = false; 8 + page = 1,
  9 + stopLoading = false,
  10 + pickBusy = false;
10 11
11 -function massageAJAX(page) { 12 +function massageAJAX(pageNum) {
12 loading.showLoadingMask(); 13 loading.showLoadingMask();
13 $.ajax({ 14 $.ajax({
14 type: 'POST', 15 type: 'POST',
15 url: '/home/message', 16 url: '/home/message',
16 dataType: 'html', 17 dataType: 'html',
17 data: { 18 data: {
18 - page: page, 19 + page: pageNum,
19 }, 20 },
20 success: function(data) { 21 success: function(data) {
21 if ($(data).find('p').html() === '您没有消息') { 22 if ($(data).find('p').html() === '您没有消息') {
@@ -86,19 +87,15 @@ $page.on('touchstart', '.del', function() { @@ -86,19 +87,15 @@ $page.on('touchstart', '.del', function() {
86 }); 87 });
87 }); 88 });
88 89
89 -var $page = $('.massage-page');  
90 -  
91 -var pickBusy = false;  
92 -  
93 // 领取生日券 90 // 领取生日券
94 $page.on('touchstart', '.pick-coupon-btn', function() { 91 $page.on('touchstart', '.pick-coupon-btn', function() {
  92 + var $id = $(this).data('id');
  93 +
95 if (pickBusy) { 94 if (pickBusy) {
96 return; 95 return;
97 } 96 }
98 pickBusy = true; 97 pickBusy = true;
99 98
100 - var $id = $(this).data('id');  
101 -  
102 $.ajax({ 99 $.ajax({
103 type: 'POST', 100 type: 'POST',
104 url: '/home/pickCoupon', 101 url: '/home/pickCoupon',