Authored by 毕凯

Merge branch 'feature/goodsList' into 'release/5.8'

Feature/goods list



See merge request !658
  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 +};
  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 + let url = `//m.yohobuy.com/product/${val.productSkn}.html`;
  39 + let imgUrl = val.picImgUrl;
  40 +
  41 + if (imgUrl.split('?')[0]) {
  42 + imgUrl = imgUrl.split('?')[0] + '?imageView2/0/w/323/h/431';
  43 + }
  44 + if (params.isApp) {
  45 + url = `http:${url}?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${val.productSkn}"}}`; // eslint-disable-line
  46 + }
  47 +
  48 + build.push({
  49 + product_name: val.productName,
  50 + default_images: imgUrl,
  51 + url: url
  52 + });
  53 + });
  54 + resu.goods = build;
  55 + }
  56 + return resu;
  57 + }
  58 + });
  59 + }
  60 +}
  61 +
  62 +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;
  1 +<div class="material-c">
  2 + <div class="goods-list">
  3 + {{# goods}}
  4 + {{> common/goods}}
  5 + {{/goods}}
  6 + </div>
  7 +</div>
@@ -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 = {
@@ -114,7 +115,8 @@ if (isProduction) { @@ -114,7 +115,8 @@ if (isProduction) {
114 liveApi: 'http://api.live.yoho.cn/', 115 liveApi: 'http://api.live.yoho.cn/',
115 singleApi: 'http://single.yoho.cn/', 116 singleApi: 'http://single.yoho.cn/',
116 imSocket: 'wss://imsocket.yohobuy.com:443', 117 imSocket: 'wss://imsocket.yohobuy.com:443',
117 - imCs: 'https://imhttp.yohobuy.com/api' 118 + imCs: 'https://imhttp.yohobuy.com/api',
  119 + platformApi: 'http://api.platform.yohoops.org'
118 }, 120 },
119 memcache: { 121 memcache: {
120 master: ['memcache1.yohoops.org:12111', 'memcache2.yohoops.org:12111', 'memcache3.yohoops.org:12111'], 122 master: ['memcache1.yohoops.org:12111', 'memcache2.yohoops.org:12111', 'memcache3.yohoops.org:12111'],
@@ -164,7 +166,8 @@ if (isProduction) { @@ -164,7 +166,8 @@ if (isProduction) {
164 liveApi: process.env.TEST_LIVE || 'http://testapi.live.yohops.com:9999/', 166 liveApi: process.env.TEST_LIVE || 'http://testapi.live.yohops.com:9999/',
165 singleApi: process.env.TEST_SINGLE || 'http://api-test1.yohops.com:9999/', 167 singleApi: process.env.TEST_SINGLE || 'http://api-test1.yohops.com:9999/',
166 imSocket: process.env.TEST_IM_SOCKET || 'ws://socket.yohobuy.com:10240', 168 imSocket: process.env.TEST_IM_SOCKET || 'ws://socket.yohobuy.com:10240',
167 - imCs: process.env.TEST_IM_CS || 'http://im.yohobuy.com/api' 169 + imCs: process.env.TEST_IM_CS || 'http://im.yohobuy.com/api',
  170 + platformApi: 'http://192.168.102.48:8088/'
168 }, 171 },
169 memcache: { 172 memcache: {
170 master: ['127.0.0.1:12111'], 173 master: ['127.0.0.1:12111'],
  1 +{{# goods}}
  2 +{{> common/goods}}
  3 +{{/ goods}}
  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;
  1 +require('3party/material.page.css');
  2 +
  3 +const MaterialController = require('./controller');
  4 +
  5 +new MaterialController();
  1 +'use strict';
  2 +
  3 +import {
  4 + http
  5 +} from 'yoho-mvc';
  6 +
  7 +function moreGoods(url, data) {
  8 + return http({
  9 + url: location.protocol + url,
  10 + data: data,
  11 + });
  12 +}
  13 +
  14 +export {
  15 + moreGoods
  16 +};
  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 +};
  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 +}