Authored by 陈轩

save

... ... @@ -33,6 +33,8 @@ function _productAddFlag(productList) {
productList.sort((a, b) => a.orderBy < b.orderBy);
productList.forEach(product => {
product.readableTime = moment.unix(product.startTime).format('MM月DD日 HH:mm');
if (now < product.startTime * 1000) { // 未开抢
product.wait = true;
} else if (product.secKillStatus === 0 || (now > product.endTime * 1000)) { // 确实已抢光, 过了秒杀时间
... ... @@ -45,23 +47,6 @@ function _productAddFlag(productList) {
return productList;
}
let _helpers = {
statusClass: (nav) => {
if (nav.over) {
return 'over';
} else if (nav.now) {
return 'now';
} else if (nav.wait) {
return 'wait';
} else {
return '';
}
},
readaleTime: (unixStamp) => {
return moment.unix(unixStamp).format('MM月DD日 HH:mm');
}
};
/**
* [秒杀列表页面]
*/
... ... @@ -80,11 +65,7 @@ const index = (req, res, next) => {
});
}
let result = {},
hbsHelper = {
helpers: _helpers
};
let result = {};
let uid = req.yoho.isApp && req.query.uid;
return seckillModel.queryActivity().then((resultActivity) => {
... ... @@ -195,7 +176,7 @@ const getProductList = (req, res, next) => {
res.render('seckill/product-list', Object.assign(result, {
layout: false
}, {helpers: _helpers}));
}));
}).catch(error => {
logger.error(error);
});
... ...
... ... @@ -14,7 +14,7 @@
<div class="item-foot">
{{# if wait}}
<div class="item-time" data-start="{{startTime}}"><span><i class="iconfont">&#xe603;</i><time>{{readaleTime startTime}}</time>开始</span></div>
<div class="item-time" data-start="{{startTime}}"><span><i class="iconfont">&#xe603;</i><time>{{readaleTime}}</time>开始</span></div>
{{else}}
<div class="item-price">
<ins>¥{{secKillPrice}}</ins><del>¥{{marketPrice}}</del>
... ...
<nav class="nav-list">
<ul class="nav-ul hide">
{{# activitys}}
<li class="time-item {{# if @last}}last{{/if}} {{# if focus}}focus{{/if}} {{@root.statusClass this}}">
<li class="time-item {{# if @last}}last{{/if}} {{# if focus}}focus{{/if}} {{./statusClass this}}">
<input type="hidden" name="" class="date" value="{{startTime}}">
<input type="hidden" name="" class="activityId" value="{{activityId}}">
<div class="normal">
... ...
... ... @@ -6,15 +6,15 @@
<div class="item-title">
{{productName}}
</div>
{{# if wait}}
{{#if wait}}
<div class="item-price">
<ins>¥{{secKillPrice}}</ins><del>¥{{marketPrice}}</del>
</div>
{{/if}}
<div class="item-foot">
{{# if wait}}
<div class="item-time" data-start="{{startTime}}"><span><i class="iconfont">&#xe603;</i><time>{{@root.readaleTime startTime}}</time>开始</span></div>
{{#if wait}}
<div class="item-time" data-start="{{startTime}}"><span><i class="iconfont">&#xe603;</i><time>{{readableTime}}</time>开始</span></div>
{{else}}
<div class="item-price">
<ins>¥{{secKillPrice}}</ins><del>¥{{marketPrice}}</del>
... ...
module.exports = function(nav) {
if (nav.over) {
return 'over';
} else if (nav.now) {
return 'now';
} else if (nav.wait) {
return 'wait';
} else {
return '';
}
};
... ...
... ... @@ -11,23 +11,7 @@ var $ = require('yoho-jquery'),
lazyload = require('yoho-jquery-lazyload'),
tip = require('plugin/tip');
var _helpers = {
statusClass: function(nav) {
if (nav.over) {
return 'over';
} else if (nav.now) {
return 'now';
} else if (nav.wait) {
return 'wait';
} else {
return '';
}
},
readaleTime: function(unixStamp) {
return moment.unix(unixStamp).format('MM月DD日 HH:mm');
}
};
window.$ = $;
var seckillObj = {};
... ... @@ -39,50 +23,56 @@ seckillObj = {
pageTemplate: require('template/product/seckill/index.hbs'),
listTemplate: require('template/product/seckill/product-list.hbs'),
el: {
// doms
$navUl: $('.nav-ul'),
$navList: $('.nav-list'),
// 变量
times: $('.nav-ul>li').length,
startX: 0,
timeWidth: 0,
focusTimeWidth: 0,
iScroll: null,
currentTick: null
},
el: {},
/**
* [初始化界面]
*/
init: function() {
var self = this;
this.$container = $('.seckill-list');
this.pageLoad()
.then(function() {
console.log('hi')
var $el = this.el, that = this;
self.domInit();
})
.then(function() {
var $el = self.el;
var focus = $el.$navUl.find('>li.focus');
this.$productList = $('.product-list');
self.$productList = $('.product-list');
$el.$navUl.find('>li').click(function() {
that.selectTime(this);
self.selectTime(self);
});
$(window).resize(function() {
that.initNav();
self.initNav();
});
that.initNav();
self.initNav();
if (focus.length && (focus.hasClass('now') || focus.hasClass('wait'))) {
that.initTick($el.$navUl.find('>li.focus'));
self.initTick($el.$navUl.find('>li.focus'));
}
this.bindEvents();
self.bindEvents();
});
},
domInit: function() {
this.el = {
// doms
$navUl: $('.nav-ul'),
$navList: $('.nav-list'),
// 变量
times: $('.nav-ul>li').length,
startX: 0,
timeWidth: 0,
focusTimeWidth: 0,
iScroll: null,
currentTick: null
};
},
/**
* [初始化时间段]
*/
... ... @@ -224,18 +214,17 @@ seckillObj = {
* [异步加载商品列表]
*/
refreshProductList: function(activityId) {
var url = yoho.isApp ?
'/product/seckill/get-product-list?app_version=1' :
'/product/seckill/get-product-list';
loading.show();
$.ajax({
url: '/product/seckill/get-product-list',
url: url,
data: {
uid: yoho.isLogin(), // only app use;
activityId: activityId
},
beforeSend: function(jqXhr, config) {
if (yoho.isApp) {
config.url += '&app_version=1';
}
},
success: function(data) {
$('.product-list').html(data);
lazyload('img.lazy');
... ... @@ -384,7 +373,7 @@ seckillObj = {
return $.get('/product/seckill')
.done(function(result) {
self.$container.html(
self.pageTemplate($.extend(result, _helpers, {
self.pageTemplate($.extend(result, {
isApp: yoho.isApp
}))
);
... ...
... ... @@ -51,11 +51,17 @@ module.exports = {
}, {
test: /\.css$/,
loader: ExtractTextPlugin.extract(['css?-url'])
}, {test: /\.hbs$/, loader: 'handlebars-loader', query: {
helperDirs: [
path.join(__dirname, '/js/common/helpers')
]
}}]
}, {
test: /\.hbs$/,
loader: 'handlebars-loader',
query: {
debug: true,
compat: false,
helperDirs: [
path.join(__dirname, '/js/common/helpers')
]
}
}]
},
resolve: {
modulesDirectories: ['node_modules', './vue', './hbs', './scss', './js'],
... ... @@ -80,3 +86,4 @@ module.exports = {
})
]
};
... ...