Authored by 王水玲

商品素材列表

... ... @@ -2,34 +2,55 @@
const Model = require('../models/material');
exports.index = (req, res, next) => {
if (req.user.uid) {
Model.index(req).then(data => {
let result = {};
if (data.code == 200) {
result.product_list = data.data.product_list;
} else {
result.product_list = '';
}
res.render('material', Object.assign({module: '3party', page: 'material', layout: false }, result));
}).catch(next);
} else {
res.send(500);
}
const index = (req, res, next) => {
let uid = req.user.uid;
Model.canLogin(uid).then(canLogin => {
if (canLogin === 'N') {
return next();
} else {
Model.getList({
page: 1,
maxSortId: 0,
middleSortId: 0,
smallSortId: 0
}).then(result => {
if (result && result.code === 200) {
res.render('material', Object.assign({
module: '3party',
page: 'material',
layout: false
}, result.product_list));
}
});
}
}).catch(next);
};
exports.newBrandList = (req, res, next) => {
const newBrandList = (req, res, next) => {
Model.newBrandList(req).then(data => {
res.send(data);
}).catch(next);
};
exports.getCategory = (req, res, next) => {
const getCategory = (req, res, next) => {
Model.getCategory().then(data => {
res.send(data);
}).catch(next);
};
const getList = (req, res, next) => {
Model.getList(req.query).then(result => {
res.send(result);
}).catch(next);
};
const getRecommendlist = (req, res, next) => {
Model.getRecommendlist().then(result => {
res.send(result);
}).catch(next);
};
// exports.getIndexGuide = (req, res, next) => {
// channelModel.getIndexGuideData().then(data => {
// if (data.code !== 200) {
... ... @@ -53,3 +74,11 @@ exports.getCategory = (req, res, next) => {
// res.send(data);
// }).catch(next);
// };
module.exports = {
index,
newBrandList,
getCategory,
getList,
getRecommendlist
};
... ...
... ... @@ -7,21 +7,16 @@ const platformApi = new global.yoho.ApiBase(global.yoho.config.domains.platformA
});
const api = global.yoho.API;
const index = (req) => {
return platformApi.get('/platform/product/material/canlogin', { uid: req.user.uid }).then(data => {
console.log(data);
let params = {
brandId: 1,
shelveTimeBegin: '2012-02-1 09:53:10',
shelveTimeEnd: '2017-03-10 09:53:10',
page: 1
};
return platformApi.get('/platform/product/material/getList', Object.assign({
method: ''
}, params), { cache: true });
const canLogin = (uid) => {
return platformApi.get('/platform/product/material/canlogin', {
uid: uid
}).then(result => {
if (result && result.code === 200) {
return result.data.canLogin;
}
});
};
const newBrandList = (req) => {
let channel = req.query.yh_channel || 1;
... ... @@ -32,9 +27,24 @@ const getCategory = () => {
return api.get('', {method: 'web.regular.groupsort'});
};
const getList = (params) => {
return platformApi.get('/platform/product/material/getList', params, {
code: 200
});
};
const getRecommendlist = () => {
return platformApi.get('/platform/product/material/getRecommendlist', {
page: 1
}, {
code: 200
});
};
module.exports = {
index,
canLogin,
newBrandList,
getCategory
getCategory,
getList,
getRecommendlist
};
... ...
... ... @@ -22,5 +22,7 @@ router.post('/check', robot.check, robot.isHuman);
router.get('/material', auth, materialController.index);
router.get('/material/newBrandList', auth, materialController.newBrandList);
router.get('/material/getCategory', auth, materialController.getCategory);
router.get('/material/getList', auth, materialController.getList);
router.get('/material/getRecommendlist', auth, materialController.getRecommendlist);
module.exports = router;
... ...
... ... @@ -21,29 +21,30 @@
</head>
<body>
{{#if pageErr}} {{> 404}} {{^}}
<div class="product_material">
<h1>商品素材列表页</h1>
<div class="line">
<label>品牌:</label>
<input id="brand" type="text" readonly="readonly">
<label for="" style="margin-left: 10px;">首次上架时间:</label>
<input type="date" class="sel">
<label for="" style="margin-left: 10px;">首次上架开始时间:</label>
<input type="date" class="sel start-time">
<label for="" style="margin-left: 10px;">首次上架结束时间:</label>
<input type="date" class="sel end-time">
<div id="brand_container"></div>
</div>
<div class="line">
<label for="">品类:</label>
<select name="" id="category" class="sel">
<option value="1">品牌</option>
<option value="2">品类</option>
<option value="3">首次上架时间</option>
</select>
<select name="" id="category-1" class="sel"></select>
<select name="" id="category-2" class="sel"></select>
<select name="" id="category-3" class="sel"></select>
<div class="search-recommend-btn">商品素材推荐列表</div>
<div class="search-btn">商品素材列表</div>
</div>
{{>tbl}}
<div class="table-data">
{{> tbl}}
</div>
<div class="mask"></div>
</div>
{{/if}}
{{#if devEnv}}
<script src="//{{devHost}}:5002/libs.js"></script>
<script src="//{{devHost}}:5002/{{module}}.{{page}}.js"></script>
... ...
<table border="1" class="table">
<tr><th>skn</th><th>商品前台名称</th><th>默认图片</th><th>经典款型</th><th>风格</th><th>图案纹理</th><th>工艺元素</th></tr>
{{#each product_list}}
<tr>
<td>{{productSkn}}</td>
<td>{{productName}}</td>
<td><img src="{{picImgUrl}}" alt=""></td>
<td>{{standardVal}}</td>
<td>{{style}}</td>
<td>{{pattern}}</td>
<td>{{makeCrafts}}</td>
<th>skn</th>
<th>商品前台名称</th>
<th>默认图片</th>
<th>经典款型</th>
<th>风格</th>
<th>图案纹理</th>
<th>工艺元素</th>
</tr>
{{#each product_list}}
<tr>
<td>{{productSkn}}</td>
<td>{{productName}}</td>
<td><img src="{{picImgUrl}}" alt=""></td>
<td>{{standardVal}}</td>
<td>{{style}}</td>
<td>{{pattern}}</td>
<td>{{makeCrafts}}</td>
</tr>
{{/each}}
</table>
\ No newline at end of file
... ...
<table border="1" class="table">
<tr>
<th>skn</th>
<th>商品前台名称</th>
<th>默认图片</th>
<th>经典款型</th>
<th>风格</th>
<th>图案纹理</th>
<th>工艺元素</th>
</tr>
{{#each product_list}}
<tr>
<td>{{productSkn}}</td>
<td>{{productName}}</td>
<td><img src="{{picImgUrl}}" alt=""></td>
<td>{{standardVal}}</td>
<td>{{style}}</td>
<td>{{pattern}}</td>
<td>{{makeCrafts}}</td>
</tr>
{{/each}}
</table>
\ No newline at end of file
... ...
var $ = require('yoho-jquery');
const brand_tmp = require('hbs/material/brand.hbs');
var _ = require('lodash');
var brandTmp = require('hbs/material/brand.hbs');
var tableTmp = require('hbs/material/tbl.hbs');
var $mask = $('.mask');
var $brand = $('#brand_container');
var query = {
page: 1,
maxSortId: 0,
middleSortId: 0,
smallSortId: 0
};
let $mask = $('.mask');
let $brand = $('#brand_container');
function brandItemEventBind() {
$('#brand_container .item').off().on('click', function() {
var id = $(this).data('id');
var text = $(this).text();
query.brandId = id;
$('#brand').val(text);
$mask.hide();
$brand.hide();
});
}
/* 获取品牌数据*/
function getBrandList(_index, yhChannel) {
$.get('/3party/material/newBrandList?yh_channel=' + yhChannel, function(data) {
var list = [];
list = Object.keys(data.data.all_list).map(item => {
return { name: item, content: data.data.all_list[item] };
});
list['focus' + _index] = true;
$('#brand_container').html(brandTmp({ list }));
brandItemEventBind();
});
}
function getCategoryOpt(opts) {
var html = '';
$.each(opts, function(k, c) {
html += '<option value="' + c.sort_id + '">' + c.sort_name + '</option>';
});
return html;
}
getBrandList(1, 1);
/* 获取品类数据*/
$.get('/3party/material/getCategory', function(res) {
var $category1 = $('#category-1'),
$category2 = $('#category-2'),
$category3 = $('#category-3'),
sub = [],
categoryData = [];
if (res && res.code === 200) {
categoryData = res.data.sort;
$category1.html(getCategoryOpt(categoryData));
query.maxSortId = $category1.find('option').eq(0).attr('value');
let query = {};
$category1.on('change', function() {
var id = $(this).val();
$('#filter').on('change', () => {
if ($('#filter').find('option:selected').attr('value') == 3) {
$('.date').show();
sub = _.find(categoryData, {sort_id: id}).sub;
$category2.html(getCategoryOpt(sub)).show();
$category3.html('').hide();
query.maxSortId = id;
query.middleSortId = $category2.find('option').eq(0).attr('value');
});
$category2.on('change', function() {
var id = $(this).val();
var third = _.find(sub, {sort_id: id}).sub;
$category3.html(getCategoryOpt(third)).show();
query.middleSortId = id;
query.smallSortId = $category3.find('option').eq(0).attr('value');
});
$category3.on('change', function() {
query.smallSortId = $(this).val();
});
}
});
/* 品牌点击*/
$('#brand').on('click', () => {
if ($brand.css('display') == 'none') {
$('#brand').on('click', function() {
if ($brand.css('display') === 'none') {
$brand.css('display', 'block');
$mask.show();
} else {
... ... @@ -29,40 +105,42 @@ $mask.click(function() {
});
$(document).on('click', '#brand_container .nav span', function() {
var yhChannel = $(this).attr('yh_channel');
$('#brand_container .nav span').removeClass('focus');
$(this).addClass('focus');
let yh_channel = $(this).attr('yh_channel');
getBrandList($(this).attr('_index'), yh_channel);
getBrandList($(this).attr('_index'), yhChannel);
});
/* 获取品牌数据*/
function getBrandList(_index, yh_channel) {
$.get('/3party/material/newBrandList?yh_channel=' + yh_channel, data => {
let list = [];
list = Object.keys(data.data.all_list).map(item => {
return { name: item, content: data.data.all_list[item] };
});
list['focus' + _index] = true;
$('#brand_container').html(brand_tmp({ list }));
brand_item_event_bind();
});
}
getBrandList(1, 1);
$('.start-time').on('change', function() {
query.shelveTimeBegin = $(this).val() + ' 00:00:00';
});
/* 获取品类数据*/
$.get('/3party/material/getCategory', data => {
console.log(data);
$('.end-time').on('change', function() {
query.shelveTimeEnd = $(this).val() + ' 23:59:59';
});
function brand_item_event_bind() {
$('#brand_container .item').off().on('click', function() {
let id = $(this).data('id');
let text = $(this).text();
$('.search-btn').on('click', function() {
$.ajax({
url: '/3party/material/getList',
data: query,
type: 'get',
success: function(data) {
if (data && data.code === 200) {
$('.table-data').html(tableTmp({product_list: data.data.product_list}));
}
}
});
});
query.brandId = id;
$('#brand').val(text);
$mask.hide();
$brand.hide();
$('.search-recommend-btn').on('click', function() {
$.ajax({
url: '/3party/material/getRecommendlist',
type: 'get',
success: function(data) {
if (data && data.code === 200) {
$('.table-data').html(tableTmp({product_list: data.data.product_list}));
}
}
});
}
});
... ...
.product_material {
width: 1200px;
margin: auto;
font-family: '微软雅黑';
font-size: 14px;
h1 {
font-size: 30px;
margin: 15px 0 50px;
text-align: center;
}
/*过滤*/
/* 过滤 */
.line {
width: 1200px;
margin: 10px auto;
}
.sel {
width: 150px;
width: 173px;
vertical-align: middle;
height: 24px;
box-sizing: border-box;
}
label,
a {
vertical-align: middle;
}
/*品牌*/
/* 品牌 */
#brand {
position: relative;
height: 24px;
box-sizing: border-box;
label {
cursor: pointer
}
}
#brand_container {
position: absolute;
width: 1200px;
... ... @@ -34,8 +47,10 @@
display: none;
height: 800px;
overflow: auto;
.nav {
overflow: hidden;
span {
display: inline-block;
width: 25%;
... ... @@ -45,19 +60,23 @@
cursor: pointer;
float: left;
}
.focus {
background: #eee;
}
}
.title {
padding: 5px 0;
background: #555;
color: #fff;
text-align: center;
}
.content {
background: #fff;
}
.item {
display: inline-block;
width: 10%;
... ... @@ -76,35 +95,72 @@
}
}
}
#category-2 {
display: none;
}
#category-3 {
display: none;
}
.search-btn {
float: right;
border-radius: 2px;
background: #000;
padding: 5px 15px;
color: #fff;
font-size: 14px;
cursor: pointer;
margin-right: 20px;
}
.search-recommend-btn {
float: right;
border-radius: 2px;
background: #000;
padding: 5px 15px;
color: #fff;
font-size: 14px;
cursor: pointer;
}
/*表格*/
table {
width: 1200px;
margin: 20px auto;
}
table {
table-layout: fixed;
empty-cells: show;
border-collapse: collapse;
img {
width: 80px;
}
}
td {
height: 30px;
}
.table {
border: 1px solid #cad9ea;
color: #666;
}
.table th {
background-repeat: repeat-x;
height: 30px;
}
.table td,
.table th {
border: 1px solid #cad9ea;
padding: 0 1em 0;
}
.table tr.alter {
background-color: #f5fafe;
}
... ...