... ... @@ -8,14 +8,14 @@
// const library = '../../../library';
// const log = require(`${library}/logger`);
const headerModel = require('../../../doraemon/models/header');
// const headerModel = require('../../../doraemon/models/header');
const mRoot = '../models';
// sale 页 model
const sale = require(`${mRoot}/sale`);
// 开发用模拟数据
// const simulation = require(`${mRoot}/simulation`);
const simulation = require(`${mRoot}/simulation`);
/**
* sale 首页
... ... @@ -25,30 +25,33 @@ const sale = require(`${mRoot}/sale`);
*/
exports.index = (req, res) => {
headerModel.requestHeaderData()
.then(responseData => {
responseData = headerModel.setHeaderData(responseData.data, 'sale');
let responseData = {};
responseData.module = 'product';
responseData.page = 'sale';
responseData.footerTop = true;
responseData.devEnv = true;
// headerModel.requestHeaderData()
// .then(responseData => {
// responseData = headerModel.setHeaderData(responseData.data, 'sale');
responseData.module = 'product';
responseData.page = 'sale';
responseData.footerTop = true;
responseData.devEnv = true;
// 假数据输出
// res.render('sale/index', Object.assign(responseData, simulation.saleIndex()));
// 真实数据输出
sale.getSaleIndexData().then(result => {
sale.getSaleIndexData().then(result => {
responseData.result = result;
responseData.resultShow = JSON.stringify(result, null, 4);
responseData.result = result;
responseData.resultShow = JSON.stringify(result, null, 4);
res.render('sale/index', responseData);
});
res.render('sale/index', responseData);
});
})
.catch(() => {
res.render('error', { devEnv: true, pageErr: true });
});
// })
// .catch(() => {
// res.render('error', { devEnv: true, pageErr: true });
// });
};
/**
... ... @@ -62,30 +65,32 @@ exports.discount = (req, res) => {
saleType: 3
}, req.query);
headerModel.requestHeaderData()
.then(responseData => {
responseData = headerModel.setHeaderData(responseData.data, 'sale-discount');
responseData.module = 'product';
responseData.page = 'sale';
responseData.footerTop = true;
responseData.devEnv = true;
let responseData = {};
// headerModel.requestHeaderData()
// .then(responseData => {
// responseData = headerModel.setHeaderData(responseData.data, 'sale-discount');
responseData.module = 'product';
responseData.page = 'sale';
responseData.footerTop = true;
responseData.devEnv = true;
// 假数据输出
// res.render('sale/discount', Object.assign(responseData, simulation.discount()));
sale.getDiscountData(params).then((result) => {
responseData.result = result;
responseData.resultShow = JSON.stringify(result, null, 4);
sale.getSaleDiscountData(params).then((result) => {
responseData.result = result;
responseData.resultShow = JSON.stringify(result, null, 4);
// log.info(result);
res.render('sale/discount', responseData);
});
res.render('sale/discount', responseData);
});
})
.catch(() => {
res.render('error', { devEnv: true, pageErr: true });
});
// })
// .catch(() => {
// res.render('error', { devEnv: true, pageErr: true });
// });
};
/**
... ... @@ -99,93 +104,99 @@ exports.vip = (req, res) => {
saleType: 2
}, req.query);
headerModel.requestHeaderData().then(responseData => {
responseData = headerModel.setHeaderData(responseData.data, 'vip');
responseData.module = 'product';
responseData.page = 'sale';
responseData.footerTop = true;
responseData.devEnv = true;
let responseData = {};
// 假数据输出
// res.render('sale/other', Object.assign(responseData, simulation.other()));
// headerModel.requestHeaderData().then(responseData => {
// responseData = headerModel.setHeaderData(responseData.data, 'vip');
responseData.module = 'product';
responseData.page = 'sale';
responseData.footerTop = true;
responseData.devEnv = true;
sale.getSaleData(params).then((result) => {
responseData.saleList = result;
responseData.resultShow = JSON.stringify(result, null, 4);
// 假数据输出
res.render('sale/other', Object.assign(responseData, simulation.other()));
res.render('sale/other', responseData);
});
// sale.getSaleOthersData(params).then((result) => {
// responseData.saleList = result;
// responseData.resultShow = JSON.stringify(result, null, 4);
//
// res.render('sale/other', responseData);
// });
}).catch(() => {
res.render('error', { devEnv: true, pageErr: true });
});
// }).catch(() => {
// res.render('error', { devEnv: true, pageErr: true });
// });
};
/**
* 断码专区
* 新降价专区
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.breakingYards = (req, res) => {
exports.newSale = (req, res) => {
let params = Object.assign({
saleType: 1
}, req.query);
headerModel.requestHeaderData().then(responseData => {
responseData = headerModel.setHeaderData(responseData.data, 'breakingYards');
responseData.module = 'product';
responseData.page = 'sale';
responseData.footerTop = true;
responseData.devEnv = true;
let responseData = {};
// 假数据输出
// res.render('sale/other', Object.assign(responseData, simulation.other()));
// headerModel.requestHeaderData().then(responseData => {
// responseData = headerModel.setHeaderData(responseData.data, 'newSale');
responseData.module = 'product';
responseData.page = 'sale';
responseData.footerTop = true;
responseData.devEnv = true;
sale.getSaleData(params).then((result) => {
responseData.saleList = result;
responseData.resultShow = JSON.stringify(result, null, 4);
// 假数据输出
// res.render('sale/other', Object.assign(responseData, simulation.other()));
res.render('sale/other', responseData);
});
sale.getSaleOthersData(params).then((result) => {
responseData.saleList = result;
responseData.resultShow = JSON.stringify(result, null, 4);
}).catch(() => {
res.render('error', { devEnv: true, pageErr: true });
res.render('sale/other', responseData);
});
// })
// .catch(() => {
// res.render('error', { devEnv: true, pageErr: true });
// });
};
/**
* 新降价专区
* 断码专区
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.newSale = (req, res) => {
exports.breakingYards = (req, res) => {
let params = Object.assign({
saleType: 1
}, req.query);
headerModel.requestHeaderData().then(responseData => {
responseData = headerModel.setHeaderData(responseData.data, 'newSale');
responseData.module = 'product';
responseData.page = 'sale';
responseData.footerTop = true;
responseData.devEnv = true;
let responseData = {};
// 假数据输出
// res.render('sale/other', Object.assign(responseData, simulation.other()));
// headerModel.requestHeaderData().then(responseData => {
// responseData = headerModel.setHeaderData(responseData.data, 'breakingYards');
responseData.module = 'product';
responseData.page = 'sale';
responseData.footerTop = true;
responseData.devEnv = true;
sale.getSaleData(params).then((result) => {
responseData.saleList = result;
responseData.resultShow = JSON.stringify(result, null, 4);
// 假数据输出
// res.render('sale/other', Object.assign(responseData, simulation.other()));
res.render('sale/other', responseData);
});
sale.getSalebreakingYardsData(params).then((result) => {
responseData.saleList = result;
responseData.resultShow = JSON.stringify(result, null, 4);
res.render('sale/other', responseData);
});
})
.catch(() => {
res.render('error', { devEnv: true, pageErr: true });
});
// }).catch(() => {
// res.render('error', { devEnv: true, pageErr: true });
// });
};
/**
... ...
/*
* @Author: Targaryen
* @Date: 2016-05-25 18:03:34
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-26 11:10:37
*/
'use strict';
const library = '../../../library';
const API = require(`${library}/api`).API;
const TARAPI = require(`${library}/tar-api`).TARAPI;
const api = new API();
const tarApi = new TARAPI();
const sign = require(`${library}/sign`);
const _ = require('lodash');
/**
* 获取商品列表 promise 对象
* @return {[type]} [description]
*/
exports.getSaleGoodsList = (params) => {
let tempParams = {
method: 'app.search.sales',
p_d: _.isEmpty(params.p_d) ? null : params.p_d,
limit: _.isEmpty(params.limit) ? null : params.limit,
order: _.isEmpty(params.order) ? 's_t_desc' : params.order,
page: _.isEmpty(params.page) ? 1 : params.page,
gender: _.isEmpty(params.gender) ? null : params.gender,
sort: _.isEmpty(params.sort) ? null : params.sort,
brand: _.isEmpty(params.brand) ? null : params.brand,
color: _.isEmpty(params.color) ? null : params.color,
size: _.isEmpty(params.size) ? null : params.size,
saleType: _.isEmpty(params.saleType) ? null : params.saleType,
breakSize: _.isEmpty(params.breakSize) ? null : params.breakSize,
breakSort: _.isEmpty(params.breakSort) ? null : params.breakSort,
productPool: _.isEmpty(params.productPool) ? null : params.productPool,
price: _.isEmpty(params.price) ? null : params.price,
productSize: '384x511',
yh_channel: 1
};
let finalParams = {};
_.forEach(tempParams, function(value, key) {
if (!_.isEmpty(value)) {
finalParams[key] = value;
}
});
return api.get('', sign.apiSign(finalParams));
};
/**
* 断码区分类信息数据 promise 对象
* @return {[type]} [description]
*/
exports.getSalebreakingYardsSortList = () => {
return api.get('', sign.apiSign({
method: 'app.sale.getBreakingSort',
yh_channel: 1
}));
};
/**
* 获取折扣专区活动列表 promise 对象
* @return {[type]} [description]
*/
exports.getSaleActivityList = () => {
return tarApi.getActivity('', sign.apiSign({
method: 'app.activity.get',
sort: 2,
plateform: 2
}));
};
/**
* 获取Sale首页顶部 banner promise 对象
* @return {[type]} [description]
*/
exports.getSaleBannerList = () => {
return tarApi.getBanner('', sign.apiSign({
content_code: '7c2b77093421efa8ae9302c91460db73'
}));
};
... ...
/*
* @Author: Targaryen
* @Date: 2016-05-25 18:16:59
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-26 18:25:08
*/
'use strict';
const library = '../../../library';
const helpers = require(`${library}/helpers`);
const _ = require('lodash');
const anHour = 3600000;
const aDay = anHour * 24;
const timeFormat = {
d: '剩{d}天',
h: '剩{h}小时',
m: '剩{m}分钟',
s: '剩{s}秒',
dh: '剩{d}天{h}小时',
dhms: '剩{d}天{h}小时{m}分钟{s}秒',
hms: '剩{h}小时{m}分钟{s}秒',
ms: '剩{m}分钟{s}秒'
};
/**
* 折扣专场专题列表过期时间处理
*/
const processTime = (time) => {
let data = {};
let type = '';
if (time < anHour) {
data.warnColor = true;
data.time = '即将结束';
} else {
if (time > aDay) {
type = 'dh';
} else {
type = 'h';
}
data.time = helpers.dateDiffFormat(timeFormat[type], time, 'ms');
}
return data.time;
};
/**
* 处理用于筛选的 URL
* @param {[type]} originParam [description]
* @param {[type]} newParam [description]
* @return {[type]} [description]
*/
const handleFilterUrl = (originParam, newParam) => {
let dest = '?';
let tempOriginParam = {};
// 创建 originParam、newParam 键的数组
let originParamArray = _.keys(originParam);
let newParamArray = _.keys(newParam);
// 判断参数是否已经存在
let isExist = !_.isEmpty(_.find(originParamArray, function(o) {
return o === newParamArray[0];
}));
if (isExist) {
tempOriginParam = Object.assign(tempOriginParam, originParam);
_.forEach(newParam, function(value, key) {
tempOriginParam[key] = value;
});
} else {
tempOriginParam = Object.assign(tempOriginParam, originParam, newParam);
}
_.forEach(tempOriginParam, function(value, key) {
dest = dest + key + '=' + value + '&';
});
return _.trim(dest, '&');
};
/**
* 处理商品列表数据
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.handleSaleGoodsListData = (origin) => {
var dest = [];
if (!_.isEmpty(origin)) {
_.forEach(origin, function(value) {
let oneGoods = {};
oneGoods.tags = value.tags;
oneGoods.thumb = value.default_images;
oneGoods.url = '/product/pro_' + value.product_id + '_' + value.goods_list[0].goods_id + '/' +
value.cn_alphabet + '.html';
oneGoods.goodsList = value.goods_list;
oneGoods.name = value.product_name;
oneGoods.brand = {};
oneGoods.brand.url = value.brand_domain + '.yohobuy.com'; // 待处理
oneGoods.brand.name = value.brand_name;
oneGoods.marketPrice = value.market_price;
dest.push(oneGoods);
});
}
return dest;
};
/**
* 处理筛选数据
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.handleSaleFilterData = (origin, params) => {
var dest = {};
dest.brand = {};
dest.price = [];
dest.channel = [];
dest.brand.default = [];
dest.brand.brandsShow = [];
dest.brand.brandIndex = [];
dest.brand.showMore = true;
dest.brand.showMulti = true;
// 品牌索引数据处理
dest.brand.brandIndex = [];
dest.brand.brandIndex[0] = {
index: 'all',
name: '全部'
};
dest.brand.brandIndex[1] = {
index: '0-9',
name: '0~9'
};
for (let i = 65; i < 91; i++) {
dest.brand.brandIndex.push({
index: String.fromCharCode(i).toLowerCase(),
name: String.fromCharCode(i)
});
}
// 品牌数据处理
if (!_.isEmpty(origin.brand)) {
let count = 0;
_.forEach(origin.brand, function(value) {
let brand = {};
brand.checked = false;
brand.href = handleFilterUrl(params, { brand: value.id });
brand.name = value.brand_name;
brand.key = value.brand_domain;
if (!_.isNaN(parseInt(value.brand_alif, 10))) {
brand.index = '0-9';
} else {
brand.index = value.brand_alif.toLowerCase();
}
if (count < 10) {
dest.brand.default.push(brand);
}
dest.brand.brandsShow.push(brand);
count++;
});
}
// 来排排序
dest.brand.brandsShow = _.sortBy(dest.brand.brandsShow, function(o) {
return o.index;
});
// 处理 价格 筛选数据
if (!_.isEmpty(origin.priceRange)) {
_.forEach(origin.priceRange, function(value, key) {
let price = {
checked: false,
href: handleFilterUrl(params, { price: key }),
name: value
};
dest.price.push(price);
});
}
// 处理频道数据
for (let i = 0; i < 2; i++) {
dest.channel[i] = {};
dest.channel[i].checked = false;
}
dest.channel[0].name = '男生';
dest.channel[0].href = handleFilterUrl(params, { gender: '1,3' });
dest.channel[1].name = '女生';
dest.channel[1].href = handleFilterUrl(params, { gender: '2,3' });
return dest;
};
/**
* 处理 opts 排序数据 待处理 待确认
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.handleSaleOptsData = (params) => {
var dest = {};
dest.countPerPage = 60;
dest.start = 1;
dest.end = 20;
dest.sortType = [];
for (let i = 0; i < 3; i++) {
let opt = {};
switch (i) {
case 0:
opt.href = handleFilterUrl(params, { order: 's_t_desc' });
opt.name = '最新';
break;
case 1:
opt.href = handleFilterUrl(params, { order: 's_p_asc' });
opt.name = '价格';
break;
case 2:
opt.href = handleFilterUrl(params, { order: 'p_d_asc' });
opt.name = '折扣';
break;
default:
break;
}
opt.hasSortOrient = {};
opt.hasSortOrient.active = {};
opt.hasSortOrient.active.desc = {};
dest.sortType.push(opt);
}
return dest;
};
/**
* 处理页面左侧分类筛选数据
* @return {[type]} [description]
*/
exports.handleSaleSortData = (origin, params) => {
var leftContent = {};
leftContent.allSort = {};
leftContent.allSort.list = [];
_.forEach(origin, function(value) {
let category = {};
category.name = value.category_name;
category.num = value.node_count;
category.childList = [];
_.forEach(value.sub, function(subValue) {
category.childList.push({
name: subValue.category_name,
num: subValue.node_count,
href: handleFilterUrl(params, { sort: subValue.relation_parameter.sort })
});
});
leftContent.allSort.list.push(category);
});
return leftContent;
};
/**
* 处理断码区分类筛选数据 待处理
* @return {[type]} [description]
*/
exports.handleSalebreakingYardsSortData = (origin, params) => {
var dest = [];
_.forEach(origin[0].sub, function(value) {
let size = {};
size.checked = false;
size.href = handleFilterUrl(params, { size: value.size_id });
size.name = value.size_name;
dest.push(size);
});
return dest;
};
/**
* 处理最新降价折扣信息
* @return {[type]} [description]
*/
exports.handleSaleNewSaleSortData = (params) => {
var dest;
dest = [{
name: '1~3折',
href: handleFilterUrl(params, { p_d: '0.1,0.3' }),
checked: false
}, {
name: '4~6折',
href: handleFilterUrl(params, { p_d: '0.4,0.6' }),
checked: false
}, {
name: '7折以上',
href: handleFilterUrl(params, { p_d: '0.7,1' }),
checked: false
}];
return dest;
};
/**
* 处理折扣专区活动数据
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.handleSaleActivityData = (origin) => {
var dest = {};
dest.big = [];
dest.normal = [];
_.forEach(origin, function(value, key) {
let activity = {};
activity.link = value.web_url;
activity.img = value.cover_url;
activity.time = processTime(value.left_time);
activity.brand = value.logo_url;
activity.discount = value.title;
if (key < 3) {
dest.big.push(activity);
} else {
dest.normal.push(activity);
}
});
return dest;
};
/**
* 处理首页 banner 数据
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.handleSaleBannerData = (origin) => {
var dest = {};
dest.list = [];
_.forEach(origin, function(value) {
if (value.template_name === 'focus') {
_.forEach(value.data, function(subValue) {
let banner = {};
banner.bannerHeight = 450;
banner.href = subValue.url;
banner.img = subValue.src;
dest.list.push(banner);
});
}
if (value.template_name === 'small_pic') {
_.forEach(value.data, function(picList) {
let smallPic = {};
smallPic.link = picList.url;
smallPic.icon = picList.src;
smallPic.title = picList.title;
smallPic.desc = picList.alt;
dest.list.push(smallPic);
});
}
});
return dest;
};
/**
* 处理首页 banner 小图
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.handleSaleBannerSmallData = (origin) => {
var dest = [];
_.forEach(origin, function(value) {
if (value.template_name === 'small_pic') {
_.forEach(value.data, function(picList) {
let smallPic = {};
smallPic.link = picList.url;
smallPic.icon = picList.src;
smallPic.title = picList.title;
smallPic.desc = picList.alt;
dest.push(smallPic);
});
}
});
return dest;
};
... ...
... ... @@ -2,327 +2,48 @@
* @Author: Targaryen
* @Date: 2016-05-19 10:20:08
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-25 10:04:06
* @Last Modified time: 2016-05-26 16:07:54
*/
'use strict';
const library = '../../../library';
const API = require(`${library}/api`).API;
const TARAPI = require(`${library}/tar-api`).TARAPI;
const sign = require(`${library}/sign`);
const api = new API();
const tarApi = new TARAPI();
const _ = require('lodash');
const saleApi = require('./sale-api');
const saleHandler = require('./sale-handler');
/**
* 处理商品列表数据
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
const handleSaleGoodsListData = (origin) => {
var dest = [];
if (!_.isEmpty(origin)) {
_.forEach(origin, function(value) {
let oneGoods = {};
oneGoods.tags = value.tags;
oneGoods.thumb = value.default_images;
oneGoods.url = '/product/pro_' + value.product_id + '_' + value.goods_list[0].goods_id + '/' +
value.cn_alphabet + '.html';
oneGoods.goodsList = value.goods_list;
oneGoods.name = value.product_name;
oneGoods.brand = {};
oneGoods.brand.url = value.brand_domain + '.SUB_DOMAIN'; // 待处理
oneGoods.brand.name = value.brand_name;
oneGoods.marketPrice = value.market_price;
dest.push(oneGoods);
});
}
return dest;
};
/**
* 处理筛选数据
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
const handleSaleFilterData = (origin) => {
var dest = {};
dest.brand = {};
dest.price = [];
dest.channel = [];
dest.opts = {};
// 处理 品牌 筛选数据
dest.brand.default = [];
if (!_.isEmpty(origin.brand)) {
_.forEach(origin.brand, function(value) {
let brand = {};
brand.checked = false;
brand.href = 'CURRENT_URL/brand=' + value.brand_domain; // 待处理
brand.name = value.brand_name;
dest.brand.default.push(brand);
});
}
// 处理 价格 筛选数据
if (!_.isEmpty(origin.priceRange)) {
_.forEach(origin.priceRange, function(value, key) {
let price = {
checked: false,
href: 'CURRENT_URL/price=' + key, // 待处理
name: value
};
dest.price.push(price);
});
}
// 处理频道数据
for (let i = 0; i < 2; i++) {
dest.channel[i] = {};
dest.channel[i].checked = false;
}
dest.channel[0].name = '男生';
dest.channel[0].href = 'CURRENT_URL/?gender=1,3';
dest.channel[1].name = '女生';
dest.channel[1].href = 'CURRENT_URL/?gender=2,3';
return dest;
};
/**
* 处理 opts 排序数据
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
const handleSaleOptsData = () => {
var dest = {};
dest.countPerPage = 60;
dest.start = 1;
dest.end = 20;
dest.sortType = [];
for (let i = 0; i < 2; i++) {
let opt = {};
opt.href = 'CURRENT_URL/?order=s_p_asc';
opt.name = '价格';
opt.hasSortOrient = {};
opt.hasSortOrient.active = {};
opt.hasSortOrient.active.desc = {};
dest.sortType.push(opt);
}
return dest;
};
/**
* 处理页面左侧分类筛选数据
* 获取Sale首页商品列表数据 仅 Ajax 调用 Controller 调用
* @return {[type]} [description]
*/
const handleSaleSortData = (origin) => {
var leftContent = {};
leftContent.allDiscount = {};
leftContent.allDiscount.list = [];
_.forEach(origin, function(value) {
let category = {};
category.name = value.sort_name;
leftContent.allDiscount.list.push(category);
});
return leftContent;
};
/**
* 处理折扣专区活动数据
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
const handleSaleActivityData = (origin) => {
var dest = {};
dest.big = [];
dest.normal = [];
_.forEach(origin, function(value, key) {
let activity = {};
activity.link = value.web_url;
activity.img = value.cover_url;
activity.time = value.left_time;
activity.brand = value.logo_url;
activity.discount = value.title;
if (key < 3) {
dest.big.push(activity);
} else {
dest.normal.push(activity);
}
});
return dest;
};
/**
* 处理首页 banner 数据
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
const handleSaleBannerData = (origin) => {
var dest = {};
dest.list = [];
_.forEach(origin, function(value) {
if (value.template_name === 'focus') {
_.forEach(value.data, function(subValue) {
let banner = {};
banner.bannerHeight = 450;
banner.href = subValue.url;
banner.img = subValue.src;
dest.list.push(banner);
});
}
if (value.template_name === 'small_pic') {
_.forEach(value.data, function(picList) {
let smallPic = {};
smallPic.link = picList.url;
smallPic.icon = picList.src;
smallPic.title = picList.title;
smallPic.desc = picList.alt;
dest.list.push(smallPic);
});
}
});
return dest;
};
/**
* 处理首页 banner 小图
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
const handleSaleBannerSmallData = (origin) => {
var dest = [];
_.forEach(origin, function(value) {
if (value.template_name === 'small_pic') {
_.forEach(value.data, function(picList) {
let smallPic = {};
exports.getSaleGoodsData = (params) => {
smallPic.link = picList.url;
smallPic.icon = picList.src;
smallPic.title = picList.title;
smallPic.desc = picList.alt;
return saleApi.getSaleGoodsList(params).then(result => {
let finalResult = {};
dest.push(smallPic);
});
if (result.code === 200) {
finalResult.goods = saleHandler.handleSaleGoodsListData(result.data.product_list);
}
return finalResult;
});
return dest;
};
/**
* 获取商品列表 promise 对象
* @return {[type]} [description]
*/
const getSaleGoodsList = (params) => {
return api.get('', sign.apiSign({
method: 'app.search.sales',
p_d: _.isEmpty(params.p_d) ? null : params.p_d,
limit: _.isEmpty(params.limit) ? null : params.limit,
order: _.isEmpty(params.order) ? 's_t_desc' : params.order,
page: _.isEmpty(params.page) ? 1 : params.page,
gender: _.isEmpty(params.gender) ? null : params.gender,
sort: _.isEmpty(params.sort) ? null : params.sort,
brand: _.isEmpty(params.brand) ? null : params.brand,
color: _.isEmpty(params.color) ? null : params.color,
size: _.isEmpty(params.size) ? null : params.size,
saleType: _.isEmpty(params.saleType) ? null : params.saleType,
breakSize: _.isEmpty(params.breakSize) ? null : params.breakSize,
breakSort: _.isEmpty(params.breakSort) ? null : params.breakSort,
productPool: _.isEmpty(params.productPool) ? null : params.productPool,
price: _.isEmpty(params.price) ? null : params.price,
productSize: '384x511',
yh_channel: 1
}));
};
/**
* 获取左侧分类信息数据 promise 对象
* @return {[type]} [description]
*/
const getSortList = () => {
return api.get('', sign.apiSign({
method: 'app.sale.getBreakingSort',
yh_channel: 1
}));
};
/**
* 获取折扣专区活动列表 promise 对象
* @return {[type]} [description]
*/
const getSaleActivityList = () => {
return tarApi.getActivity('', sign.apiSign({
method: 'app.activity.get',
sort: 2,
plateform: 2
}));
};
/**
* 获取顶部 banner
* @return {[type]} [description]
*/
const getSaleBannerList = () => {
return tarApi.getBanner('', sign.apiSign({
content_code: '7c2b77093421efa8ae9302c91460db73'
}));
};
/**
* 获取 Sale 首页数据
* 获取 Sale 首页数据 Controller 调用
* @return {[type]} [description]
*/
exports.getSaleIndexData = () => {
return api.all([getSaleActivityList(), getSaleBannerList()]).then(result => {
return api.all([saleApi.getSaleActivityList(), saleApi.getSaleBannerList()]).then(result => {
var finalResult = {};
if (result[0].code === 200) {
finalResult.brandSale = handleSaleActivityData(result[0].data);
finalResult.brandSale = saleHandler.handleSaleActivityData(result[0].data);
}
if (result[1].code === 200) {
finalResult.topBanner = handleSaleBannerData(result[1].data);
finalResult.activityEnter = handleSaleBannerSmallData(result[1].data);
finalResult.topBanner = saleHandler.handleSaleBannerData(result[1].data);
finalResult.activityEnter = saleHandler.handleSaleBannerSmallData(result[1].data);
}
return finalResult;
... ... @@ -330,64 +51,67 @@ exports.getSaleIndexData = () => {
};
/**
* 获取商品列表数据 仅 Ajax 调用时使
* 获取 VIP 会员专享和新降价专区数据 Controller 调
* @return {[type]} [description]
*/
exports.getSaleGoodsData = (params) => {
exports.getSaleOthersData = (params) => {
return getSaleGoodsList(params).then(result => {
return api.all([saleApi.getSaleGoodsList(params)]).then(result => {
let finalResult = {};
if (result.code === 200) {
finalResult.goods = handleSaleGoodsListData(result.data.product_list);
if (result[0].code === 200) {
finalResult.goods = saleHandler.handleSaleGoodsListData(result[0].data.product_list);
finalResult.filters = saleHandler.handleSaleFilterData(result[0].data.filter, params);
finalResult.leftContent = saleHandler.handleSaleSortData(result[0].data.filter.group_sort, params);
}
finalResult.filters.discount = saleHandler.handleSaleNewSaleSortData(params);
finalResult.opts = saleHandler.handleSaleOptsData(params);
return finalResult;
});
};
/**
* 获取其他三个页面全部数据
* 获取折扣专场数据 Controller 调用
* @return {[type]} [description]
*/
exports.getSaleData = (params) => {
return api.all([getSortList(), getSaleGoodsList(params)]).then(result => {
exports.getSaleDiscountData = (params) => {
return api.all([saleApi.getSaleGoodsList(params)]).then(result => {
let finalResult = {};
if (result[0].code === 200) {
finalResult.leftContent = handleSaleSortData(result[0].data);
finalResult.saleList = {};
finalResult.saleList.goods = saleHandler.handleSaleGoodsListData(result[0].data.product_list);
finalResult.leftContent = saleHandler.handleSaleSortData(result[0].data.filter.group_sort, params);
}
if (result[1].code === 200) {
if (!_.isEmpty(result[1].data.product_list)) { // 处理商品列表数据
finalResult.goods = handleSaleGoodsListData(result[1].data.product_list);
}
if (!_.isEmpty(result[1].data.filter)) {
finalResult.filters = handleSaleFilterData(result[1].data.filter);
}
}
finalResult.opts = handleSaleOptsData();
return finalResult;
});
};
/**
* 获取折扣专场数据
* @return {[type]} [description]
* 获取断码区数据 Controller 调用
* @param {[type]} params [description]
* @return {[type]} [description]
*/
exports.getDiscountData = (params) => {
return api.all([getSortList(), getSaleGoodsList(params)]).then(result => {
exports.getSalebreakingYardsData = (params) => {
return api.all([saleApi.getSaleGoodsList(params), saleApi.getSalebreakingYardsSortList()]).then(result => {
let finalResult = {};
if (result[0].code === 200) {
finalResult.leftContent = handleSaleSortData(result[0].data);
finalResult.goods = saleHandler.handleSaleGoodsListData(result[0].data.product_list);
finalResult.filters = saleHandler.handleSaleFilterData(result[0].data.filter, params);
finalResult.leftContent = saleHandler.handleSaleSortData(result[0].data.filter.group_sort, params);
}
if (result[1].code === 200) {
finalResult.saleList = {};
finalResult.saleList.goods = handleSaleGoodsListData(result[1].data.product_list);
finalResult.filters.size = saleHandler.handleSalebreakingYardsSortData(result[1].data, params);
}
finalResult.opts = saleHandler.handleSaleOptsData(params);
return finalResult;
});
};
... ...
... ... @@ -188,24 +188,29 @@ exports.discount = () => {
discount: '5折',
time: '12313'
},
sort: [
{
name: '全部',
number: 10
},
{
name: '上装',
number: 20
},
{
name: '夏装',
number: 5
},
{
name: '衣服',
number: 20
leftContent: {
allDiscount: {
list: [
{
name: '全部',
number: 10
},
{
name: '上装',
number: 20
},
{
name: '夏装',
number: 5
},
{
name: '衣服',
number: 20
}
]
}
],
},
filters: {
checkedConditions: {
... ... @@ -404,6 +409,52 @@ exports.other = () => {
href: 'asdad',
name: '品牌2'
}
],
showMore: true,
showMulti: true,
brandIndex: [
{
index: 1,
name: 'name1'
},
{
index: 2,
name: 'name2'
}
],
brandsShow: [
{
checked: false,
index: 1,
key: 'name1',
href: 'dasd',
id: 1,
name: '测试1'
},
{
checked: false,
index: 1,
key: 'name1',
href: 'dasd',
id: 1,
name: '测试2'
},
{
checked: false,
index: 1,
key: 'name1',
href: 'dasd',
id: 1,
name: '测试3'
},
{
checked: false,
index: 1,
key: 'name1',
href: 'dasd',
id: 1,
name: '测试4'
}
]
},
... ... @@ -449,11 +500,31 @@ exports.other = () => {
}
],
pageCounts: [
{
href: 'wdad',
count: 100,
},
{
href: 'wdad',
count: 80,
},
{
href: 'wdad',
count: 60,
},
],
// curpage 前面的点击的href
preHref: '213132',
countPerPage: 60,
pageCounts: {
href: 'wda',
count: '12'
},
curPage: 1,
pageCount: 20,
nextHref: 'nextPage',
start: 1,
end: 20
},
... ...
{{!-- <pre>{{resultShow}}</pre> --}}
{{# result}}
<div class="sale-discount-page yoho-page center-content .new-sale-page">
{{# saleList}}
{{> sale/sale-banner}}
{{> sale/sale-banner}}
<div class="center-content clearfix">
{{#saleTitle}}
<div class="sale-title">
<span class="title">{{title}}</span>
{{#if discount}}
<span class="discount">{{discount}}</span>
{{/if}}
{{#if up}}
{{/if}}
<div class="time pull-right">
<span class="iconfont">&#xe60d;</span>{{time}}
</div>
<div class="center-content clearfix">
{{#saleTitle}}
<div class="sale-title">
<span class="title">{{title}}</span>
{{#if discount}}
<span class="discount">{{discount}}</span>
{{/if}}
{{#if up}}
{{/if}}
<div class="time pull-right">
<span class="iconfont">&#xe60d;</span>{{time}}
</div>
{{/saleTitle}}
<ul class="sort">
<li class="title">分类:</li>
{{#sort}}
<li class="{{#if active}}active{{/if}}"><a href="#">{{name}}{{#if number}}({{number}}){{/if}}</a></li>
{{/sort}}
</ul>
</div>
{{/saleTitle}}
<ul class="sort">
<li class="title">分类:</li>
{{#leftContent}}
{{#allDiscount}}
{{#list}}
<li class="{{#if active}}active{{/if}}"><a href="#">{{name}}{{#if number}}({{number}}){{/if}}</a></li>
{{/list}}
{{/allDiscount}}
{{/leftContent}}
</ul>
</div>
{{# saleList}}
{{> product/standard-content}}
</div>
{{/ saleList}}
</div>
{{/ result}}
\ No newline at end of file
{{/ result}}
... ...
... ... @@ -3,8 +3,6 @@
<div class="sale-page yoho-page center-content">
{{! 头部banner}}
{{log this}}
{{#topBanner}}
{{> common/slide-banner}}
{{/topBanner}}
... ...
... ... @@ -12,7 +12,7 @@ const isTest = process.env.NODE_ENV === 'test';
module.exports = {
port: 6002,
domains: {
api: 'http://192.168.102.205:8080/gateway', // 192.168.102.205:8080 testapi.yoho.cn:28078
api: 'http://api.yoho.cn/', // 192.168.102.205:8080 testapi.yoho.cn:28078
service: 'http://testservice.yoho.cn:28077',
search: 'http://192.168.10.64:8080/yohosearch/'
},
... ...
... ... @@ -187,6 +187,19 @@
</div>
{{/if}}
{{#if discount}}
<div class="price section">
<span class="title">折扣:</span>
<div class="attr-content clearfix">
{{# discount}}
<a class="attr{{#if checked}} checked{{/if}}" href="{{href}}">¥{{name}}</a>
{{/ discount}}
</div>
</div>
{{/if}}
{{#if color}}
<div class="color section">
<span class="title">颜色:</span>
... ...
... ... @@ -7,6 +7,7 @@
const querystring = require('querystring');
const _ = require('lodash');
const config = require('../config/common');
const moment = require('moment');
/**
* 七牛图片路径处理
... ... @@ -75,3 +76,41 @@ exports.upperCase = (str) => {
str = str || '';
return str.toUpperCase();
};
/**
* 时间差格式化
* @param {[string]} format 格式化字符串
* @param {[number]} diff 相差值
* @param {[string]} type diff时间类型 默认ms
*
* Key Shorthand
* years y
* quarters Q
* months M
* weeks w
* days d
* hours h
* minutes m
* seconds s
* milliseconds ms
*
* @example
* let diff = 60 * 60 * 24 * (1.3) + 2;
*
* let s = helpers.dateDiffFormat('{d}天{h}小时', diff, 's');
* >>> 1天7小时
*/
exports.dateDiffFormat = (format, diff, type) => {
if (typeof format !== 'string' || typeof diff === 'undefined') {
return '';
} else {
type = type || 'ms';
const m = moment.duration(diff, type);
format.match(/(\{.*?\})/g).forEach((s) => {
format = format.replace(s, m.get(s.substring(1, s.length - 1)));
});
return format;
}
};
... ...
... ... @@ -48,6 +48,7 @@
"gulp-util": "^3.0.7",
"husky": "^0.11.4",
"mocha": "^2.4.5",
"moment": "^2.13.0",
"nodemon": "1.9.2",
"postcss-assets": "^4.0.1",
"postcss-cachebuster": "^0.1.2",
... ...
/**
* 商品筛选逻辑
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/12/4
*/
var $ = require('yoho-jquery'),
Handlebars = require('yoho-handlebars');
var checkUnicode = {
unchecked: '&#xe635;',
checked: '&#xe636;'
},
moreUnicode = {
up: '&#xe610;',
down: '&#xe600;'
};
// 品牌相关变量
var $brandDefault = $('.brand .default'),
$brandInput = $('#brand-search-input'),
$brandPanel = $('.brand .brand-panel'),
$brandAttrs = $brandPanel.find('.attr'),
$brandMore = $('#brand-more'),
$brandMulti = $('#brand-multi'),
$brandsIndex = $('.brands-index');
var $brandMoreTxt, $brandMoreIcon;
// 价格相关变量
var $udPrice = $('.ud-price-range'),
interReg = /^\d+$/,
$limit, $min, $max, $btn;
// 分类相关变量
var $sortSub = $('.sort-sub-wrap');
// 高级选项相关变量
var $seniorSubWrap = $('.senior-sub-wrap'),
$seniorAttrWrap = $('.senior-attr-wrap');
var seniorHoverTime, hoveredIndex;
// 尺寸 handlebars 模板
var sizeTmpl = '{{# size}}<a class="attr {{#if checked}}checked{{/if}}" href="{{href}}">{{name}}</a>{{/ size}}',
sizeCache = {}, // 缓存一下尺寸信息
$sizeWrap = $('.filter-box .size');
sizeTmpl = Handlebars.compile(sizeTmpl);
// 清除checkbox选中状态[页面默认checked不清空]
function clearChecked($checkbox, $checked) {
$checkbox.each(function() {
if ($(this).closest('.attr').hasClass('checked')) {
return;
}
$(this).removeClass('checked').html(checkUnicode.unchecked);
});
$checked.find('.checkbox').addClass('checked').html(checkUnicode.checked);
}
// 显示更多品牌面板
function brandShowMore() {
$brandDefault.addClass('hide');
$brandPanel.removeClass('hide');
}
// 隐藏更多品牌面板
function brandHideMore() {
$brandPanel.addClass('hide');
$brandDefault.removeClass('hide');
// 清除索引状态
$brandsIndex.children('span').removeClass('hover');
}
// url构造&跳转
function uriLoc(attr, val) {
var qs = window.queryString(),
newHref;
qs[attr] = val;
delete qs.page;
newHref = '?' + decodeURIComponent($.param(qs));
window.location.href = newHref;
}
// 隐藏高级选项面板
function hideSeniorPanel(index) {
$seniorSubWrap.children('.senior-sub:eq(' + hoveredIndex + ')').addClass('hide');
$seniorAttrWrap.children('.attr:eq(' + hoveredIndex + ')').removeClass('hover');
hoveredIndex = -1;
}
// 屏蔽筛选项双击文字选中
$('.filter-box').on('selectstart', '.attr, .brands-index span', function() {
return false;
});
// 【分类】
$('.sort-pre').on('click', 'li', function() {
var $this = $(this),
index = $this.index(),
id = $this.data('id');
if ($this.hasClass('active')) {
// 选中时,再次点击取消选中
$this.removeClass('active');
$sortSub.children(':eq(' + index + ')').addClass('hide');
$sizeWrap.addClass('hide');
return;
}
$this.siblings('.active').removeClass('active');
$this.addClass('active');
$sortSub.children(':not(.hide)').addClass('hide');
$sortSub.children(':eq(' + index + ')').removeClass('hide');
if (!$sizeWrap.data('load')) {
if (sizeCache[id]) {
$sizeWrap.find('.attr-content').html(sizeCache[id]);
$sizeWrap.removeClass('hide');
} else {
$.ajax({
url: '/product/search/sortSize',
data: {
msort: id
}
}).then(function(res) {
if ($.type(res) === 'array' && res.length) {
sizeCache[id] = sizeTmpl({
size: res
});
$sizeWrap.find('.attr-content').html(sizeCache[id]);
$sizeWrap.removeClass('hide');
} else {
$sizeWrap.addClass('hide');
}
});
}
}
});
// 【品牌】
if ($brandMore.length > 0) {
$brandMoreTxt = $brandMore.children('em');
$brandMoreIcon = $brandMore.children('.iconfont');
}
// 【品牌】多选
$brandMulti.click(function() {
if ($brandPanel.css('display') === 'none') {
// 显示品牌面板
$brandMore.trigger('click');
}
brandShowMore();
$brandPanel.removeClass('hide').addClass('multi'); // 显示出checkbox
$(this).addClass('hide');
// 隐藏更多按钮
$brandMore.addClass('hide');
});
// 【品牌】更多
$brandMore.click(function() {
var $this = $(this);
if ($this.hasClass('more')) {
brandHideMore();
$brandMoreTxt.text('更多');
$brandMoreIcon.html(moreUnicode.down);
// 清空搜索框和搜索结果
$brandInput.val('').trigger('keyup');
} else {
brandShowMore();
$brandMoreTxt.text('收起');
$brandMoreIcon.html(moreUnicode.up);
}
$(this).toggleClass('more');
});
// 【品牌】索引
$brandsIndex.on('mouseenter', 'span', function() {
var $this = $(this),
index = $this.data('index');
if ($this.hasClass('hover')) {
return;
}
setTimeout(function() {
$this.siblings('span.hover').removeClass('hover');
$this.addClass('hover');
if ($this.index() === 0) {
// 全部
$brandAttrs.removeClass('hide');
} else {
$brandAttrs.addClass('hide').filter('[data-index=' + index + ']').removeClass('hide');
}
}, 120);
});
// 【品牌】搜索
$brandInput.keyup(function() {
var val = $(this).val().toLowerCase();
if (val === '') {
$brandAttrs.removeClass('hide');
} else {
$brandAttrs.addClass('hide').filter('[data-key*="' + val + '"]').removeClass('hide');
}
});
// 【品牌】多选确定
$('#brand-multi-ok').click(function() {
var val = [];
if ($(this).hasClass('dis')) {
return;
}
$brandPanel.find('span.checked').each(function() {
val.push($(this).data('id'));
});
uriLoc('brand', val.join(','));
});
// 【品牌/高级选项】多选取消
$('.multi-select-cancel').click(function() {
var $panel = $(this).closest('.multi');
if ($panel.hasClass('brand-panel')) {
$brandMulti.removeClass('hide'); // 显示多选按钮
$brandMore.trigger('click');
// 显示出更多按钮
$brandMore.removeClass('hide');
// 清空搜索框和搜索结果
$brandInput.val('').trigger('keyup');
brandHideMore();
}
$panel.addClass('hide').removeClass('multi');
clearChecked($panel.find('.checkbox.checked'), $panel.find('.attr.checked')); // 清除选中状态
// 确定按钮状态恢复dis
$(this).siblings('.multi-select-ok').addClass('dis');
});
// 【品牌/高级选项】checkbox
$('.check-container').on('click', '.attr', function() {
var $this = $(this),
$check = $this.find('.checkbox'),
$btnOk = $this.closest('.brand-panel, .senior-sub').find('.multi-select-ok');
$check.toggleClass('checked');
if ($check.hasClass('checked')) {
$check.html(checkUnicode.checked);
} else {
$check.html(checkUnicode.unchecked);
}
// 更新按钮状态
if ($check.hasClass('checked') ||
$this.siblings('.attr').find('.checked').length > 0) {
$btnOk.removeClass('dis');
} else {
$btnOk.addClass('dis');
}
});
// 【品牌/高级选项】当多选时阻止链接默认跳转
$('.brand, .senior').on('click', '.attr > a', function(e) {
if ($(this).closest('.multi').length > 0) {
e.preventDefault();
}
});
// 已选中的条件,点击不刷新
$('.filter-box').on('click', 'li.checked, a.checked', function(e) {
e.preventDefault();
});
// 【价格】用户定义价格处理
if ($udPrice.length > 0) {
$limit = $udPrice.find('.limit');
$min = $limit.filter('.min');
$max = $limit.filter('.max');
$btn = $udPrice.find('.price-sure');
// 【价格】输入
$limit.keyup(function() {
var thisPrice = $.trim($(this).val()),
isPriInt = interReg.test(thisPrice),
intPrice,
min,
max;
if (!isPriInt) {
intPrice = parseInt(thisPrice, 10);
$(this).val(isNaN(intPrice) ? '' : intPrice);
}
min = $.trim($min.val());
max = $.trim($max.val());
if (min !== '' || max !== '') {
$btn.removeClass('hide');
} else {
$btn.addClass('hide');
}
});
// 【价格】多项查询
$btn.click(function() {
var min = $.trim($min.val()),
max = $.trim($max.val()),
tmp;
// 对于min大于max的情况,交换位置
if (min !== '' && max !== '' && +min > +max) {
tmp = max;
max = min;
min = tmp;
}
uriLoc('price', min + ',' + max);
});
}
// 【高级选项】鼠标移入显示子项
$seniorAttrWrap.on('mouseenter', '.attr', function() {
var $this = $(this);
var index = $this.index();
if ($this.hasClass('no-sub')) {
return;
}
$this.addClass('hover').siblings().removeClass('hover');
$seniorSubWrap.children('.senior-sub:eq(' + index + ')').removeClass('hide').siblings().addClass('hide');
}).on('mouseleave', '.attr', function() {
var $this = $(this),
index = $this.index();
if ($this.hasClass('no-sub')) {
return;
}
hoveredIndex = index;
seniorHoverTime = setTimeout(function() {
hideSeniorPanel();
}, 100);
});
// 【高级选项】多选
$('.senior-sub').on('click', '.multi-select', function() {
$(this).closest('.senior-sub').addClass('multi');
}).on('click', '.multi-select-ok', function() {
var $btn = $(this),
$sub = $btn.closest('.senior-sub'),
val = [];
if ($btn.hasClass('dis')) {
return;
}
$sub.find('span.checked').each(function() {
val.push($(this).data('id'));
});
uriLoc($sub.data('attr'), val.join(','));
}).on('mouseenter', function() {
clearTimeout(seniorHoverTime);
}).on('mouseleave', function() {
hideSeniorPanel();
});
... ...
/**
* 筛选页和列表页操作banner中的每页N个商品选择逻辑
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/12/4
*/
var $ = require('yoho-jquery');
var $countPerPage = $('#count-per-page'),
$countChose = $countPerPage.next('ul');
var SLIDETIME = 200;
$(document).click(function(e) {
if ($(e.target).closest('.page-count').length > 0) {
return;
}
$countChose && $countChose.slideUp(SLIDETIME);
});
$countPerPage.click(function() {
if ($countChose.css('display') === 'none') {
$countChose.slideDown(SLIDETIME);
} else {
$countChose.slideUp(SLIDETIME);
}
});
... ...
... ... @@ -5,8 +5,10 @@ var $ = require('yoho-jquery'),
var product = require('./product');
require('./sale/banner');
require('../header');
require('../common/slider');
require('../common/filter');
require('../common/sort-pager');
product.init();
lazyLoad($('img.lazy'));
... ...