Authored by lijing

浏览历史

... ... @@ -59,8 +59,42 @@ exports.myDetails = (req, res, next) => {
};
indexModel.myDetails({
}).then(result => {
res.render('personal-details', Object.assign(responseData, result));
}).catch(next);
};
/**
* 浏览记录
* @param req
* @param res
* @param next
*/
exports.record = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '浏览记录'
});
let responseData = {
pageHeader: headerData,
module: 'home',
page: 'browse-record',
title: '浏览记录',
pageFooter: true
};
indexModel.record({
}).then(result => {
console.log(Object.assign(responseData, result));
res.render('browse-record', Object.assign(responseData, result));
}).catch(next);
};
... ...
... ... @@ -11,6 +11,7 @@ const api = global.yoho.API;
const singleAPI = global.yoho.SingleAPI;
const helpers = global.yoho.helpers;
const camelCase = global.yoho.camelCase;
const _ = require('lodash');
/**
* 个人详情数据
... ... @@ -127,6 +128,7 @@ const myDetails = (params) => {
result = camelCase(result);
if (result.data) {
return result.data;
// {
// nickname: result.data.nickname,
// gender: result.data.gender,
... ... @@ -137,11 +139,54 @@ const myDetails = (params) => {
// }
// }
}
// return finalResult;
});
};
/**
* 浏览记录
* @param params
*/
const record = (params) => {
return api.get('', {
method: 'app.browse.product',
uid: params.uid || 6228593,
limit: 100,
page: 1
}, {code: 200}).then((result) => {
let resu = {
recordResult: []
};
if (result && result.code === 200) {
_.forEach(result.data.product_list, function(val) {
let obj = {};
obj = _.assign(obj, {
product_name: val.product_name,
product_skn: val.product_skn,
invalidGoods: val.status === 0,
storage: val.storage
});
resu.recordResult.push(obj);
});
}
// console.log(resu);
return resu;
});
};
module.exports = {
index,
myDetails
myDetails,
record
};
... ...
... ... @@ -39,6 +39,7 @@ router.get('/orderDetail', orderDetailController.orderDetail); // 订å•è¯¦æƒ…é¡
router.get('/', homeController.index); // 个人中心首页
router.get('/mydetails', homeController.myDetails); // 个人基本资料页面
router.get('/record', homeController.record); // 浏览记录
// 我的收藏
router.get('/favorite', favorite.favorite);
... ...
{{# browseRecord}}
<a class="browse-record-good clearfix {{#if invalidGoods}}invalidGoods{{/if}}" data-skn="{{product_skn}}" href="{{link}}">
<img class="thumb lazy" data-original="{{image}}">
<div class="deps clearfix">
<p class="name row">{{product_name}}</p>
<p class="price row">
<span class="sale-price{{#unless market_price}} original-price{{/unless}}">¥{{sales_price}}</span>
&nbsp;&nbsp;
{{#if market_price}}
<span class="market-price">¥{{market_price}}</span>
{{/if}}
</p>
<p class="sold-out row">
{{#unless storage}}
<span class="sold-out-tag">已售罄</span>
{{/unless}}
</p>
<span class="iconfont del-icon">&#xe621;</span>
</div>
</a>
{{/ browseRecord}}
{{#if noRecord}}
<div class="no-record">
<div class="icon"></div>
<span>暂无浏览记录</span>
<a class="walk-way" href="{{walkwayUrl}}">随便逛逛</a>
</div>
{{/if}}
\ No newline at end of file
... ...
<div class="browse-record-page yoho-page">
<div class="records">
{{# browseRecord}}
<a class="browse-record-good clearfix {{#if invalidGoods}}invalidGoods{{/if}}" data-skn="{{product_skn}}" href="{{link}}">
<img class="thumb lazy" data-original="{{image}}">
<div class="deps clearfix">
<p class="name row">{{product_name}}</p>
<p class="price row">
<span class="sale-price{{#unless market_price}} original-price{{/unless}}">¥{{sales_price}}</span>
&nbsp;&nbsp;
{{#if market_price}}
<span class="market-price">¥{{market_price}}</span>
{{/if}}
</p>
<p class="sold-out row">
{{#unless storage}}
<span class="sold-out-tag">已售罄</span>
{{/unless}}
</p>
<span class="iconfont del-icon">&#xe621;</span>
</div>
</a>
{{/ browseRecord}}
{{#if noRecord}}
<div class="no-record">
<div class="icon"></div>
<span>暂无浏览记录</span>
<a class="walk-way" href="{{walkwayUrl}}">随便逛逛</a>
</div>
{{/if}}
</div>
<div class="load-more hide">
<span class="more">正在加载...</span>
<span class="no-more hide">没有更多了</span>
</div>
</div>
\ No newline at end of file
... ...
/**
* 浏览记录
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/11/28
*/
var $ = require('yoho-jquery');
var lazyLoad = require('yoho-jquery-lazyload'),
load = require('../plugin/loading'),
tip = require('../plugin/tip');
var dialog = require('../plugin/dialog');
var $page = $('.records');
var $loadMore = $('.load-more'),
$more = $loadMore.children('.more'),
$noMore = $loadMore.children('.no-more');
var page = 0;
var end = false,
loading = false;
var winH = $(window).height();
require('../common');
load.init();
function moreRecord(cb) {
var count = $page.children('.browse-record-good').length;
if (loading) {
return;
}
if (page === 1) {
$loadMore.removeClass('hide');
}
loading = true;
$.ajax({
type: 'GET',
url: '/home/recordContent',
data: {
page: page + 1
},
success: function(data) {
if (data === ' ') {
end = true;
$more.addClass('hide');
$noMore.removeClass('hide');
} else {
if (count === 0) {
$page.html(data);
lazyLoad();
} else {
$page.append(data);
lazyLoad($page.find('.browse-record-good:gt(' + (count - 1) + ') .lazy'));
}
window.rePosFooter();
page++;
if (cb) {
cb();
}
}
},
complete: function() {
loading = false;
}
});
}
load.showLoadingMask();
moreRecord(load.hideLoadingMask);
$(window).scroll(function() {
if (end) {
return;
}
if (winH + $(window).scrollTop() > $(document).height() - 0.25 * $page.height()) {
moreRecord();
}
});
$page.on('touchstart', '.del-icon', function() {
var $good = $(this).closest('.browse-record-good'),
skn = $good.data('skn');
dialog.showDialog({
dialogText: '确定删除此条浏览记录吗?',
hasFooter: {
leftBtnText: '取消',
rightBtnText: '确定'
}
}, function() {
$.ajax({
type: 'GET',
url: '/home/delRecord',
data: {
skn: skn
},
success: function(data) {
if (data.code === 200) {
dialog.showDialog({
dialogText: '删除浏览记录成功',
autoHide: 2000,
fast: true
});
setTimeout(function() {
window.history.go(0);
}, 1200);
}
}
});
});
});
$('.deps').on('touchstart', 'span', function() {
$(this).css('background', '#eee');
}).on('touchend touchcancel', 'span', function() {
$(this).css('background', 'transparent');
});
$('.invalidGoods').on('touchstart touchend', function(e) {
var $this = $(e.target).closest('span');
if ($this.hasClass('del-icon')) {
return;
}
tip.show('商品已下架');
return false;
});
... ...
... ... @@ -14,6 +14,8 @@ var $userAvatar = $('.user-avatar');
var myImage = new Image(),
avatar;
require('../common');
// 部分老用户没有头像,显示默认头像
avatar = $userAvatar.data('avatar');
myImage.src = avatar;
... ...