Authored by baoss

列表页分享功能

@@ -25,11 +25,13 @@ function index(req, res, next) { @@ -25,11 +25,13 @@ function index(req, res, next) {
25 25
26 function groupListIndex(req, res, next) { 26 function groupListIndex(req, res, next) {
27 let params = Object.assign({}, req.query); 27 let params = Object.assign({}, req.query);
28 - let showType = params.showType || 1; // 1、只展示已开始的 2、只展示即将开始的 3、展示全部 28 + let uid = 0;
29 29
30 - Promise.all([req.ctx(GroupService).groupList(params),  
31 - showType === '2' && req.ctx(GroupService).readyListResource()  
32 - ]).then(result => { 30 + if (typeof req.user.uid !== 'undefined') {
  31 + uid = req.user.uid;
  32 + }
  33 +
  34 + req.ctx(GroupService).groupListIndex(params, uid).then(result => {
33 return res.render('group/group-list', { 35 return res.render('group/group-list', {
34 title: '拼团列表', 36 title: '拼团列表',
35 page: 'group-list', 37 page: 'group-list',
@@ -37,9 +39,10 @@ function groupListIndex(req, res, next) { @@ -37,9 +39,10 @@ function groupListIndex(req, res, next) {
37 nodownload: true, 39 nodownload: true,
38 width750: true, 40 width750: true,
39 wechatShare: true, 41 wechatShare: true,
40 - activityData: result[0],  
41 - resource: result[1],  
42 - showType 42 + activityData: result.groupList,
  43 + resource: result.readyListResource,
  44 + shareInfo: result.shareInfo,
  45 + showType: result.showType
43 }); 46 });
44 }).catch(next); 47 }).catch(next);
45 } 48 }
@@ -170,7 +173,10 @@ function delOrder(req, res, next) { @@ -170,7 +173,10 @@ function delOrder(req, res, next) {
170 let orderCode = req.query.id; 173 let orderCode = req.query.id;
171 let uid = req.user.uid; 174 let uid = req.user.uid;
172 175
173 - req.ctx(GroupService).delOrder({ orderCode, uid }).then((result) => { 176 + req.ctx(GroupService).delOrder({
  177 + orderCode,
  178 + uid
  179 + }).then((result) => {
174 res.json(result); 180 res.json(result);
175 }).catch(next); 181 }).catch(next);
176 } 182 }
@@ -179,7 +185,10 @@ function cancelOrder(req, res, next) { @@ -179,7 +185,10 @@ function cancelOrder(req, res, next) {
179 let orderCode = req.query.id; 185 let orderCode = req.query.id;
180 let uid = req.user.uid; 186 let uid = req.user.uid;
181 187
182 - req.ctx(GroupService).cancelOrder({ orderCode, uid }).then((result) => { 188 + req.ctx(GroupService).cancelOrder({
  189 + orderCode,
  190 + uid
  191 + }).then((result) => {
183 res.json(result); 192 res.json(result);
184 }).catch(next); 193 }).catch(next);
185 } 194 }
@@ -195,15 +204,17 @@ function changeOrderStatus(orderItem) { @@ -195,15 +204,17 @@ function changeOrderStatus(orderItem) {
195 case 'buyNow': 204 case 'buyNow':
196 orderBtn.push({ 205 orderBtn.push({
197 buyNow: true, 206 buyNow: true,
198 - link: helpers.urlFormat('/home/orders/paynew', {order_code: orderItem.order_code}), 207 + link: helpers.urlFormat('/home/orders/paynew', {
  208 + order_code: orderItem.order_code
  209 + }),
199 }); 210 });
200 break; 211 break;
201 - case 'closeOrder':// 取消订单 212 + case 'closeOrder': // 取消订单
202 orderBtn.push({ 213 orderBtn.push({
203 closeOrder: true 214 closeOrder: true
204 }); 215 });
205 break; 216 break;
206 - case 'delOrder':// 删除订单 217 + case 'delOrder': // 删除订单
207 orderBtn.push({ 218 orderBtn.push({
208 delOrder: true, 219 delOrder: true,
209 }); 220 });
@@ -44,6 +44,40 @@ class GroupApi extends global.yoho.BaseModel { @@ -44,6 +44,40 @@ class GroupApi extends global.yoho.BaseModel {
44 return activityData; 44 return activityData;
45 })); 45 }));
46 } 46 }
  47 + _getShareId(params) {
  48 + return this.get({
  49 + url: '',
  50 + data: {
  51 + method: 'app.union.shareOrder.queryUnionTypeByUid',
  52 + uid: params.uid
  53 + },
  54 + param: {
  55 + code: 200
  56 + }
  57 + }).then((result) => {
  58 + result = result.data;
  59 +
  60 + return result;
  61 + }).catch(error => {
  62 + console.log(error);
  63 + return error;
  64 + });
  65 + }
  66 + _getShareInfo(params) {
  67 + return this.get({
  68 + url: '/operations/api/v5/webshare/getShare',
  69 + data: {
  70 + ...params
  71 + },
  72 + param: {
  73 + code: 200
  74 + }
  75 + }).then((result) => {
  76 + result = result.data;
  77 +
  78 + return result;
  79 + });
  80 + }
