Authored by zhangxiaoru

接口调试

... ... @@ -3,7 +3,7 @@
const shopModel = require('../models/shopCollect'),
headerModel = require('../../../doraemon/models/header');
const shopIndex = (req, res, next) => {
const shopIndex = (req, res) => {
res.render('shop-collect/index', {
module: 'activity',
... ... @@ -19,44 +19,30 @@ const shopIndex = (req, res, next) => {
{src: '//img10.static.yhbimg.com/yhb-img01/2016/10/10/15/01a6351f91fe38304d268db009c9126bd4.jpg?imageView2/2/w/640/h/240/q/70'},
{src: '//img11.static.yhbimg.com/yhb-img01/2016/10/12/17/0168982b53cefca01ff3b2c5b91e606714.jpg?imageView2/2/w/640/h/240/q/70'}
]
},
navList: [
{
navName: '推荐'
},
{
navName: '推荐'
},
{
navName: '推荐'
},
{
navName: '推荐'
},
{
navName: '推荐'
},
{
navName: '推荐'
},
{
navName: '推荐'
}
]
}
}
});
};
const shopNav = (req, res, next) => {
shopModel.shopNav().then((result) => {
res.json(result);
}).catch(next);
};
const shopList = (req, res, next) => {
let uid = req.user.uid || 12696231;
let uid = req.user.uid;
let tabName = req.query.tabName;
shopModel.shopList(uid, tabName).then((result) => {
res.json(result);
});
}).catch(next);
};
module.exports = {
shopIndex,
shopList
shopList,
shopNav
};
... ...
... ... @@ -16,29 +16,11 @@ const shopList = (uid, tabName) => {
uid: uid,
tab_name: tabName
}).then((result) => {
console.log(result);
result = {
alg: 'SALT_MD5',
code: 200,
data: [
{
bannerUrl: 'http://aaa.jpg',
collectionNum: 134,
id: 2,
logoUrl: 'http://bbb.png',
shopName: 'Stussy',
shopsId: 333,
tabName: 'promotion',
words: '关注送20有货币',
isFavorite: 'Y'
}
],
md5: 'e2acc1bf474ee2b1a581d2ca91286511',
message: 'product shopsPromote Info'
};
if (result && result.code === 200) {
// console.log(result.data, 123)
_.forEach(result.data, function(data) {
data.isFavorite = data.isFavorite === 'Y';
});
return result.data;
} else {
logger.error('shop list data return code is not 200');
... ... @@ -47,6 +29,15 @@ const shopList = (uid, tabName) => {
});
};
const shopNav = () => {
return api.get('', {
method: 'app.shops.promoteTabNameList'
}).then((result) => {
return result.data;
});
};
module.exports = {
shopList
shopList,
shopNav
};
... ...
... ... @@ -86,5 +86,6 @@ router.get('/vip-day/msg/fetch.json', vipDay.fetchMsg);
router.get('/shopCollect', shopCollect.shopIndex);// 店铺收藏
router.get('/shopList', shopCollect.shopList);// 店铺收藏列表
router.get('/shopNav', shopCollect.shopNav);// 店铺收藏导航
module.exports = router;
... ...
... ... @@ -9,7 +9,6 @@ var $ = require('yoho-jquery'),
// Handlebars = require('yoho-handlebars');
var searching,
$collect = $('.collect-btn'),
shopId,
navSwiper,
stoping;
... ... @@ -17,125 +16,145 @@ var searching,
var shopNav = require('template/shopCollect/shop-nav.hbs'),
shopList = require('template/shopCollect/shop-list.hbs');
var navString = shopNav({
navList: [
{
navName: '欧美',
tabName: 'promotion'
},
{
navName: '欧美',
tabName: 'promotion1'
},
{
navName: '推荐',
tabName: 'promotion2'
}
]
});
require('../common');
var navType = window.queryString;
$('.shop-nav').html(navString);
$collect.on('click', function() {
console.log(12);
var opt,
$this = $(this);
require('../common');
shopId = $this.parents('.shop-info').data('id');
// 店铺列表数据
function shopListData(tabName, stoping) {
if (searching) {
if (stoping) {
return;
}
searching = true;
if ($collect.hasClass('already-collect')) {
opt = 'cancel';
} else {
opt = 'ok';
}
$.ajax({
method: 'get',
url: location.protocol + '//m.yohobuy.com' + '/product/opt/favoriteBrand',
url: '/activity/shopList',
data: {
id: shopId,
opt: opt,
type: 'shop',
},
xhrFields: {
withCredentials: true
tabName: tabName
},
success: function(data) {
if (data.code === 200) {
if ($collect.hasClass('already-collect')) {
$collect.removeClass('already-collect');
tip.show('店铺取消收藏成功');
var list = shopList({
shopList: data
});
$('.shop-list').html(list);
stoping = false;
$('.collect-btn').on('click', function() {
var opt,
$this = $(this);
shopId = $this.parents('.shop-info').data('id');
if (searching) {
return;
}
searching = true;
if ($this.hasClass('already-collect')) {
opt = 'cancel';
} else {
$collect.addClass('already-collect');
tip.show('店铺收藏成功');
opt = 'ok';
}
}
if (data.code === 400) {
window.location.href = 'http://www.yohobuy.com/passport/login';
}
searching = false;
$.ajax({
method: 'get',
url: location.protocol + '//m.yohobuy.com' + '/product/opt/favoriteBrand',
data: {
id: shopId,
opt: opt,
type: 'shop',
},
xhrFields: {
withCredentials: true
},
success: function(data) {
if (data.code === 200) {
if ($this.hasClass('already-collect')) {
$this.removeClass('already-collect');
tip.show('店铺取消收藏成功');
} else {
$this.addClass('already-collect');
tip.show('店铺收藏成功');
}
}
if (data.code === 400) {
window.location.href = 'http://www.yohobuy.com/passport/login';
}
searching = false;
},
error: function() {
tip.show('网络断开连接了~');
searching = false;
}
});
});
},
error: function() {
tip.show('网络断开连接了~');
searching = false;
stoping = false;
}
});
});
}
function shopListData(tabName, stoping) {
if (stoping) {
return;
}
// 导航数据
function shopNavData() {
$.ajax({
method: 'get',
url: '/activity/shopList',
data: {
tabName: tabName
},
url: '/activity/shopNav',
success: function(data) {
var list = shopList({
shopList: data
var navString = shopNav({
navList: data
});
$('.shop-list').html(list);
$('.shop-nav').html(navString);
if (navType.id) {
$('.shop-nav').find('li').each(function() {
if (navType.id === $(this).data('type')) {
$(this).addClass('active');
shopListData($(this).data('type'));
}
});
} else {
$('.shop-nav').find('li').eq(0).addClass('active');
shopListData($('.shop-nav').find('li').eq(0).data('type'));
}
$('.shop-nav').find('li').on('click', function() {
var $this = $(this),
tabName = $this.data('type');
if ($this.hasClass('active')) {
stoping = true;
} else {
stoping = false;
}
shopListData(tabName, stoping);
$this.addClass('active').siblings().removeClass('active');
});
stoping = false;
},
error: function() {
tip.show('网络断开连接了~');
stoping = false;
}
});
}
$('.shop-nav').find('li').on('click', function() {
var $this = $(this),
tabName = $this.data('type');
if ($this.hasClass('active')) {
stoping = true;
} else {
stoping = false;
}
shopListData(tabName, stoping);
$this.addClass('active').siblings().removeClass('active');
});
$(function() {
navSwiper = new Swiper('.shop-nav', {
... ... @@ -157,18 +176,5 @@ $(function() {
});
}
if (navType.id) {
$('.shop-nav').find('li').each(function() {
if (navType.id === $(this).data('type')) {
$(this).addClass('active');
shopListData($(this).data('type'));
}
});
} else {
$('.shop-nav').find('li').eq(0).addClass('active');
shopListData($('.shop-nav').find('li').eq(0).data('type'));
}
shopNavData();
});
... ...
{{# shopList}}
<div class="shop-info" data-id="1284">
<div class="shop-info" data-id="{{shopsId}}">
<div class="info-title">
<div class="collect">
<span class="fans">粉丝{{fansNum}}</span>
<i class="iconfont collect-btn already-collect">&#xe605;</i>
<span class="fans">粉丝{{collectionNum}}</span>
<i class="iconfont collect-btn {{#if isFavorite}}already-collect{{/ if}}">&#xe605;</i>
</div>
<div class="shop-tile">
<img src="{{logo}}"></img>
<img src="{{logoUrl}}"></img>
<p>
<span class="shop-name">stussy</span><br>
<span class="giving">关注送yoho币</span>
<span class="shop-name">{{shopName}}</span><br>
<span class="giving">{{words}}</span>
</p>
</div>
</div>
<div class="info-content">
<img class="content"></img>
<img class="content" src="{{bannerUrl}}"></img>
</div>
</div>
{{/ shopList}}
\ No newline at end of file
... ...
<ul class="swiper-wrapper clearfix">
{{# navList}}
<li class="swiper-slide" data-type={{tabName}}>{{navName}}</li>
<li class="swiper-slide" data-type={{.}}>{{.}}</li>
{{/ navList}}
</ul>
\ No newline at end of file
... ...