Showing
11 changed files
with
233 additions
and
1 deletions
apps/3party/controllers/material.js
0 → 100644
1 | + | ||
2 | +'use strict'; | ||
3 | + | ||
4 | +const materialModel = require('../models/material'); | ||
5 | +const headerModel = require('../../../doraemon/models/header'); // 头部model | ||
6 | + | ||
7 | +exports.list = (req, res, next) => { | ||
8 | + let responseData = { | ||
9 | + pageHeader: headerModel.setNav({ | ||
10 | + navTitle: '商品列表', | ||
11 | + }), | ||
12 | + title: '商品列表', | ||
13 | + module: '3party', | ||
14 | + page: 'material', | ||
15 | + width750: true, | ||
16 | + localCss: true | ||
17 | + }; | ||
18 | + | ||
19 | + let params = { | ||
20 | + uid: req.user.uid, | ||
21 | + page: 1, | ||
22 | + isApp: req.yoho.isApp | ||
23 | + }; | ||
24 | + | ||
25 | + req.ctx(materialModel).canLogin(params).then(result => { | ||
26 | + if (result === 'N') { | ||
27 | + return next(); | ||
28 | + } else { | ||
29 | + req.ctx(materialModel).list(params).then(list => { | ||
30 | + res.render('material', Object.assign(responseData, list)); | ||
31 | + }).catch(next); | ||
32 | + } | ||
33 | + }).catch(next); | ||
34 | +}; | ||
35 | + | ||
36 | +exports.moreGoods = (req, res, next) => { | ||
37 | + let params = { | ||
38 | + page: req.query.page || 2, | ||
39 | + isApp: req.yoho.isApp | ||
40 | + }; | ||
41 | + | ||
42 | + req.ctx(materialModel).list(params).then(result => { | ||
43 | + res.json(result); | ||
44 | + }).catch(next); | ||
45 | +}; |
apps/3party/models/material.js
0 → 100644
1 | +'use strict'; | ||
2 | + | ||
3 | +const platformApi = new global.yoho.ApiBase(global.yoho.config.domains.platformApi, { | ||
4 | + name: 'imCs', | ||
5 | + cache: global.yoho.cache, | ||
6 | + useCache: false | ||
7 | +}); | ||
8 | +const _ = require('lodash'); | ||
9 | + | ||
10 | +class materialModel extends global.yoho.BaseModel { | ||
11 | + constructor(ctx) { | ||
12 | + super(ctx); | ||
13 | + } | ||
14 | + | ||
15 | + canLogin(params) { | ||
16 | + return platformApi.get('/platform/product/material/canlogin', { | ||
17 | + uid: params.uid | ||
18 | + }).then(result => { | ||
19 | + if (result && result.code === 200) { | ||
20 | + return result.data.canLogin; | ||
21 | + } | ||
22 | + }); | ||
23 | + } | ||
24 | + | ||
25 | + list(params) { | ||
26 | + return platformApi.get('/platform/product/material/getRecommendProductList', { | ||
27 | + page: params.page || 1 | ||
28 | + }).then(result => { | ||
29 | + if (result && result.code === 200) { | ||
30 | + let resu = { | ||
31 | + goods: [] | ||
32 | + }; | ||
33 | + | ||
34 | + if (result && result.data && result.data.product_list) { | ||
35 | + let build = []; | ||
36 | + | ||
37 | + _.forEach(result.data.product_list, (val) => { | ||
38 | + build.push({ | ||
39 | + product_name: val.productName, | ||
40 | + default_images: val.picImgUrl, | ||
41 | + url: `//m.yohobuy.com/product/${val.productSkn}.html` | ||
42 | + }); | ||
43 | + }); | ||
44 | + resu.goods = build; | ||
45 | + } | ||
46 | + return resu; | ||
47 | + } | ||
48 | + }); | ||
49 | + } | ||
50 | +} | ||
51 | + | ||
52 | +module.exports = materialModel; |
@@ -13,6 +13,7 @@ const check = require(`${cRoot}/check`); | @@ -13,6 +13,7 @@ const check = require(`${cRoot}/check`); | ||
13 | const question = require(`${cRoot}/question`); | 13 | const question = require(`${cRoot}/question`); |
14 | const validateCode = require('../passport/controllers/validateCode'); | 14 | const validateCode = require('../passport/controllers/validateCode'); |
15 | const auth = require('../../doraemon/middleware/auth'); | 15 | const auth = require('../../doraemon/middleware/auth'); |
16 | +const material = require(`${cRoot}/material`); | ||
16 | 17 | ||
17 | // routers | 18 | // routers |
18 | 19 | ||
@@ -25,5 +26,7 @@ router.get('/questionnaire', auth, question.list); | @@ -25,5 +26,7 @@ router.get('/questionnaire', auth, question.list); | ||
25 | router.post('/questionnaire/check', question.check); | 26 | router.post('/questionnaire/check', question.check); |
26 | router.post('/questionnaire/submit', question.submit); | 27 | router.post('/questionnaire/submit', question.submit); |
27 | router.get('/questionnaire/:id', auth, question.detail); | 28 | router.get('/questionnaire/:id', auth, question.detail); |
29 | +router.get('/material', auth, material.list); | ||
30 | +router.get('/material/moreGoods', auth, material.moreGoods); | ||
28 | 31 | ||
29 | module.exports = router; | 32 | module.exports = router; |
apps/3party/views/action/material.hbs
0 → 100644
@@ -17,7 +17,8 @@ const domains = { | @@ -17,7 +17,8 @@ const domains = { | ||
17 | global: 'http://global-test-soa.yohops.com:9999', | 17 | global: 'http://global-test-soa.yohops.com:9999', |
18 | liveApi: 'http://testapi.live.yohops.com:9999/', | 18 | liveApi: 'http://testapi.live.yohops.com:9999/', |
19 | imSocket: 'ws://socket.yohobuy.com:10240', | 19 | imSocket: 'ws://socket.yohobuy.com:10240', |
20 | - imCs: 'http://im.yohobuy.com/api' | 20 | + imCs: 'http://im.yohobuy.com/api', |
21 | + platformApi: 'http://192.168.102.48:8088/' | ||
21 | }; | 22 | }; |
22 | 23 | ||
23 | module.exports = { | 24 | module.exports = { |
public/hbs/3party/material/goods.hbs
0 → 100644
public/js/3party/material/controller.js
0 → 100644
1 | +'use strict'; | ||
2 | + | ||
3 | +import { | ||
4 | + Controller | ||
5 | +} from 'yoho-mvc'; | ||
6 | + | ||
7 | +import { | ||
8 | + GetMore | ||
9 | +} from './view'; | ||
10 | + | ||
11 | +import { | ||
12 | + moreGoods as getMore | ||
13 | +} from './model'; | ||
14 | + | ||
15 | +const lazyLoad = require('yoho-jquery-lazyload'); | ||
16 | +const goodContent = require('3party/material/goods.hbs'); | ||
17 | + | ||
18 | +class MaterialController extends Controller { | ||
19 | + constructor() { | ||
20 | + super(); | ||
21 | + lazyLoad($('img.lazy')); | ||
22 | + this.more = new GetMore(); | ||
23 | + this.more.on('more', this.doMore.bind(this)); | ||
24 | + this.page = 1; | ||
25 | + this.loading = false; | ||
26 | + } | ||
27 | + | ||
28 | + doMore() { | ||
29 | + if (!this.end && !this.loading) { | ||
30 | + this.page ++; | ||
31 | + this.moreGood(this.page); | ||
32 | + } | ||
33 | + } | ||
34 | + | ||
35 | + moreGood(page) { | ||
36 | + this.loading = true; | ||
37 | + $('.material-c').append('<p class="show-more good-more">加载更多...</p>'); | ||
38 | + getMore('//m.yohobuy.com/3party/material/moreGoods', {page: page}).then(data => { | ||
39 | + if (data.goods.length > 0) { | ||
40 | + $('.goods-list').append(goodContent(data)); | ||
41 | + | ||
42 | + // 每次只lazyload倒数10 | ||
43 | + lazyLoad($('img.lazy')); | ||
44 | + } else { | ||
45 | + $('.material-c').append('<p class="show-more">没有更多了...</p>'); | ||
46 | + this.end = true; | ||
47 | + } | ||
48 | + }).catch(() => {}).finally(() => { | ||
49 | + this.loading = false; | ||
50 | + $('.good-more').remove(); | ||
51 | + }); | ||
52 | + } | ||
53 | +} | ||
54 | + | ||
55 | +module.exports = MaterialController; |
public/js/3party/material/index.js
0 → 100644
public/js/3party/material/model.js
0 → 100644
public/js/3party/material/view.js
0 → 100644
1 | +import { | ||
2 | + View | ||
3 | +} from 'yoho-mvc'; | ||
4 | + | ||
5 | +class GetMore extends View { | ||
6 | + constructor() { | ||
7 | + super('.material-c'); | ||
8 | + | ||
9 | + // srcoll to load more | ||
10 | + $(window).scroll(() => { | ||
11 | + window.requestAnimationFrame(this.scrollHandler.bind(this)); | ||
12 | + }); | ||
13 | + } | ||
14 | + | ||
15 | + scrollHandler() { | ||
16 | + if (($(window).scrollTop() + $(window).height() >= $(document).height() * 0.8)) { | ||
17 | + this.emit('more'); | ||
18 | + } | ||
19 | + } | ||
20 | +} | ||
21 | + | ||
22 | +export { | ||
23 | + GetMore | ||
24 | +}; |
public/scss/3party/material.page.css
0 → 100644
1 | +@import "common/good"; | ||
2 | + | ||
3 | +.material-c { | ||
4 | + .goods-list { | ||
5 | + padding-left: 15px; | ||
6 | + } | ||
7 | + | ||
8 | + .show-more { | ||
9 | + text-align: center; | ||
10 | + color: #b0b0b0; | ||
11 | + font-size: 28px; | ||
12 | + clear: both; | ||
13 | + line-height: 88px; | ||
14 | + } | ||
15 | + | ||
16 | + .good-detail-text { | ||
17 | + .price { | ||
18 | + display: none; | ||
19 | + } | ||
20 | + } | ||
21 | +} |
-
Please register or login to post a comment