Authored by 姜枫

change module

'use strict';
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({ page: 'material', layout: false }, result));
}).catch(next);
} else {
res.send(500);
}
};
exports.newBrandList = (req, res, next) => {
Model.newBrandList(req).then(data => {
res.send(data);
}).catch(next);
};
exports.getCategory = (req, res, next) => {
Model.getHeaderNavAsync().then(data => {
res.send(data);
}).catch(next);
};
// exports.getIndexGuide = (req, res, next) => {
// channelModel.getIndexGuideData().then(data => {
// if (data.code !== 200) {
// const err = new Error('异常');
// throw err;
// }
// return channelModel.formatIndexGuideData(data.data);
// }).then(data => {
// return channelModel.getResourceData(data);
// }).then(data => {
// let result = {list: data, layout: false};
// res.render('guide', result);
// }).catch(next);
// };
// exports.hasNewUserFloor = (req, res, next) => {
// channelModel.hasNewUserFloor(req.yoho.channel, req.user.uid).then(data => {
// res.send(data);
// }).catch(next);
// };
... ...
'use strict';
const api = global.yoho.API;
const serviceApi = global.yoho.ServiceAPI;
const index = (req) => {
return api.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 api.get('/platform/product/material/getList', Object.assign({
method: ''
}, params), { cache: true });
});
};
const newBrandList = (req) => {
let channel = req.query.yh_channel || 1;
return serviceApi.get('', { method: 'app.brand.newBrandList', yh_channel: channel });
};
const getHeaderNavAsync = () => {
return serviceApi.get('operations/api/v6/category/getCategory', {});
};
module.exports = {
index,
newBrandList,
getHeaderNavAsync
};
... ...
... ... @@ -9,11 +9,18 @@
const router = require('express').Router(); // eslint-disable-line
const cRoot = './controllers';
const auth = require(`${global.middleware}/auth`);
const ads = require(`${cRoot}/ads`); // 第三方广告平台对接
const robot = require(`${cRoot}/robot-check`); // 机器人检查
const materialController = require(`${cRoot}/material`);
router.get('/ads', ads.jump);
router.get('/check', robot.index);
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);
module.exports = router;
... ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{title}}</title>
<meta name="keywords" content="{{keywords}}">
<meta name="description" content="{{description}}"> {{#if cononicalURL}}
<link rel="cononical" href="{{cononicalURL}}" /> {{/if}}
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta http-equiv="cleartype" content="on">
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta content="telephone=no" name="format-detection" />
<meta content="email=no" name="format-detection" /> {{#dnsPrefetch.hosts}}
<link rel="dns-prefetch" href="{{this}}"> {{/dnsPrefetch.hosts}}
{{#if devEnv}}
<link rel="stylesheet" href="//{{devHost}}:5002/css/index.css">
{{^}}
<link rel="stylesheet" href="//{{#isEqual cdn 'qcloud'}}qcdn.yoho.cn{{^}}cdn.yoho.cn{{/isEqual}}/yohobuy-node/{{version}}/index.css">
{{/if}}
</head>
<body>
{{#if pageErr}} {{> 404}} {{^}}
<div class="product_material">
<h1>商品素材列表页</h1>
<div class="line">
<a id="brand"><label>品牌>>></label><span id="brand_container"></span></a>
<label for="" style="margin-left: 10px;">首次上架时间</label>
<input type="date" class="sel">
</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>
</div>
{{>tbl}}
</div>
{{/if}}
{{#if devEnv}}
<script src="//{{devHost}}:5002/libs.js"></script>
<script src="//{{devHost}}:5002/{{module}}.{{page}}.js"></script>
{{^}}
<script src="//{{#isEqual cdn 'qcloud'}}qcdn.yoho.cn{{^}}cdn.yoho.cn{{/isEqual}}/yohobuy-node/{{version}}/libs.js"></script>
<script src="//{{#isEqual cdn 'qcloud'}}qcdn.yoho.cn{{^}}cdn.yoho.cn{{/isEqual}}/yohobuy-node/{{version}}/{{module}}.{{page}}.js"></script>
{{> analysis}}
{{/if}}
</body>
</html>
... ...
<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');
$('#filter').on('change', () => {
if ($('#filter').find('option:selected').attr('value') == 3) {
$('.date').show();
}
});
/* 品牌点击*/
$('#brand label').on('click', () => {
if ($('#brand_container').css('display') == 'none') {
$('#brand_container').css('display', 'block');
} else {
$('#brand_container').hide();
}
});
$(document).on('click', '#brand_container .nav span', function() {
$('#brand_container .nav span').removeClass('focus');
$(this).addClass('focus');
let yh_channel = $(this).attr('yh_channel');
getBrandList($(this).attr('_index'), yh_channel);
});
/* 获取品牌数据*/
function getBrandList(_index, yh_channel) {
$.get('/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 }));
});
}
getBrandList(1, 1);
/* 获取品类数据*/
$.get('/material/getCategory', data => {
console.log(data);
});
... ...