Authored by zzzzzzz

个人中心消息重构

... ... @@ -19,6 +19,7 @@ const _getList = (req, res, next) => {
pageFooter: true,
list: result,
};
req.body.page && req.body.page !== '1' && (options.layout = false);
res.render('message', options);
}).catch(next);
... ... @@ -32,6 +33,8 @@ const _msgDetail = (req, res, next) => {
uid: req.user.uid,
}).then(result => {
let options = {
module: 'home',
page: 'message',
pageHeader: headerModel.setNav({
navTitle: '我的消息'
}),
... ... @@ -39,6 +42,7 @@ const _msgDetail = (req, res, next) => {
pageFooter: true,
info: result,
};
res.render('message-detail', options);
}).catch(next);
};
... ...
... ... @@ -3,6 +3,7 @@
const moment = require('moment');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
// 格式化时间
const _formatTime = (time) => {
... ... @@ -12,6 +13,7 @@ const _formatTime = (time) => {
// 获取列表页
const _list = (result) => {
let final = [];
if (result.data && result.data.list) {
// PHP排序了,应该不用
for (let item of result.data.list) {
... ... @@ -28,31 +30,23 @@ const _list = (result) => {
// 获取生日信息
const _getBirthCouponById = (uid) => {
let arr = [];
return api.get('', {
method: 'app.promotion.queryBirthCoupon',
uid: uid,
couponType: 4,
}).then(result => {
if (result && result['data']) {
for (let item of result['data']) {
arr.push({
'id': item['id'] ? item['id'] : '',
'remark': item['couponName'] ? item['couponName'] : '',
// 'useTime': item['body']['use_time'] ? item['body']['use_time'] : '',
// 'pickTime': item['body']['collar_time'] ? item['body']['collar_time'] : '',
'canPick': true
});
}
if (result && result.data) {
return result.data;
} else {
return [];
}
return arr;
});
};
// 获取详情页
const _detail = (result, id, couponData) => {
let final = {};
if (result.data && result.data.list) {
for (let item of result.data.list) {
if (item.id === Number(id) && item.type !== 'showGetCoin' && item.type !== 'notice') {
... ... @@ -61,35 +55,46 @@ const _detail = (result, id, couponData) => {
final.time = `${item.create_date} ${_formatTime(item.create_time * 1000)}`; // 时间
// 判断消息类型
switch (item['type']) {
switch (item.type) {
case 'pullCoupon':
// 领取生日券消息
final['coupons'] = couponData; // 获取优惠券信息
final.coupons = [];
for (let coupon of couponData) {
final.coupons.push({
id: coupon.id ? coupon.id : '',
remark: coupon.couponName ? coupon.couponName : '',
useTime: item.body.use_time ? item.body.use_time : '',
pickTime: item.body.collar_time ? item.body.collar_time : '',
canPick: true
});
}
break;
case 'button':
// 促销活动
final['sale'] = {
'image': item['body']['image'] ? item['body']['image'] : '',
'content': item['body']['text'] ? item['body']['text'] : '',
'btnLink': item['body']['pc_link'] ? item['body']['pc_link'] : '',
'btnName': item['body']['button_text'] ? item['body']['button_text'] : '',
final.sale = {
image: item.body.image ? item.body.image : '',
content: item.body.text ? item.body.text : '',
btnLink: item.body.pc_link ? item.body.pc_link : '',
btnName: item.body.button_text ? item.body.button_text : '',
};
break;
case 'pushCoupon':
// 查看优惠券
final['coupons'] = [];
final['coupons'].push({
'remark': item['body']['coupon_name'] ? item['body']['coupon_name'] : '',
'useTime': item['body']['time'] ? item['body']['time'] : '',
'id': item['body']['inboxId'] ? item['body']['inboxId'] : '',
'price': item['body']['price'] ? item['body']['price'] : '',
//'url' : Helpers::url('/home/coupons', array('t' => microtime(true)))
final.coupons = [];
final.coupons.push({
remark: item.body.coupon_name ? item.body.coupon_name : '',
useTime: item.body.time ? item.body.time : '',
id: item.body.inboxId ? item.body.inboxId : '',
price: item.body.price ? item.body.price : '',
url: helpers.urlFormat('/home/coupons', {
t: (new Date().getTime()) / 1000,
}),
});
break;
default:
// 普通文本
final['text'] = {
'content': item['body']['content'] ? item['body']['content'] : '',
final.text = {
content: item.body.content ? item.body.content : '',
};
break;
}
... ... @@ -105,11 +110,11 @@ const getList = (params) => {
method: 'app.inbox.getlist',
page: params.page || 1,
size: params.size || 10,
uid: params.uid || 123,
uid: params.uid,
}).then(result => {
if (params.msgid) {
// 绕的一比
return _getBirthCouponById(params.uid || 20000382).then(couponData => {
return _getBirthCouponById(params.uid).then(couponData => {
return _detail(result, params.msgid, couponData);
});
} else {
... ... @@ -122,15 +127,14 @@ const getList = (params) => {
const delMsg = (params) => {
return api.get('', {
method: 'app.inbox.delmessage',
uid: params.uid || 20000382,
uid: params.uid,
id: params.msgid,
}).then(result => {
if (result && result.code === 200) {
return {
code: 200
};
}
else {
} else {
return {
code: 400,
message: '出错啦~',
... ... @@ -143,24 +147,17 @@ const delMsg = (params) => {
const pickCoupon = (params) => {
return api.get('', {
method: 'app.promotion.getCoupon',
uid: params.uid || 20000382,
uid: params.uid,
couponId: params.couponId,
}).then(result => {
if (result && result.code === 200) {
return {
code: 200
};
}
else if (result.code === 401) {
return {
code: 401,
message: '优惠券已经领取',
};
}
else {
} else {
return {
code: 400,
message: '出错啦~',
code: result.code,
message: result.message,
};
}
});
... ...
... ... @@ -72,7 +72,7 @@ router.get('/favBrand', favorite.favfavBrand);
router.post('/favoriteDel', favorite.favoriteDelete);
// 优惠券
router.use('/coupons', coupons.index);
router.use('/coupons', auth, coupons.index);
// 帮助中心
router.get('/help', help.index);
... ... @@ -88,8 +88,9 @@ router.post('/savesuggest', suggest.saveSuggest);
// 消息
router.use('/message', message.index);
router.post('/ajaxDelMes', message.ajaxDelMes);
router.post('/pickCoupon', message.pickCoupon);
router.use('/message', auth, message.index);
router.get('/messageDetail', auth, message.index);
router.post('/ajaxDelMes', auth, message.ajaxDelMes);
router.post('/pickCoupon', auth, message.pickCoupon);
module.exports = router;
... ...
... ... @@ -5,7 +5,7 @@
{{#if isNotReaded}}
<strong></strong>
{{/if}}
<p><a href="//m.yohobuy.com/home/message?id={{id}}">{{title}}</a></p>
<p><a href="//m.yohobuy.com/home/messageDetail?id={{id}}">{{title}}</a></p>
<span>{{time}}</span>
<i class="iconfont del">&#xe621;</i>
</div>
... ...
// 消息列表 by acgpiano
// 消息列表 by acgpiano
var $ = require('yoho-jquery'),
loading = require('../plugin/loading'),
... ... @@ -6,16 +6,17 @@ var $ = require('yoho-jquery'),
var $page = $('.massage-page'),
page = 1,
stopLoading = false;
stopLoading = false,
pickBusy = false;
function massageAJAX(page) {
function massageAJAX(pageNum) {
loading.showLoadingMask();
$.ajax({
type: 'POST',
url: '/home/message',
dataType: 'html',
data: {
page: page,
page: pageNum,
},
success: function(data) {
if ($(data).find('p').html() === '您没有消息') {
... ... @@ -86,19 +87,15 @@ $page.on('touchstart', '.del', function() {
});
});
var $page = $('.massage-page');
var pickBusy = false;
// 领取生日券
$page.on('touchstart', '.pick-coupon-btn', function() {
var $id = $(this).data('id');
if (pickBusy) {
return;
}
pickBusy = true;
var $id = $(this).data('id');
$.ajax({
type: 'POST',
url: '/home/pickCoupon',
... ...