Authored by 姜枫

调试数据

'use strict';
const _ = require('lodash');
const Search = require('../models/list');
const camelCase = global.yoho.camelCase;
... ... @@ -22,53 +23,112 @@ function brandLetters() {
return letters;
}
function peopleChoose(channel) {
function peopleChoose(gender) {
return [
{
name: '男士',
value: '0',
checked: channel === 'men'
value: '1,3'
}, {
name: '女士',
value: '1',
checked: channel === 'women'
value: '2,3'
}];
}
function newFilter(key, value, name) {
return {
key: key,
value: value,
name: name
};
}
const list = {
index: (req, res, next) => {
let channel = req.query.channel || req.cookies._Channel;
let sex = req.query.sex;
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 || '';
if (sex === '0') {
channel = 'men';
} else if (sex === '1') {
channel = 'women';
}
Search.queryProduct({
page: page,
brand: brand,
sort: sort,
gender: gender,
size: size,
price: price
}).then(result => {
Search.queryProduct({}).then(result => {
if (result && result.code === 200 && result.data) {
let data = camelCase(result.data);
let priceRange = data.filter.priceRange;
let ret = {};
if (data.filter) {
let priceRange = data.filter.priceRange;
let sizeInfo = data.filter.size;
let genders = peopleChoose(gender);
let brands = data.filter.brand;
let colors = data.filter.color;
let sorts = data.filter.groupSort;
let filters = [];
genders.forEach(g => {
if (g.value === gender) {
filters.push(newFilter('gender', gender, g.name));
}
});
priceRange = Object.keys(priceRange).map((k) => {
let prices = k.split(',');
if (k === price) {
filters.push(newFilter('price', price, ${prices[0]}-¥${prices[1]}`));
}
return {
lower: prices[0],
higher: prices[1]
};
}).sort((a, b) => {
return a.lower - b.lower;
});
priceRange = Object.keys(priceRange).map((k) => {
let prices = k.split(',');
if (!_.isArray(sizeInfo)) {
sizeInfo.checked = true;
sizeInfo = [sizeInfo];
}
return {
lower: prices[0],
higher: prices[1]
if (size) {
sizeInfo.forEach(s => {
if (s.sizeId === size) {
filters.push(newFilter('size', size, s.sizeName));
}
});
}
if (brand) {
let brandNames = brands.filter(b => {
return (',' + brand + ',').index(',' + b.id + ',') >= 0;
}).map(b => {
return b.brandName;
}).join('、');
filters.push('brand', brand, brandNames);
}
ret = {
people: genders,
sortData: sorts,
brandData: brands,
colors: colors,
size: sizeInfo,
priceRange: priceRange,
filters: filters
};
}).sort((a, b) => {
return a.lower - b.lower;
});
res.display('list', {
}
res.display('list', _.assign(ret, {
letters: brandLetters(),
people: peopleChoose(channel),
sortData: data.filter.groupSort,
brandData: data.filter.brand,
colors: data.filter.color,
size: data.filter.size,
priceRange: priceRange,
total: data.total,
pageTotal: data.pageTotal,
pageNo: data.page,
... ... @@ -99,7 +159,7 @@ const list = {
module: 'product',
page: 'list',
title: '列表'
});
}));
} else {
throw 'query product error';
}
... ...
... ... @@ -7,6 +7,15 @@ const logger = global.yoho.logger;
const camelCase = global.yoho.camelCase;
const _ = require('lodash');
function clearEmptyVal(obj) {
_.keys(obj).forEach(k => {
if (obj[k] === null || obj[k] === '') {
_.unset(obj, k);
}
});
return obj;
}
const Search = {
querySort(query) {
return SearchAPI.get('sortgroup.json', _.assign({
... ... @@ -34,7 +43,7 @@ const Search = {
yh_channel: 1
};
Object.assign(finalParams, params);
Object.assign(finalParams, clearEmptyVal(params));
return api.get('', finalParams);
}
... ...
... ... @@ -2,24 +2,24 @@
<label>已选条件:</label>
<div class="filter-item">
<span class="label">男士</span>
<span class="iconfont cancel">&#xe608;</span>
<span class="iconfont cancel">&#xe61d;</span>
</div>
<div class="filter-item">
<span class="label">S'wdsft zBesd</span>
<span class="iconfont cancel">&#xe608;</span>
<span class="iconfont cancel">&#xe61d;</span>
</div>
<div class="filter-item">
<span class="label">¥2001-¥4001</span>
<span class="iconfont cancel">&#xe608;</span>
<span class="iconfont cancel">&#xe61d;</span>
</div>
<div class="filter-item">
<span class="label">XL</span>
<span class="iconfont cancel">&#xe608;</span>
<span class="iconfont cancel">&#xe61d;</span>
</div>
<div class="filter-item">
<span class="iconfont c-red">&#xe603;</span>
<span class="label">红色</span>
<span class="iconfont cancel">&#xe608;</span>
<span class="iconfont cancel">&#xe61d;</span>
</div>
<label class="cancel">清空筛选条件</label>
</div>
... ... @@ -39,7 +39,7 @@
</label>
<label class="page-info">{{pageNo}}/{{pageTotal}}</label>
<span class="iconfont page disable page-pre">&#xe607;</span>
<span class="iconfont page page-next">&#xe606;</span>
<span class="iconfont page page-next">&#xe61e;</span>
</div>
</div>
... ... @@ -47,7 +47,7 @@
{{#each products}}
<div class="goods" data-id="{{productId}}">
<div class="goods-img">
<img src="{{defaultImages}}" width="265" height="344" alt="">
<img src="{{image defaultImages 265 344}}" width="265" height="344" alt="">
</div>
<div class="goods-brand">
{{brandName}}
... ... @@ -63,7 +63,7 @@
</div>
<div class="goods-list hide">
{{#each goodsList}}
<i>{{imagesUrl}}</i>
<i>{{image imagesUrl 265 344}}</i>
{{/each}}
</div>
</div>
... ...
... ... @@ -16,10 +16,10 @@
<div class="yoho-ui-accordion no-active">
{{#each sortData}}
<h3>{{categoryName}}</h3>
<div class="body" data-msort="{{categoryId}}">
<div class="body" data-value="{{categoryId}}">
<div class="list-body">
{{#each sub}}
<div class="input-radio" data-misort="{{categoryId}}">
<div class="input-radio" data-value="{{categoryId}}">
{{> icon/radio }}
<label>{{categoryName}}</label>
</div>
... ... @@ -63,7 +63,7 @@
<div class="yoho-ui-accordion">
<h3>价格</h3>
<div class="body">
<div class="body price-body">
{{#each priceRange}}
<div class="input-radio" data-value="{{lower}},{{higher}}">
{{> icon/radio }}
... ...
... ... @@ -18,7 +18,7 @@ module.exports = {
default: '//www.yohoblk.com'
},
domains: {
api: 'http://devapi.yoho.cn:58078/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
api: 'http://api.yoho.yohoops.org/', // 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/'
},
... ...
var $ = require('yoho-jquery');
var common = require('../common');
var YohoListPage = {
rootDoc: $('.yoho-product-list'),
... ... @@ -9,7 +10,6 @@ var YohoListPage = {
goodsWrapperState: false,
init: function() {
require('yoho-jquery-accordion');
require('../common');
require('../plugins/check');
$('.yoho-ui-accordion', this.rootDoc).each(function() {
var opts = {
... ... @@ -27,7 +27,34 @@ var YohoListPage = {
type: 'radio',
onChange: function(ele, checked, value) {
YohoListPage.go({
sex: checked ? value : ''
gender: checked ? value : ''
});
}
});
$('.yoho-product-list .list-body .input-radio').check({
type: 'radio',
onChange: function(ele, checked, value) {
YohoListPage.go({
sort: checked ? value : ''
});
}
});
$('.yoho-product-list .price-body .input-radio').check({
type: 'radio',
onChange: function(ele, checked, value) {
YohoListPage.go({
price: checked ? value : ''
});
}
});
$('.yoho-product-list .size-body .input-radio').check({
type: 'radio',
onChange: function(ele, checked, value) {
YohoListPage.go({
size: checked ? value : ''
});
}
});
... ... @@ -36,7 +63,7 @@ var YohoListPage = {
type: 'radio',
onChange: function(ele, checked, value) {
if (!YohoListPage.mulitBrand) {
YohoListPage.go({brands: value});
YohoListPage.go({brand: value});
} else {
YohoListPage.showBrandMulitBtn();
}
... ... @@ -57,7 +84,7 @@ var YohoListPage = {
$('.yoho-product-list .brand-btns .confirm').click(function() {
if (!$(this).hasClass('disable')) {
YohoListPage.go({
brands: YohoListPage.getSelectBrands().join(',')
brand: YohoListPage.getSelectBrands().join(',')
});
}
});
... ... @@ -151,7 +178,7 @@ var YohoListPage = {
},
go: function(q) {
var qs = $.extend(window.queryString(), q);
var qs = $.extend(common.queryString(), q);
location.search = $.param(qs);
}
... ...
... ... @@ -62,11 +62,11 @@
}
.select {
color: cornflowerblue;
color: #379ed6;
}
.mulit-choose {
border: 1px solid #000;
border: 1px solid #1b1b1b;
padding: 5px 10px;
}
}
... ... @@ -186,7 +186,7 @@
}
span.cancel {
font-size: 8px;
font-size: 14px;
}
}
}
... ... @@ -224,7 +224,7 @@
}
.iconfont.selected {
color: #000;
color: #1b1b1b;
}
.iconfont.up {
... ... @@ -236,7 +236,7 @@
}
.order.selected {
color: #000;
color: #1b1b1b;
}
.right {
... ... @@ -246,7 +246,7 @@
margin-top: 12px;
label {
color: #000;
color: #1b1b1b;
font-weight: 700;
display: inline-block;
}
... ... @@ -256,9 +256,9 @@
}
.page {
color: #000;
color: #1b1b1b;
font-weight: 700;
border: 2px solid #000;
border: 2px solid #1b1b1b;
width: 24px;
height: 24px;
line-height: 24px;
... ...