|
|
/* global wx */
|
|
|
const $ = require('yoho-jquery');
|
|
|
const lazyLoad = require('js/plugin/lazyload');
|
|
|
const Swiper = require('yoho-swiper');
|
...
|
...
|
@@ -7,13 +8,327 @@ const cookie = require('yoho-cookie'); |
|
|
const shopTmpl = require('hbs/activity/feature/shop-group.hbs');
|
|
|
const seckillTabTpl = require('hbs/activity/feature/seckill-tab.hbs');
|
|
|
const seckillProductTpl = require('hbs/activity/feature/seckill-product.hbs');
|
|
|
const yo_sdk = require('yoho-activity-sdk');
|
|
|
|
|
|
require('scss/feature.scss');
|
|
|
|
|
|
let isAndroid = /(Android)/i.test(navigator.userAgent);
|
|
|
let isWechat = /micromessenger/i.test(navigator.userAgent);
|
|
|
let isApp = /yohobuy/i.test(navigator.userAgent);
|
|
|
let isWechatMiniProgram = /miniprogram/i.test(navigator.userAgent);
|
|
|
let app_info = {
|
|
|
uid: '0',
|
|
|
session_key: '',
|
|
|
app_version: '',
|
|
|
client_type: ''
|
|
|
};
|
|
|
let appInterface = null;
|
|
|
|
|
|
// 分享领券相关START------------------------------------------------------------
|
|
|
// 用于判断app版本
|
|
|
let versionCompare = {
|
|
|
toVersion: function(str = '') {
|
|
|
let ver = str.split('.').map(function(i) {
|
|
|
return Number(i);
|
|
|
});
|
|
|
|
|
|
if (!ver[0]) {
|
|
|
ver[0] = 0;
|
|
|
}
|
|
|
|
|
|
if (!ver[1]) {
|
|
|
ver[1] = 0;
|
|
|
}
|
|
|
|
|
|
if (!ver[2]) {
|
|
|
ver[2] = 0;
|
|
|
}
|
|
|
|
|
|
return ver;
|
|
|
},
|
|
|
toNumber: function(ver) {
|
|
|
let major = ver[0] * 10000;
|
|
|
let minor = ver[1] * 100;
|
|
|
let patch = ver[2] * 1;
|
|
|
|
|
|
return major + minor + patch;
|
|
|
},
|
|
|
compare: function(left, right) {
|
|
|
if (left > right) {
|
|
|
return 1;
|
|
|
} else if (left < right) {
|
|
|
return -1;
|
|
|
} else {
|
|
|
return 0;
|
|
|
}
|
|
|
},
|
|
|
version: function(left, right) {
|
|
|
let leftVersion = this.toNumber(this.toVersion(left));
|
|
|
let rightVersion = this.toNumber(this.toVersion(right));
|
|
|
let result = this.compare(leftVersion, rightVersion);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
function closeWebShareTips() { // 关闭提示框
|
|
|
$('.web-share-tips-wrapper').removeClass('show');
|
|
|
$('.web-share-tips-wrapper .desc').text('');
|
|
|
}
|
|
|
|
|
|
function showWebShareTips(text) { // 显示提示框
|
|
|
$('.web-share-tips-wrapper').addClass('show');
|
|
|
$('.web-share-tips-wrapper .desc').text(text);
|
|
|
}
|
|
|
|
|
|
function showShare() {
|
|
|
$('.web-share-img-wrapper').addClass('show');
|
|
|
}
|
|
|
|
|
|
function hideShare() {
|
|
|
$('.web-share-img-wrapper').removeClass('show');
|
|
|
}
|
|
|
|
|
|
function getParams() { // 获取登录相关信息
|
|
|
let app_uid = cookie.get('app_uid') || qs.uid || app_info.uid;
|
|
|
let app_session_key = cookie.get('app_session_key') || qs.session_key || app_info.session_key;
|
|
|
let app_version = cookie.get('app_version') || qs.app_version || '';
|
|
|
let app_client_type = cookie.get('app_client_type') || qs.app_client_type || '';
|
|
|
|
|
|
if (isApp) {
|
|
|
if (/android/i.test(navigator.userAgent)) {
|
|
|
app_client_type = 'android';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
app_info = {
|
|
|
uid: app_uid,
|
|
|
session_key: app_session_key,
|
|
|
app_version: app_version,
|
|
|
client_type: app_client_type
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function getCoupon() { // 分享成功后领券
|
|
|
if (parseInt(app_info.uid, 10)) {
|
|
|
let activityInfo = JSON.parse($('.activity-plan').val());
|
|
|
|
|
|
let data = {
|
|
|
activityId: activityInfo[0].activityId,
|
|
|
templateId: activityInfo[0].templateId,
|
|
|
app: app_info
|
|
|
};
|
|
|
|
|
|
$.ajax({
|
|
|
url: '//m.yohobuy.com/activity/feature/webShareCouponSend',
|
|
|
type: 'get',
|
|
|
dataType: 'jsonp',
|
|
|
data: data,
|
|
|
success: function(result) {
|
|
|
if (result.code === 200) {
|
|
|
showWebShareTips(result.message);
|
|
|
} else if (result.code === 401) {
|
|
|
showWebShareTips('您已领取过该优惠券');
|
|
|
} else if (result.code === 402) {
|
|
|
showWebShareTips('登录信息异常');
|
|
|
} else {
|
|
|
showWebShareTips(result.message);
|
|
|
}
|
|
|
hideShare();
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
showWebShareTips('您还没登录哦');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function checkShare(shareData) {
|
|
|
if (isApp) {
|
|
|
let newShare = false;
|
|
|
let app_vercode = cookie.get('app_vercode');
|
|
|
let app_version = cookie.get('app_version') || qs.app_version || '';
|
|
|
|
|
|
if (versionCompare.version(app_version, '6.9.5') >= 0 || app_vercode) {
|
|
|
newShare = true;
|
|
|
}
|
|
|
|
|
|
window.successShare = function() {
|
|
|
getCoupon();
|
|
|
};
|
|
|
|
|
|
appInterface.triggerEvent(
|
|
|
function() {},
|
|
|
function() {},
|
|
|
{
|
|
|
method: 'go.showshareaction',
|
|
|
arguments: shareData
|
|
|
}
|
|
|
);
|
|
|
|
|
|
if (!newShare) {
|
|
|
setTimeout(getCoupon, 5000);
|
|
|
}
|
|
|
} else {
|
|
|
showShare();
|
|
|
if (isWechatMiniProgram) {
|
|
|
setTimeout(getCoupon, 6000);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function goLogin(shareData) { // 跳转登录判断
|
|
|
if (isApp) {
|
|
|
let uidParams = {
|
|
|
method: 'get.uid'
|
|
|
};
|
|
|
let sessionIdParams = {
|
|
|
method: 'get.sessionId'
|
|
|
};
|
|
|
|
|
|
appInterface.triggerEvent(function(uid) {
|
|
|
if (!parseInt(uid, 10)) {
|
|
|
yo_sdk.goLogin();
|
|
|
} else {
|
|
|
app_info.uid = uid;
|
|
|
|
|
|
appInterface.triggerEvent(function(sid) {
|
|
|
app_info.session_key = sid;
|
|
|
checkShare(shareData);
|
|
|
}, function() {}, sessionIdParams);
|
|
|
}
|
|
|
}, function() {}, uidParams);
|
|
|
} else {
|
|
|
yo_sdk.goLogin();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
function initWxShare(data) {
|
|
|
let shareData = {
|
|
|
title: data.title,
|
|
|
imgUrl: data.imgUrl,
|
|
|
desc: data.desc,
|
|
|
link: data.link,
|
|
|
success: function() {
|
|
|
setTimeout(getCoupon, 500);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
if (wx) {
|
|
|
setTimeout(function() {
|
|
|
window.wx.ready(function() {
|
|
|
wx.onMenuShareAppMessage(shareData);
|
|
|
|
|
|
wx.onMenuShareTimeline(shareData);
|
|
|
|
|
|
wx.onMenuShareQQ(shareData);
|
|
|
|
|
|
wx.onMenuShareWeibo(shareData);
|
|
|
});
|
|
|
}, 500);
|
|
|
|
|
|
if (isWechatMiniProgram) {
|
|
|
wx.miniProgram.postMessage({
|
|
|
data: {
|
|
|
title: data.title,
|
|
|
imgUrl: data.imgUrl,
|
|
|
link: data.link
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// yo_sdk.wxShare(shareData);
|
|
|
}
|
|
|
|
|
|
function initWebShareButtons(env = '') { // 初始化分享按钮事件
|
|
|
let webShareData = {
|
|
|
title: $('#shareTitle').val(),
|
|
|
desc: $('#shareImg').val(),
|
|
|
imgUrl: $('#shareDesc').val(),
|
|
|
link: $('#shareLink').val()
|
|
|
};
|
|
|
|
|
|
if ($('.web-share-button')[0]) {
|
|
|
let webShareButton = $('.web-share-button');
|
|
|
|
|
|
webShareData = {
|
|
|
title: webShareButton.data('stitle'),
|
|
|
desc: webShareButton.data('sdesc'),
|
|
|
imgUrl: webShareButton.data('spic'),
|
|
|
link: webShareButton.data('surl').replace('https:', 'http:')
|
|
|
};
|
|
|
}
|
|
|
|
|
|
initWxShare(webShareData);
|
|
|
|
|
|
$('.web-share-button').each(function() {
|
|
|
let webShareButton = $(this);
|
|
|
|
|
|
$(this).on('click', function() {
|
|
|
if (!env) {
|
|
|
showWebShareTips('请在微信中打开');
|
|
|
return;
|
|
|
}
|
|
|
getParams();
|
|
|
webShareData = {
|
|
|
title: webShareButton.data('stitle'),
|
|
|
desc: webShareButton.data('sdesc'),
|
|
|
imgUrl: webShareButton.data('spic'),
|
|
|
link: webShareButton.data('surl').replace('https:', 'http:')
|
|
|
};
|
|
|
|
|
|
$('#shareTitle').val(webShareData.title);
|
|
|
$('#shareImg').val(webShareData.desc);
|
|
|
$('#shareDesc').val(webShareData.imgUrl);
|
|
|
$('#shareLink').val(webShareData.link);
|
|
|
|
|
|
if (isApp) {
|
|
|
Object.assign(webShareData, {
|
|
|
hideType: ['4', '5', '6', '7', '8', '9'],
|
|
|
isCareCallBack: '1',
|
|
|
wxShareMode: parseInt(webShareButton.data('slanding'), 10) ? 'miniprogram' : 'h5',
|
|
|
miniProgramUrl: 'pages/webview/webview?url=' + webShareData.link // 安卓分享小程序会用到
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (parseInt(app_info.uid, 10)) {
|
|
|
|
|
|
checkShare(webShareData);
|
|
|
} else {
|
|
|
goLogin(webShareData);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
$('.web-share-img-wrapper').on('click', hideShare);
|
|
|
}
|
|
|
|
|
|
// 分享领券模板功能初始化
|
|
|
function initWebShare() {
|
|
|
getParams();
|
|
|
$('.web-share-buttons-container .button-ok').on('click', closeWebShareTips);
|
|
|
if (isApp) {
|
|
|
document.addEventListener('deviceready', function() {
|
|
|
appInterface = window.yohoInterface;
|
|
|
if (appInterface) {
|
|
|
initWebShareButtons('app');
|
|
|
}
|
|
|
});
|
|
|
$('.web-share-buttons-container .button-download').hide();
|
|
|
} else if (isWechatMiniProgram) {
|
|
|
$('.web-share-buttons-container .button-download').hide();
|
|
|
initWebShareButtons('miniprogram');
|
|
|
} else if (isWechat) {
|
|
|
initWebShareButtons('wechat');
|
|
|
} else {
|
|
|
initWebShareButtons();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 分享领券相关END------------------------------------------------------------
|
|
|
|
|
|
function swiperInit() {
|
|
|
$('.swiper-container').each(function() {
|
...
|
...
|
@@ -1120,6 +1435,9 @@ $(function() { |
|
|
miniProgramHandleInit();
|
|
|
}
|
|
|
|
|
|
// 分享领券
|
|
|
initWebShare();
|
|
|
|
|
|
// 商品曝光事件上报
|
|
|
if (yoho.isApp) {
|
|
|
require('./feature/goods-show-yas-rpter');
|
...
|
...
|
|