Authored by 姜枫

完善列表页

... ... @@ -7,14 +7,9 @@ const DateHelper = require('../models/helpers');
const list = {
index: (req, res, next) => {
let page = req.query.page || 1;
let brand = req.query.brand || 0;
let sort = req.query.sort || '';
let gender = req.query.gender || '';
let price = req.query.price || '';
let size = req.query.size || '';
let color = req.query.color || '';
let order = req.query.order || '';
let q = req.query;
q.page = q.page || 1;
let retDate = {
module: 'product',
... ... @@ -22,40 +17,68 @@ const list = {
title: '列表'
};
Search.queryProduct({
page: page,
brand: brand,
sort: sort,
gender: gender,
size: size,
price: price,
color: color,
order: order
}).then(result => {
Search.queryProduct(q).then(result => {
if (result && result.code === 200 && result.data) {
let data = camelCase(result.data);
if (data.filter) {
retDate.filter = DateHelper.filterHandle(data.filter, req.query);
retDate.filter = DateHelper.filterHandle(data.filter, q);
}
retDate.paginationData = {
page: page,
page: q.page,
limit: data.limit || 45,
total: data.total,
pageTotal: data.pageTotal,
queryParams: req.query
queryParams: q
};
res.display('list', _.assign(retDate, {
products: data.productList,
order: order
order: q.order
}));
} else {
return Promise.reject('query product error');
}
}).catch(next);
},
newPage: (req, res, next) => {
let q = req.query;
q.page = q.page || 1;
let retDate = {
module: 'product',
page: 'list',
title: '列表'
};
Search.queryProduct(q).then(result => {
if (result && result.code === 200 && result.data) {
let data = camelCase(result.data);
if (data.filter) {
retDate.filter = DateHelper.filterHandle(data.filter, q);
}
retDate.paginationData = {
page: q.page,
limit: data.limit || 45,
total: data.total,
pageTotal: data.pageTotal,
queryParams: q
};
res.display('newList', _.assign(retDate, {
products: data.productList,
order: q.order
}));
} else {
return Promise.reject('query product error');
}
}).catch(next);
}
};
... ...
... ... @@ -58,7 +58,7 @@ const helpers = {
name: 'MEN首页'
}];
if (sort) {
if (sort && sorts) {
sorts.forEach(s => {
if (s.relationParameter.sort === sort) {
nav.push({
... ... @@ -103,6 +103,8 @@ const helpers = {
let colors = this.colorConvert(filter.color);
let sorts = filter.groupSort;
let filters = [];
let customPriceLow = '';
let customPriceHigh = '';
genders.forEach(g => {
if (g.value === q.gender) {
... ... @@ -111,20 +113,34 @@ const helpers = {
}
});
let matchPrice = false;
priceRange = Object.keys(priceRange).map((k) => {
let prices = k.split(',');
if (k === q.price) {
filters.push(this.newFilter('price', q.price, ${prices[0]}-¥${prices[1]}`));
}
return {
let p = {
lower: prices[0],
higher: prices[1]
};
if (k === q.price) {
p.checked = true;
matchPrice = true;
}
return p;
}).sort((a, b) => {
return a.lower - b.lower;
});
if (!matchPrice && q.price) {
let prices = q.price.split(',');
filters.push(this.newFilter('price', q.price, ${prices[0]}-¥${prices[1]}`));
customPriceLow = prices[0];
customPriceHigh = prices[1];
}
if (!_.isArray(sizeInfo)) {
sizeInfo.checked = true;
sizeInfo = [sizeInfo];
... ... @@ -133,6 +149,7 @@ const helpers = {
if (q.size) {
sizeInfo.forEach(s => {
if (s.sizeId === parseInt(q.size, 10)) {
s.checked = true;
filters.push(this.newFilter('size', q.size, s.sizeName));
}
});
... ... @@ -142,6 +159,7 @@ const helpers = {
let brandNames = brands.filter(b => {
return (',' + q.brand + ',').indexOf(',' + b.id + ',') >= 0;
}).map(b => {
b.checked = true;
return b.brandName;
}).join('、');
... ... @@ -173,7 +191,9 @@ const helpers = {
letters: this.brandLetters(),
navPath: {
nav: this.getNav('', q.sort, sorts)
}
},
customPriceLow: customPriceLow,
customPriceHigh: customPriceHigh
};
}
};
... ...
... ... @@ -14,6 +14,7 @@ const shop = require(cRoot + '/shop');
// Your controller here
router.get('/list', list.index); // 列表页面
router.get('/list/new', list.newPage); // 新品列表页
router.get(/\/item\/([\d]+)_([\d]+).html/, item.index); // 商品详情页
... ...
{{!-- 新品 列表页 --}}
<div class="blk-page yoho-product-list">
<div class="center-content">
{{# filter.navPath}}
{{> path-nav}}
{{/ filter.navPath}}
</div>
<div class="center-content clearfix">
<div class="left">
{{!-- 筛选区域 --}}
{{#filter}}
{{> list/filter}}
{{/filter}}
</div>
<div class="right">
{{!-- 新品banner --}}
<div class="banner-img" style="height: 200px;margin-bottom:30px; background:url(//img12.static.yhbimg.com/couponImg/2016/07/06/10/025f07ba2e91648de11e5c054471323920.jpg) no-repeat top center;"></div>
{{!-- 已选中条件 --}}
{{#filter}}
{{> list/filter-area}}
{{/filter}}
{{!-- 排序 --}}
{{> list/order-area}}
{{!-- 商品列表 --}}
{{> list/goods-box}}
{{!-- 分页 --}}
{{{ pagination paginationData }}}
</div>
</div>
</div>
... ...
... ... @@ -77,14 +77,14 @@
<div class="price-btns">
<div class="price-input inline-block">
<span>¥</span>
<input type="text">
<input type="text" class="price-low" value="{{customPriceLow}}">
</div>
<span></span>
<div class="price-input inline-block">
<span>¥</span>
<input type="text">
<input type="text" class="price-high" value="{{customPriceHigh}}">
</div>
<span class="btn large">确定</span>
<span class="btn large confirm">确定</span>
</div>
</div>
</div>
... ...
... ... @@ -19,7 +19,7 @@ module.exports = {
},
cookieDomain: 'yohoblk.com',
domains: {
api: 'http://devapi.yoho.cn:58078/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
api: 'http://testapi.yoho.cn:28078/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
service: 'http://devservice.yoho.cn:28077/', // testservice.yoho.cn:28077 devservice.yoho.cn:58077
search: 'http://192.168.102.216:8080/yohosearch/'
},
... ...
... ... @@ -25,7 +25,12 @@ var jQuery = require('yoho-jquery');
var type = options.type || defaults.type;
var ele = this;
options = $.extend({}, defaults, defaultsHtml[type], options);
options = $.extend({}, defaults, $(this).data('options'), defaultsHtml[type], options);
var _checked = $('.iconfont', this).hasClass('checked');
$('.iconfont', this).removeClass('radio').removeClass('checkbox').addClass(options.type);
$('.iconfont', this).html(_checked ? options.checkedHtml : options.uncheckedHtml);
if (options.group) {
$(this).addClass('check-group-' + options.group);
... ...
... ... @@ -27,6 +27,7 @@ var YohoListPage = {
$('.sex-body .input-radio', this.rootDoc).check({
type: 'radio',
group: 'gender',
onChange: function(ele, checked, value) {
YohoListPage.go({
gender: checked ? value : ''
... ... @@ -36,6 +37,7 @@ var YohoListPage = {
$('.list-body .input-radio', this.rootDoc).check({
type: 'radio',
group: 'sort',
onChange: function(ele, checked, value) {
YohoListPage.go({
sort: checked ? value : ''
... ... @@ -45,6 +47,7 @@ var YohoListPage = {
$('.price-body .input-radio', this.rootDoc).check({
type: 'radio',
group: 'price',
onChange: function(ele, checked, value) {
YohoListPage.go({
price: checked ? value : ''
... ... @@ -54,6 +57,7 @@ var YohoListPage = {
$('.size-body .input-radio', this.rootDoc).check({
type: 'radio',
group: 'size',
onChange: function(ele, checked, value) {
YohoListPage.go({
size: checked ? value : ''
... ... @@ -63,6 +67,7 @@ var YohoListPage = {
$('.brand-list .input-radio', this.rootDoc).check({
type: 'radio',
group: 'brand',
onChange: function(ele, checked, value) {
if (!YohoListPage.mulitBrand) {
YohoListPage.go({brand: value});
... ... @@ -100,6 +105,17 @@ var YohoListPage = {
}
});
$('.price-btns .confirm', this.rootDoc).click(function() {
var priceLow = $('.price-low', $(this).parent()).val() || 0;
var priceHigh = $('.price-high', $(this).parent()).val() || 0;
if(priceLow > 0 || priceHigh > 0) {
YohoListPage.go({
price: priceLow + ',' + priceHigh
});
}
});
$('.yoho-product-list .brand-body input').on('keyup', function() {
YohoListPage.filterBrand($(this).val().toLowerCase());
});
... ... @@ -181,6 +197,9 @@ var YohoListPage = {
},
openBrandMulitChoose: function() {
$('.yoho-product-list .mulit-choose').hide();
$('.input-radio', this.brandsDoc).check({
type: 'checkbox'
});
YohoListPage.mulitBrand = true;
YohoListPage.showBrandMulitBtn();
},
... ... @@ -190,6 +209,9 @@ var YohoListPage = {
$('.yoho-product-list .brand-list .input-radio').check('unCheckAll');
YohoListPage.mulitBrand = false;
$('.input-radio', this.brandsDoc).check({
type: 'radio'
});
},
showBrandMulitBtn: function() {
$('.brand-btns', this.rootDoc).removeClass('hide');
... ... @@ -221,7 +243,7 @@ var YohoListPage = {
getSelectBrands: function() {
let brands = [];
$('.input-radio .radio', this.brandsDoc).each(function() {
$('.input-radio .checkbox', this.brandsDoc).each(function() {
if ($(this).hasClass('checked')) {
brands.push($(this).parent().data('value'));
}
... ...