Authored by baoss

列表页分享功能

... ... @@ -25,11 +25,13 @@ function index(req, res, next) {
function groupListIndex(req, res, next) {
let params = Object.assign({}, req.query);
let showType = params.showType || 1; // 1、只展示已开始的 2、只展示即将开始的 3、展示全部
let uid = 0;
Promise.all([req.ctx(GroupService).groupList(params),
showType === '2' && req.ctx(GroupService).readyListResource()
]).then(result => {
if (typeof req.user.uid !== 'undefined') {
uid = req.user.uid;
}
req.ctx(GroupService).groupListIndex(params, uid).then(result => {
return res.render('group/group-list', {
title: '拼团列表',
page: 'group-list',
... ... @@ -37,9 +39,10 @@ function groupListIndex(req, res, next) {
nodownload: true,
width750: true,
wechatShare: true,
activityData: result[0],
resource: result[1],
showType
activityData: result.groupList,
resource: result.readyListResource,
shareInfo: result.shareInfo,
showType: result.showType
});
}).catch(next);
}
... ... @@ -170,7 +173,10 @@ function delOrder(req, res, next) {
let orderCode = req.query.id;
let uid = req.user.uid;
req.ctx(GroupService).delOrder({ orderCode, uid }).then((result) => {
req.ctx(GroupService).delOrder({
orderCode,
uid
}).then((result) => {
res.json(result);
}).catch(next);
}
... ... @@ -179,7 +185,10 @@ function cancelOrder(req, res, next) {
let orderCode = req.query.id;
let uid = req.user.uid;
req.ctx(GroupService).cancelOrder({ orderCode, uid }).then((result) => {
req.ctx(GroupService).cancelOrder({
orderCode,
uid
}).then((result) => {
res.json(result);
}).catch(next);
}
... ... @@ -195,15 +204,17 @@ function changeOrderStatus(orderItem) {
case 'buyNow':
orderBtn.push({
buyNow: true,
link: helpers.urlFormat('/home/orders/paynew', {order_code: orderItem.order_code}),
link: helpers.urlFormat('/home/orders/paynew', {
order_code: orderItem.order_code
}),
});
break;
case 'closeOrder':// 取消订单
case 'closeOrder': // 取消订单
orderBtn.push({
closeOrder: true
});
break;
case 'delOrder':// 删除订单
case 'delOrder': // 删除订单
orderBtn.push({
delOrder: true,
});
... ...
... ... @@ -44,6 +44,40 @@ class GroupApi extends global.yoho.BaseModel {
return activityData;
}));
}
_getShareId(params) {
return this.get({
url: '',
data: {
method: 'app.union.shareOrder.queryUnionTypeByUid',
uid: params.uid
},
param: {
code: 200
}
}).then((result) => {
result = result.data;
return result;
}).catch(error => {
console.log(error);
return error;
});
}
_getShareInfo(params) {
return this.get({
url: '/operations/api/v5/webshare/getShare',
data: {
...params
},
param: {
code: 200
}
}).then((result) => {
result = result.data;
return result;
});
}
_getPromoteCount() {
let option = {
data: {
... ... @@ -242,8 +276,10 @@ class GroupApi extends global.yoho.BaseModel {
shop_id: data.shop_id,
};
return this.get({data: param})
.then(res =>{
return this.get({
data: param
})
.then(res => {
let shopList = res.data;
if (shopList && shopList.length) {
... ... @@ -266,7 +302,9 @@ class GroupApi extends global.yoho.BaseModel {
activityId: obj.activityId
};
return this.get({data: param})
return this.get({
data: param
})
.then(data => {
return data.data;
})
... ... @@ -283,7 +321,9 @@ class GroupApi extends global.yoho.BaseModel {
productSkn: obj.productSkn
};
return this.get({data: param})
return this.get({
data: param
})
.then(function(data) {
return data.data;
}).catch(function(error) {
... ... @@ -298,7 +338,9 @@ class GroupApi extends global.yoho.BaseModel {
coupon_limit_status: 0
};
return this.get({data: param})
return this.get({
data: param
})
.then(function(data) {
let free = [{
flag: 1,
... ...
... ... @@ -29,7 +29,7 @@ class GroupService extends global.yoho.BaseModel {
return result;
} catch (e) {
throw new Error('Group index fail to load resources.');
throw new Error('fail to load ready list resources.');
}
}
... ... @@ -130,6 +130,36 @@ class GroupService extends global.yoho.BaseModel {
return result;
}
async groupListIndex(params, uid) {
let result = {};
result.showType = params.showType || 1; // 1、只展示已开始的 2、只展示即将开始的 3、展示全部
result.groupList = await this.groupList(params);
result.readyListResource = result.showType === '2' && await this.readyListResource();
// 登录后获取分享信息
if (uid !== 0) {
let share_id = await this.getShareId(uid);
result.shareInfo = await this.getShareInfo({
share_id
});
} else {
result.shareInfo = '';
}
return result;
}
async getShareId(uid) {
try {
const result = await this.api._getShareId({
uid
});
return result.shareId;
} catch (e) {
throw new Error('can not get shareId.');
}
}
async tabData() {
const result = await this.api._getPromoteCount();
let tabsData = {};
... ... @@ -221,7 +251,13 @@ class GroupService extends global.yoho.BaseModel {
throw new Error('Group list fail to load resources.');
}
}
async getShareInfo(params) {
try {
return await this.api._getShareInfo(params);
} catch (e) {
throw new Error('get shareInfo failed.');
}
}
async goodsDetail(params) {
let result = await this.api.getProductData(params);
... ...
<div class="container">
<div class="container" data-share-img="{{shareInfo.bigImage}}" data-share-title="{{shareInfo.title}}" data-share-content="{{shareInfo.content}}">
{{#if activityData.banner}}
<a href="{{activityData.banner.imageUrl}}" class="img-wrapper">
... ... @@ -15,7 +15,7 @@
{{/each}}
{{/if}}
{{/ifcond}}
<div id="goodsContainer">
<div class="goods-list">
{{#each activityData.activityList}}
... ... @@ -26,4 +26,7 @@
</div>
<a class="my-group my-group-handler" href="/activity/group/order">我的拼团</a>
<div class='my-share'></div>
\ No newline at end of file
{{#if shareInfo}}
<div class='my-share'></div>
{{/if}}
<div class="h5-share-clipboard"></div>
\ No newline at end of file
... ...
... ... @@ -4,13 +4,25 @@ import $ from 'yoho-jquery';
import Page from 'js/yoho-page';
import qs from 'yoho-qs';
import ProductListLoader from './group/group-list';
import Clipboard from 'clipboard';
import tip from 'js/plugin/tip';
import dialog from 'js/plugin/dialog';
import sharePlugin from 'js/common/share';
import yoSdk from 'yoho-activity-sdk';
const querystring = require('querystring');
class ProductList extends Page {
constructor() {
super();
this.selector = {
$goodsContainer: $('.goods-list')
$pageContainer: $('.container'),
$goodsContainer: $('.goods-list'),
$share: $('.my-share')
};
this.shareData = {
shareImgUrl: this.selector.$pageContainer.data('share-img'),
shareTitle: this.selector.$pageContainer.data('share-title')
};
this.firstScreen = this.selector.$goodsContainer.children().size() > 0;
if (!this.firstScreen) {
... ... @@ -26,13 +38,16 @@ class ProductList extends Page {
new ProductListLoader(initParams, '/activity/group/goods-list', {
scrollActived: this.firstScreen
});
this.shareInfo();
this.bindEvents();
this.swiperTop();
}
bindEvents() {
this.selector.$goodsContainer.on('click', '.groupListCellTapped',
this.checkDetail.bind(this));
this.selector.$share.on('click', this.share.bind(this));
}
checkDetail(e) {
let $this = $(e.currentTarget);
... ... @@ -42,6 +57,42 @@ class ProductList extends Page {
console.log(productSkn, activityId);
window.location.href = `/activity/group/detail?activityId=${activityId}&productSkn=${productSkn}`;
}
shareInfo() {
let shareData = this.shareData;
let [link, paramsStr] = location.href.split('?');
let params = querystring.parse(paramsStr);
delete params['openby:yohobuy'];
paramsStr = querystring.stringify(params);
link = link + (paramsStr ? '?' + paramsStr : '');
sharePlugin({
title: shareData.shareTitle,
imgUrl: shareData.shareImgUrl,
link: link
});
let clipboardShare = new Clipboard('.h5-share-clipboard', {
text: () => {
return `${shareData.shareTitle}>>${link}`;
}
});
clipboardShare.on('success', (e) => {
tip.show('复制成功,发送给好友', 3500);
e.clearSelection();
});
}
share() {
if (/QQ/i.test(navigator.userAgent) ||
/MicroMessenger/i.test(navigator.userAgent)) {
dialog.showDialog({
hasClass: 'group-guide-mask'
});
} else if (yoSdk.env === 'h5') {
$('.h5-share-clipboard').trigger('click');
}
}
// 顶部swiper
swiperTop() {
... ...
@import "~scss/layout/swiper";
@import "floor/banner-top";
body {
background-color: #fff;
}
.container {
margin-bottom: 90px;
}
... ... @@ -268,3 +272,23 @@
.button-hover {
opacity: 1;
}
.dialog-wrapper {
z-index: 9999;
}
.dialog-wrapper .dialog-box.group-guide-mask {
width: 284px;
height: 278px;
background: url("img/activity/group/share-tip.png");
background-size: 100% 100%;
margin: 0 !important;
border: 0;
right: 92px;
top: 28px !important;
left: auto;
> * {
display: none !important;
}
}
... ...
... ... @@ -10,6 +10,7 @@
.group {
.resources {
background-color: #fff;
margin-bottom: 90px;
}
... ...