Authored by 李靖

开发完成

'use strict';
const materialModel = require('../models/material');
const headerModel = require('../../../doraemon/models/header'); // 头部model
exports.list = (req, res, next) => {
let responseData = {
pageHeader: headerModel.setNav({
navTitle: '商品列表',
}),
title: '商品列表',
module: '3party',
page: 'material',
width750: true,
localCss: true
};
let params = {
uid: req.user.uid,
page: 1,
isApp: req.yoho.isApp
};
req.ctx(materialModel).canLogin(params).then(result => {
if (result === 'N') {
return next();
} else {
req.ctx(materialModel).list(params).then(list => {
res.render('material', Object.assign(responseData, list));
}).catch(next);
}
}).catch(next);
};
exports.moreGoods = (req, res, next) => {
let params = {
page: req.query.page || 2,
isApp: req.yoho.isApp
};
req.ctx(materialModel).list(params).then(result => {
res.json(result);
}).catch(next);
};
... ...
'use strict';
const platformApi = new global.yoho.ApiBase(global.yoho.config.domains.platformApi, {
name: 'imCs',
cache: global.yoho.cache,
useCache: false
});
const _ = require('lodash');
class materialModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
canLogin(params) {
return platformApi.get('/platform/product/material/canlogin', {
uid: params.uid
}).then(result => {
if (result && result.code === 200) {
return result.data.canLogin;
}
});
}
list(params) {
return platformApi.get('/platform/product/material/getRecommendProductList', {
page: params.page || 1
}).then(result => {
if (result && result.code === 200) {
let resu = {
goods: []
};
if (result && result.data && result.data.product_list) {
let build = [];
_.forEach(result.data.product_list, (val) => {
build.push({
product_name: val.productName,
default_images: val.picImgUrl,
url: `//m.yohobuy.com/product/${val.productSkn}.html`
});
});
resu.goods = build;
}
return resu;
}
});
}
}
module.exports = materialModel;
... ...
... ... @@ -13,6 +13,7 @@ const check = require(`${cRoot}/check`);
const question = require(`${cRoot}/question`);
const validateCode = require('../passport/controllers/validateCode');
const auth = require('../../doraemon/middleware/auth');
const material = require(`${cRoot}/material`);
// routers
... ... @@ -25,5 +26,7 @@ router.get('/questionnaire', auth, question.list);
router.post('/questionnaire/check', question.check);
router.post('/questionnaire/submit', question.submit);
router.get('/questionnaire/:id', auth, question.detail);
router.get('/material', auth, material.list);
router.get('/material/moreGoods', auth, material.moreGoods);
module.exports = router;
... ...
<div class="material-c">
<div class="goods-list">
{{# goods}}
{{> common/goods}}
{{/goods}}
</div>
</div>
\ No newline at end of file
... ...
... ... @@ -17,7 +17,8 @@ const domains = {
global: 'http://global-test-soa.yohops.com:9999',
liveApi: 'http://testapi.live.yohops.com:9999/',
imSocket: 'ws://socket.yohobuy.com:10240',
imCs: 'http://im.yohobuy.com/api'
imCs: 'http://im.yohobuy.com/api',
platformApi: 'http://192.168.102.48:8088/'
};
module.exports = {
... ...
{{# goods}}
{{> common/goods}}
{{/ goods}}
\ No newline at end of file
... ...
'use strict';
import {
Controller
} from 'yoho-mvc';
import {
GetMore
} from './view';
import {
moreGoods as getMore
} from './model';
const lazyLoad = require('yoho-jquery-lazyload');
const goodContent = require('3party/material/goods.hbs');
class MaterialController extends Controller {
constructor() {
super();
lazyLoad($('img.lazy'));
this.more = new GetMore();
this.more.on('more', this.doMore.bind(this));
this.page = 1;
this.loading = false;
}
doMore() {
if (!this.end && !this.loading) {
this.page ++;
this.moreGood(this.page);
}
}
moreGood(page) {
this.loading = true;
$('.material-c').append('<p class="show-more good-more">加载更多...</p>');
getMore('//m.yohobuy.com/3party/material/moreGoods', {page: page}).then(data => {
if (data.goods.length > 0) {
$('.goods-list').append(goodContent(data));
// 每次只lazyload倒数10
lazyLoad($('img.lazy'));
} else {
$('.material-c').append('<p class="show-more">没有更多了...</p>');
this.end = true;
}
}).catch(() => {}).finally(() => {
this.loading = false;
$('.good-more').remove();
});
}
}
module.exports = MaterialController;
... ...
require('3party/material.page.css');
const MaterialController = require('./controller');
new MaterialController();
... ...
'use strict';
import {
http
} from 'yoho-mvc';
function moreGoods(url, data) {
return http({
url: location.protocol + url,
data: data,
});
}
export {
moreGoods
};
... ...
import {
View
} from 'yoho-mvc';
class GetMore extends View {
constructor() {
super('.material-c');
// srcoll to load more
$(window).scroll(() => {
window.requestAnimationFrame(this.scrollHandler.bind(this));
});
}
scrollHandler() {
if (($(window).scrollTop() + $(window).height() >= $(document).height() * 0.8)) {
this.emit('more');
}
}
}
export {
GetMore
};
... ...
@import "common/good";
.material-c {
.goods-list {
padding-left: 15px;
}
.show-more {
text-align: center;
color: #b0b0b0;
font-size: 28px;
clear: both;
line-height: 88px;
}
.good-detail-text {
.price {
display: none;
}
}
}
... ...