47 _getPromoteCount() { 81 _getPromoteCount() {
48 let option = { 82 let option = {
49 data: { 83 data: {
@@ -242,8 +276,10 @@ class GroupApi extends global.yoho.BaseModel { @@ -242,8 +276,10 @@ class GroupApi extends global.yoho.BaseModel {
242 shop_id: data.shop_id, 276 shop_id: data.shop_id,
243 }; 277 };
244 278
245 - return this.get({data: param})  
246 - .then(res =>{ 279 + return this.get({
  280 + data: param
  281 + })
  282 + .then(res => {
247 let shopList = res.data; 283 let shopList = res.data;
248 284
249 if (shopList && shopList.length) { 285 if (shopList && shopList.length) {
@@ -266,7 +302,9 @@ class GroupApi extends global.yoho.BaseModel { @@ -266,7 +302,9 @@ class GroupApi extends global.yoho.BaseModel {
266 activityId: obj.activityId 302 activityId: obj.activityId
267 }; 303 };
268 304
269 - return this.get({data: param}) 305 + return this.get({
  306 + data: param
  307 + })
270 .then(data => { 308 .then(data => {
271 return data.data; 309 return data.data;
272 }) 310 })
@@ -283,7 +321,9 @@ class GroupApi extends global.yoho.BaseModel { @@ -283,7 +321,9 @@ class GroupApi extends global.yoho.BaseModel {
283 productSkn: obj.productSkn 321 productSkn: obj.productSkn
284 }; 322 };
285 323
286 - return this.get({data: param}) 324 + return this.get({
  325 + data: param
  326 + })
287 .then(function(data) { 327 .then(function(data) {
288 return data.data; 328 return data.data;
289 }).catch(function(error) { 329 }).catch(function(error) {
@@ -298,7 +338,9 @@ class GroupApi extends global.yoho.BaseModel { @@ -298,7 +338,9 @@ class GroupApi extends global.yoho.BaseModel {
298 coupon_limit_status: 0 338 coupon_limit_status: 0
299 }; 339 };
300 340
301 - return this.get({data: param}) 341 + return this.get({
  342 + data: param
  343 + })
302 .then(function(data) { 344 .then(function(data) {
303 let free = [{ 345 let free = [{
304 flag: 1, 346 flag: 1,
@@ -29,7 +29,7 @@ class GroupService extends global.yoho.BaseModel { @@ -29,7 +29,7 @@ class GroupService extends global.yoho.BaseModel {
29 29
30 return result; 30 return result;
31 } catch (e) { 31 } catch (e) {
32 - throw new Error('Group index fail to load resources.'); 32 + throw new Error('fail to load ready list resources.');
33 } 33 }
34 } 34 }
35 35
@@ -130,6 +130,36 @@ class GroupService extends global.yoho.BaseModel { @@ -130,6 +130,36 @@ class GroupService extends global.yoho.BaseModel {
130 return result; 130 return result;
131 } 131 }
132 132
  133 + async groupListIndex(params, uid) {
  134 + let result = {};
  135 +
  136 + result.showType = params.showType || 1; // 1、只展示已开始的 2、只展示即将开始的 3、展示全部
  137 + result.groupList = await this.groupList(params);
  138 + result.readyListResource = result.showType === '2' && await this.readyListResource();
  139 +
  140 + // 登录后获取分享信息
  141 + if (uid !== 0) {
  142 + let share_id = await this.getShareId(uid);
  143 +
  144 + result.shareInfo = await this.getShareInfo({
  145 + share_id
  146 + });
  147 + } else {
  148 + result.shareInfo = '';
  149 + }
  150 + return result;
  151 + }
  152 + async getShareId(uid) {
  153 + try {
  154 + const result = await this.api._getShareId({
  155 + uid
  156 + });
  157 +
  158 + return result.shareId;
  159 + } catch (e) {
  160 + throw new Error('can not get shareId.');
  161 + }
  162 + }
133 async tabData() { 163 async tabData() {
134 const result = await this.api._getPromoteCount(); 164 const result = await this.api._getPromoteCount();
135 let tabsData = {}; 165 let tabsData = {};
@@ -221,7 +251,13 @@ class GroupService extends global.yoho.BaseModel { @@ -221,7 +251,13 @@ class GroupService extends global.yoho.BaseModel {
221 throw new Error('Group list fail to load resources.'); 251 throw new Error('Group list fail to load resources.');
222 } 252 }
223 } 253 }
224 - 254 + async getShareInfo(params) {
  255 + try {
  256 + return await this.api._getShareInfo(params);
  257 + } catch (e) {
  258 + throw new Error('get shareInfo failed.');
  259 + }
  260 + }
225 async goodsDetail(params) { 261 async goodsDetail(params) {
226 let result = await this.api.getProductData(params); 262 let result = await this.api.getProductData(params);
227 263
1 -<div class="container"> 1 +<div class="container" data-share-img="{{shareInfo.bigImage}}" data-share-title="{{shareInfo.title}}" data-share-content="{{shareInfo.content}}">
2 2
3 {{#if activityData.banner}} 3 {{#if activityData.banner}}
4 <a href="{{activityData.banner.imageUrl}}" class="img-wrapper"> 4 <a href="{{activityData.banner.imageUrl}}" class="img-wrapper">
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 {{/each}} 15 {{/each}}
16 {{/if}} 16 {{/if}}
17 {{/ifcond}} 17 {{/ifcond}}
18 - 18 +
19 <div id="goodsContainer"> 19 <div id="goodsContainer">
20 <div class="goods-list"> 20 <div class="goods-list">
21 {{#each activityData.activityList}} 21 {{#each activityData.activityList}}
@@ -26,4 +26,7 @@ @@ -26,4 +26,7 @@
26 </div> 26 </div>
27 27
28 <a class="my-group my-group-handler" href="/activity/group/order">我的拼团</a> 28 <a class="my-group my-group-handler" href="/activity/group/order">我的拼团</a>
29 -<div class='my-share'></div>  
  29 +{{#if shareInfo}}
  30 +<div class='my-share'></div>
  31 +{{/if}}
  32 +<div class="h5-share-clipboard"></div>
@@ -4,13 +4,25 @@ import $ from 'yoho-jquery'; @@ -4,13 +4,25 @@ import $ from 'yoho-jquery';
4 import Page from 'js/yoho-page'; 4 import Page from 'js/yoho-page';
5 import qs from 'yoho-qs'; 5 import qs from 'yoho-qs';
6 import ProductListLoader from './group/group-list'; 6 import ProductListLoader from './group/group-list';
  7 +import Clipboard from 'clipboard';
  8 +import tip from 'js/plugin/tip';
  9 +import dialog from 'js/plugin/dialog';
  10 +import sharePlugin from 'js/common/share';
  11 +import yoSdk from 'yoho-activity-sdk';
  12 +const querystring = require('querystring');
7 13
8 class ProductList extends Page { 14 class ProductList extends Page {
9 constructor() { 15 constructor() {
10 super(); 16 super();
11 17
12 this.selector = { 18 this.selector = {
13 - $goodsContainer: $('.goods-list') 19 + $pageContainer: $('.container'),
  20 + $goodsContainer: $('.goods-list'),
  21 + $share: $('.my-share')
  22 + };
  23 + this.shareData = {
  24 + shareImgUrl: this.selector.$pageContainer.data('share-img'),
  25 + shareTitle: this.selector.$pageContainer.data('share-title')
14 }; 26 };
15 this.firstScreen = this.selector.$goodsContainer.children().size() > 0; 27 this.firstScreen = this.selector.$goodsContainer.children().size() > 0;
16 if (!this.firstScreen) { 28 if (!this.firstScreen) {
@@ -26,13 +38,16 @@ class ProductList extends Page { @@ -26,13 +38,16 @@ class ProductList extends Page {
26 new ProductListLoader(initParams, '/activity/group/goods-list', { 38 new ProductListLoader(initParams, '/activity/group/goods-list', {
27 scrollActived: this.firstScreen 39 scrollActived: this.firstScreen
28 }); 40 });
  41 + this.shareInfo();
29 this.bindEvents(); 42 this.bindEvents();
30 this.swiperTop(); 43 this.swiperTop();
  44 +
31 } 45 }
32 46
33 bindEvents() { 47 bindEvents() {
34 this.selector.$goodsContainer.on('click', '.groupListCellTapped', 48 this.selector.$goodsContainer.on('click', '.groupListCellTapped',
35 this.checkDetail.bind(this)); 49 this.checkDetail.bind(this));
  50 + this.selector.$share.on('click', this.share.bind(this));
36 } 51 }
37 checkDetail(e) { 52 checkDetail(e) {
38 let $this = $(e.currentTarget); 53 let $this = $(e.currentTarget);
@@ -42,6 +57,42 @@ class ProductList extends Page { @@ -42,6 +57,42 @@ class ProductList extends Page {
42 console.log(productSkn, activityId); 57 console.log(productSkn, activityId);
43 window.location.href = `/activity/group/detail?activityId=${activityId}&productSkn=${productSkn}`; 58 window.location.href = `/activity/group/detail?activityId=${activityId}&productSkn=${productSkn}`;
44 } 59 }
  60 + shareInfo() {
  61 + let shareData = this.shareData;
  62 + let [link, paramsStr] = location.href.split('?');
  63 + let params = querystring.parse(paramsStr);
  64 +
  65 + delete params['openby:yohobuy'];
  66 + paramsStr = querystring.stringify(params);
  67 + link = link + (paramsStr ? '?' + paramsStr : '');
  68 +
  69 + sharePlugin({
  70 + title: shareData.shareTitle,
  71 + imgUrl: shareData.shareImgUrl,
  72 + link: link
  73 + });
  74 +
  75 + let clipboardShare = new Clipboard('.h5-share-clipboard', {
  76 + text: () => {
  77 + return `${shareData.shareTitle}>>${link}`;
  78 + }
  79 + });
  80 +
  81 + clipboardShare.on('success', (e) => {
  82 + tip.show('复制成功,发送给好友', 3500);
  83 + e.clearSelection();
  84 + });
  85 + }
  86 + share() {
  87 + if (/QQ/i.test(navigator.userAgent) ||
  88 + /MicroMessenger/i.test(navigator.userAgent)) {
  89 + dialog.showDialog({
  90 + hasClass: 'group-guide-mask'
  91 + });
  92 + } else if (yoSdk.env === 'h5') {
  93 + $('.h5-share-clipboard').trigger('click');
  94 + }
  95 + }
45 96
46 // 顶部swiper 97 // 顶部swiper
47 swiperTop() { 98 swiperTop() {
1 @import "~scss/layout/swiper"; 1 @import "~scss/layout/swiper";
2 @import "floor/banner-top"; 2 @import "floor/banner-top";
3 3
  4 +body {
  5 + background-color: #fff;
  6 +}
  7 +
4 .container { 8 .container {
5 margin-bottom: 90px; 9 margin-bottom: 90px;
6 } 10 }
@@ -268,3 +272,23 @@ @@ -268,3 +272,23 @@
268 .button-hover { 272 .button-hover {
269 opacity: 1; 273 opacity: 1;
270 } 274 }
  275 +
  276 +.dialog-wrapper {
  277 + z-index: 9999;
  278 +}
  279 +
  280 +.dialog-wrapper .dialog-box.group-guide-mask {
  281 + width: 284px;
  282 + height: 278px;
  283 + background: url("img/activity/group/share-tip.png");
  284 + background-size: 100% 100%;
  285 + margin: 0 !important;
  286 + border: 0;
  287 + right: 92px;
  288 + top: 28px !important;
  289 + left: auto;
  290 +
  291 + > * {
  292 + display: none !important;
  293 + }
  294 +}
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 10
11 .group { 11 .group {
12 .resources { 12 .resources {
  13 + background-color: #fff;
13 margin-bottom: 90px; 14 margin-bottom: 90px;
14 } 15 }
15 16