Authored by xuqi

goods loadMore & prise

... ... @@ -7,6 +7,8 @@
var $ = require('jquery'),
lazyLoad = require('./common/lazyload');
require('./common/maybe-like');
//lazyload
lazyLoad();
... ... @@ -41,4 +43,10 @@ $('.sub-nav').each(function() {
$('.sub-nav').removeClass('show');
event.stopPropagation();
});
});
//
$('.back-to-top').bind('touchstart', function(e) {
e.preventDefault();
$(window).scrollTop(0);
});
\ No newline at end of file
... ...
/**
* “你可能喜欢”模块JS
* @author: xuqi(qi.xu@yoho.cn)
* @date: 2015/7/15
*/
var $ = require('jquery'),
Mustache = require('mustache'),
lazyLoad = require('./lazyload');
var winH = $(window).height(),
loading = false,
end = false,
page = 1,
tpl;
//read good-info template
$.get('/common/goodinfo', function(data) {
tpl = '{{# goods}}' + data + '{{/ goods}}';
Mustache.parse(tpl);
});
var isLogin = 'Y'; //TODO:是否登录,后台提供,区分走Ajax还是页面跳转
//商品收藏
$('.goods-list').delegate('.good-islike', 'touchstart', function(e) {
var $cur, $good, id, url;
if (isLogin === 'Y') {
e.preventDefault(); // 阻止链接跳转改AJAX
$cur = $(e.currentTarget);
$good = $cur.closest('.good-info');
id = $good.data('id');
if ($cur.hasClass('good-like')) {
url = '/goods/cancelprise';
} else {
url = '/goods/prise';
}
$.ajax({
type: 'GET',
url: url,
data: {
product_skn: id
}
}).then(function(data) {
if (data.code === 200) {
$cur.toggleClass('good-like');
} else if (data.code === 400) {
//TODO:提示登录
}
});
}
});
var $maybeLike = $('.maybe-like:last'),
$goodList = $maybeLike.children('.goods-list'),
mblTop = $maybeLike.offset().top; //页面内容固定,可以预先求出高度
//srcoll to load more
$(window).scroll(function() {
var num;
if (end || loading) {
return;
}
if ($(window).scrollTop() + winH < mblTop + $maybeLike.height()) {
return;
}
loading = true;
num = $goodList.children('.good-info').length;
$.ajax({
type: 'GET',
url: '/goods/more',
data: {
gender: 0, //性别
page: page + 1
}
}).then(function(data) {
var res,
i;
if (data.code === 200) {
res = data.data;
if (res.end) {
end = res.end;
}
$goodList.append(Mustache.render(tpl, {
goods: res.goods
}));
//lazyLoad
lazyLoad($goodList.children('.good-info:gt(' + (num - 1) + ')').find('img.lazy'));
loading = false;
page++;
}
});
});
\ No newline at end of file
... ...
/**
* 商品信息数据
* @author xuqi(qi.xu@yoho.cn)
* @date 2015/7/15
*/
module.exports = [
{
id: 5,
thumb: 'http://img11.static.yhbimg.com/goodsimg/2015/03/02/07/01ebfb219e22770ffb0c2c3a2cbb2b4bef.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
name: 'GAWS DIGI 丛林数码印花拼接卫衣',
isLike: false,
price: 1268,
salePrice: 589,
isSale: true,
isFew: true,
isNew: false,
url: '',
likeUrl: ''
},
{
id: 6,
thumb: 'http://img13.static.yhbimg.com/goodsimg/2015/03/03/08/023d70c59e81ccbfb39404487aaf642da2.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
name: 'CLOTtee 撞色连帽外套',
isLike: false,
price: 488,
salePrice: 139,
isSale: true,
isFew: true,
isNew: false,
url: '',
likeUrl: ''
},
{
id: 7,
thumb: 'http://img12.static.yhbimg.com/goodsimg/2015/03/02/08/02e2d44125e95495e3152aa459fa6b9b0c.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
name: 'HALFGIRL 插肩棒球服短裙套装',
isLike: true,
price: 478,
salePrice: 208,
isSale: true,
isFew: true,
isNew: false,
url: '',
likeUrl: ''
},
{
id: 8,
thumb: 'http://img12.static.yhbimg.com/goodsimg/2015/03/03/08/022f25fbe177ee12803c522f04fcce06d0.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
name: '黄伟文Wyman X yohood联名商品YYYOHOOD连帽卫衣',
isLike: false,
salePrice: 148,
isSale: false,
isFew: false,
isNew: true,
url: '',
likeUrl: ''
}
];
\ No newline at end of file
... ...
... ... @@ -3,8 +3,15 @@
* @author: liuyue(yue.liu@yoho.cn)
* @date: 2015/7/13
*/
var boys = require('./views/controller/boys');
var controllerPath = './views/controller/',
boys = require(controllerPath + 'boys'),
goods = require(controllerPath + 'goods');
module.exports = function(app) {
app.get('/boys', boys.index); //boys首页
app.get('/common/goodinfo', goods.goodTpl); //商品信息模板
app.get('/goods/more', goods.more); //下拉加载更多
app.get('/goods/prise', goods.like); //商品收藏/取消收藏
app.get('/goods/cancelprise', goods.like);
};
\ No newline at end of file
... ...
/**
* 商品信息相关路由处理
* @author: xuqi(qi.xu@yoho.cn)
* @date: 2015/7/15
*/
var fs = require('fs'),
path = require('path'),
tplPath = path.normalize(path.join(__dirname, '../partials/common/good_info.html')),
data = require('../../public/js/data/goods');
exports.goodTpl = function(req, res) {
fs.readFile(tplPath, 'utf8', function(err, data) {
if (err) {
res.send({
success: false
});
}
res.send(data);
});
};
//加载更多商品信息
exports.more = function(req, res) {
res.send({
code: 200,
data: {
end: true,
goods: data
}
});
};
// 收藏、取消收藏
exports.like = function(req, res) {
res.send({
code: 200
});
};
\ No newline at end of file
... ...