Authored by 陈峰

swtich yoluck back

Showing 33 changed files with 2195 additions and 6 deletions
const _ = require('lodash');
const {YOLUCK_LIST_TYPE, YoLuckService} = require('../models/yoluck-service-back');
function _handelErrorMessage(e) {
if (e && e.statusCode === 503) {
e.title = '人数过多。。。';
e.message = '目前参与人数过多请点击刷新';
}
return e;
}
function index(req, res, next) {
let type = +req.query.type || YOLUCK_LIST_TYPE.running;
let uid = req.user.uid;
if (!Object.values(YOLUCK_LIST_TYPE).includes(type)) {
type = YOLUCK_LIST_TYPE.running;
}
req.ctx(YoLuckService).index(type, uid).then(result => {
if (result.error) {
if (type === YOLUCK_LIST_TYPE.joined && result.error === 401) {
return res.redirect(
`/signin.html?refer=//m.yohobuy.com/activity/yoluck/index.html?type=${YOLUCK_LIST_TYPE.joined}`
);
} else {
return Promise.reject(result.error);
}
}
res.render('yoluck-back/list', {
title: 'YO!LUCK',
page: 'yoluck-list-back',
tabpanel: result,
localCss: true,
nodownload: true,
width750: true,
wechatShare: true
});
}).catch(e => next(_handelErrorMessage(e)));
}
function nextPage(req, res, next) {
const page = req.query.page || 1;
const type = Number(req.query.type || 0);
const uid = _.get(req.user, 'uid', '');
if (!Object.values(YOLUCK_LIST_TYPE).includes(type)) {
return res.json({
code: 404,
message: '参数错误'
});
}
req.ctx(YoLuckService).getList({page, type, uid}).then(result => {
if (result.error) {
if (result.error === 400) {
return res.json({code: 400, message: '用户未登录'});
} else {
return res.json({code: 404, message: '参数错误'});
}
}
res.json({code: 200, data: result});
}).catch(next);
}
function detail(req, res, next) {
const id = req.params.id;
const uid = req.user.uid;
if (!id) {
return next(Error('页面不存在'));
}
req.ctx(YoLuckService).getDetail(id, uid).then(result => {
if (result.error) {
return Promise.reject(result.error);
}
res.render('yoluck-back/detail', {
title: 'YO!LUCK',
page: 'yoluck-detail-back',
result,
localCss: true,
nodownload: true,
width750: true,
wechatShare: true
});
}).catch(e => next(_handelErrorMessage(e)));
}
function getCode(req, res, next) {
const shareUid = req.body.shareUid;
const actPrizeId = req.params.id;
const uid = req.user.uid;
if (!actPrizeId) {
return res.json({
error: '活动参数错误'
});
}
req.ctx(YoLuckService).getCode({shareUid, uid, actPrizeId}).then(result => {
if (result.error) {
return res.json({code: 404, message: result.error});
}
res.json({code: 200, data: result});
}).catch(next);
}
function getActivityCodeList(req, res, next) {
const actPrizeId = req.body.id;
const uid = req.user.uid;
if (!actPrizeId || !uid) {
return res.json({code: 200, data: []});
}
req.ctx(YoLuckService).getActivityCodeList(req.user.uid, actPrizeId).then(result => {
if (result.error) {
return res.json({code: 404, message: result.error});
}
res.json({code: 200, data: result});
}).catch(next);
}
module.exports = {
index,
nextPage,
detail,
getCode,
getActivityCodeList
};
... ...
const MODULE = '/activity/zerobuy';
const serviceAPI = global.yoho.ServiceAPI;
const yoLuckApi = new global.yoho.ApiBase(global.yoho.config.domains.yoLuck, {
name: 'yoLuck',
cache: global.yoho.cache,
useCache: false
});
function productTime(p) {
if (p.status === 1) {
p.end_time = 0;
}
p.price = p.price.replace('¥', '¥');
return p;
}
function formatCountDown(end) {
if (end === 0 || (end * 1000 - Date.now() < 0)) {
return '00000000';
}
let timeInSecond = (end * 1000 - Date.now()) / 1000;
let day = 24 * 60 * 60;
let numberOfDay = Math.floor(timeInSecond / day);
timeInSecond = timeInSecond - numberOfDay * day;
numberOfDay = Math.min(numberOfDay, 99);
let hour = 60 * 60;
let numberOfHour = Math.floor(timeInSecond / hour);
timeInSecond = timeInSecond - numberOfHour * hour;
let minute = 60;
let numberOfMinute = Math.floor(timeInSecond / minute);
timeInSecond = timeInSecond - numberOfMinute * minute;
let numberOfSecond = parseInt(timeInSecond, 10);
let list = [numberOfDay, numberOfHour, numberOfMinute, numberOfSecond];
for (let i = 0; i < list.length; i++) {
let item = list[i];
if (item < 10) {
list[i] = '0' + item;
} else {
list[i] = '' + item;
}
}
return list;
}
class YoLuckApi extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 列表页
* @param page
* @param type
* @returns {Promise}
*/
getList({page, type}) {
return yoLuckApi.get(MODULE + '/list', {
page,
type,
channel: 0
}).then(result => {
if (result.code === 200) {
const products = result.data;
const newProducts = products.map((p) => {
p = productTime(p);
p.countdown = formatCountDown(p.end_time);
return p;
});
result.data = newProducts;
return result;
}
return result;
});
}
/**
* 详情页
* @param actPrizeId
* @returns {Promise}
*/
getDetail({actPrizeId, uid}) {
return yoLuckApi.get(MODULE + '/content', {actPrizeId, uid}).then(result => {
if (result.code === 200) {
productTime(result.data);
result.data.countdown = formatCountDown(result.data.end_time);
}
return result;
});
}
/**
* 推荐列表
* @param actPrizeId
* @returns {Promise}
*/
getRecommend({actPrizeId}) {
return yoLuckApi.get(MODULE + '/list/recommend', {
actPrizeId,
channel: 0
}).then(result => {
if (result.code === 200) {
const products = result.data;
const newProducts = products.map((p) => {
p = productTime(p);
p.countdown = formatCountDown(p.end_time);
return p;
});
result.data = newProducts;
return result;
}
return result;
});
}
/**
* 已参加用户
* @param actPrizeId
* @returns {Promise}
*/
getRecentAvatars({actPrizeId}) {
return yoLuckApi.get(MODULE + '/code/recent', {actPrizeId});
}
/**
* 我的列表
* @param page
* @param type
* @returns {Promise}
*/
getMyList({page, type, limit, uid}) {
return yoLuckApi.get(MODULE + '/list/mine', {type, page, uid, limit, channel: 0});
}
/**
* 我的抽奖码列表(单个活动)
* @param uid
* @param actPrizeId
* @returns {Promise}
*/
getMyListWithActid(uid, actPrizeId) {
return yoLuckApi.get(MODULE + '/code/mine', {uid, actPrizeId});
}
/**
* 获得分享码
* @param shareUid
* @param uid
* @param actPrizeId
* @param userThumb
* @param userName
* @returns {Promise}
*/
fetchCode({shareUid, uid, actPrizeId, userThumb, userName}) {
return yoLuckApi.post(MODULE + '/code/gain', {
shareUid,
uid,
actPrizeId,
userThumb,
userName
});
}
_getResourceCode(param) {
return this.get({
api: serviceAPI,
url: 'operations/api/v5/resource/get',
data: {
content_code: param.contentCode,
platform: 'iphone'
},
param: {code: 200}
}).then((result) => {
result = result.data;
return result;
});
}
_getUsreInfo(uid) {
if (!uid) {
return Promise.resolve({
code: 400
});
}
return this.get({
data: {
method: 'app.passport.profile',
uid: uid
},
param: {
code: 200
}
});
}
}
module.exports = YoLuckApi;
... ...
const YoLuckApi = require('./yoluck-api-back');
const _ = require('lodash');
const logger = global.yoho.logger;
const YOLUCK_LIST_TYPE = {
running: 0,
ready: 1,
finished: 2,
joined: 3
};
const YOLUCK_MYLIST_TYPE = {
running: 0,
finished: 1
};
const ACTIVITY = {
UNKNOWN: 0,
READY: 1, // 活动未开始
START: 2, // 活动开始
END: 3, // 活动结束
LUCK: 4, // 抽奖结束
END_LESS_PEOPLE: 5 // 人数不足
};
const STEP = {
ZERO: 0,
FIRST: 1,
SECOND: 2,
THIRD: 3,
FOURTH: 4,
};
const ACTION_BAR_STATUS = {
UNKNOWN: 0,
READY: 1, // 未开始
START: 2, // 参加
ALEADY: 3, // 已参加活动
WAIT: 4, // 等待抽奖中
LUCK: 5, // 抽奖结束
END: 6, // 活动结束
};
class YoLuckService extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.api = new YoLuckApi(ctx);
}
async index(type = YOLUCK_LIST_TYPE.running, uid) {
try {
const [r1, r2] = await Promise.all([
this.getList({page: 1, type, uid}),
this.getBottomBanner()
]);
if (r1.error) {
return r1;
}
const desc = {
[YOLUCK_LIST_TYPE.running]: '进行中',
[YOLUCK_LIST_TYPE.ready]: '即将开始',
[YOLUCK_LIST_TYPE.finished]: '已结束',
[YOLUCK_LIST_TYPE.joined]: '已参加',
};
const pages = {
tabs: [{
type: YOLUCK_LIST_TYPE.running,
active: false,
key: desc[YOLUCK_LIST_TYPE.running]
}, {
type: YOLUCK_LIST_TYPE.ready,
active: false,
key: desc[YOLUCK_LIST_TYPE.ready]
}, {
type: YOLUCK_LIST_TYPE.finished,
active: false,
key: desc[YOLUCK_LIST_TYPE.finished]
}, {
type: YOLUCK_LIST_TYPE.joined,
active: false,
key: desc[YOLUCK_LIST_TYPE.joined]
}],
panels: [{
type: YOLUCK_LIST_TYPE.running,
active: false,
list: [],
key: desc[YOLUCK_LIST_TYPE.running]
}, {
type: YOLUCK_LIST_TYPE.ready,
active: false,
list: []
}, {
type: YOLUCK_LIST_TYPE.finished,
active: false,
list: [],
key: desc[YOLUCK_LIST_TYPE.running]
}, {
type: YOLUCK_LIST_TYPE.joined,
active: false,
list: [],
key: desc[YOLUCK_LIST_TYPE.joined]
}],
resource: r2,
currentType: type
};
for (let t of Object.keys(pages.tabs)) {
let tab = pages.tabs[t];
let panel = pages.panels[t];
if (tab.type === type) {
tab.active = true;
panel.active = true;
panel.list = r1;
}
}
return pages;
} catch (e) {
return {
error: e
};
}
}
async getList({page, type, uid}) {
try {
let result;
if (type === YOLUCK_LIST_TYPE.joined) {
if (!uid) {
return {
error: 400,
};
}
const [resRunning, resFinished] = await Promise.all([
this.getMyListNext({page: 1, limit: 1000, type: YOLUCK_MYLIST_TYPE.running, uid}),
await this.getMyListNext({page: 1, limit: 1000, type: YOLUCK_MYLIST_TYPE.finished, uid})
]);
result = [];
if (resRunning.error) {
result.push([]);
} else {
result.push(resRunning);
}
if (resFinished.error) {
result.push([]);
} else {
result.push(resFinished);
}
return result;
} else {
result = await this.api.getList({page, type});
}
if (result.code !== 200) {
return {
error: '出错了'
};
}
return result.data;
} catch (e) {
return {
error: e
};
}
}
async _getDetail(actPrizeId, uid) {
try {
const result = await this.api.getDetail({actPrizeId, uid});
if (result.code !== 200) {
return {
error: 'error'
};
}
return result.data;
} catch (e) {
return {
error: e
};
}
}
async _getRecentAvatars(actPrizeId) {
try {
const result = await this.api.getRecentAvatars({actPrizeId});
if (result.code !== 200) {
return {
error: 'error'
};
}
return result.data;
} catch (e) {
return {
error: '出错了'
};
}
}
async getDetail(actPrizeId, uid) {
let userName = uid && _.get(this.ctx.req, 'user.NAME');
const [r1, r2, r3, r4] = await Promise.all([
this._getDetail(actPrizeId, uid),
this._getRecentAvatars(actPrizeId),
this.getDetailBanner(),
userName ? Promise.resolve({}) : this.api._getUsreInfo(uid)
]);
const result = {};
if (r1.error) {
result.error = r1.error;
return result;
}
result.userName = userName || _.get(r4, 'data.nickname', '') || '';
result.actPrizeId = actPrizeId;
result.product = !r1.error ? r1 : {};
result.avatars = !r2.error ? r2.map(i => {
i.user_name = this.wrapperName(i.user_name);
i.user_thumb = i.user_thumb || 'http://img12.static.yhbimg.com/sns/2018/08/02/15/0237a5305f921865764e8409fcffbd3299.png';
return i;
}) : [];
result.myPrizeCount = !r1.error ? r1.myCodeNum : 0;
result.product.myPrizeCount = result.myPrizeCount;
let participantCount = !r1.error ? r1.joinNum : 0;
if (r1.status === ACTIVITY.END || r1.status === ACTIVITY.LUCK) {
participantCount = r1.limit;
}
let notice;
try {
notice = JSON.parse(result.product.notice);
} catch (e) {} // eslint-disable-line
notice = _.assign({}, notice);
notice.content = notice.content || '关注公众号“潮流有货”,发送“开奖”查看中奖结果';
notice.h5BtnName = notice.h5BtnName || '关注';
result.product.notice = notice;
result.product.participantCount = participantCount;
result.actionStatus = this.setActionStatus(result.product);
result.resource = r3;
this.setStep(result);
return result;
}
wrapperName(name) {
if (!name) {
return '';
}
let nL = name.length;
let newName = [];
if (nL > 5) {
newName.push(name[0]);
newName.push(name[1]);
newName.push('*');
newName.push('*');
newName.push(name[nL - 1]);
return newName.join('');
} else {
return name;
}
}
formatN(format, num) {
let n = num + '';
let nList = n.split('');
let l = nList.length;
let fl = format.length;
if (format.length < nList.length) {
return nList;
}
let el = fl - l;
for (let i = 0; i < el; i++) {
nList.splice(0, 0, '0');
}
return nList.join('');
}
setActionStatus(product) {
let status = ACTION_BAR_STATUS.START;
let activityStatus = product.status;
if (activityStatus === ACTIVITY.UNKNOWN) {
status = ACTION_BAR_STATUS.END;
} else if (activityStatus === ACTIVITY.READY) {
status = ACTION_BAR_STATUS.READY;
} else if (activityStatus >= ACTIVITY.END) {
if (this.isInActivity(product)) {
if (activityStatus === ACTIVITY.LUCK) {
status = ACTION_BAR_STATUS.LUCK;
} else {
status = ACTION_BAR_STATUS.WAIT;
}
} else {
status = ACTION_BAR_STATUS.END;
}
} else {
if (this.isInActivity(product)) {
status = ACTION_BAR_STATUS.ALEADY;
} else {
status = ACTION_BAR_STATUS.START;
}
}
return status;
}
isInActivity(p) {
return p.myPrizeCount > 0;
}
setStep(result) {
let step = STEP.ZERO;
let activityStatus = result.product.status;
let myPrizeCount = result.product.myPrizeCount;
if (myPrizeCount === 0) {
step = STEP.ZERO;
} else {
if (activityStatus === ACTIVITY.START) {
myPrizeCount = result.myPrizeCount;
if (myPrizeCount === 0) {
step = STEP.ZERO;
} else if (myPrizeCount === 1) {
step = STEP.FIRST;
} else if (myPrizeCount >= 2) {
step = STEP.SECOND;
} else {
step = STEP.ZERO;
}
} else if (activityStatus === ACTIVITY.END || activityStatus === ACTIVITY.LUCK) {
step = STEP.THIRD;
} else if (activityStatus === ACTIVITY.END_LESS_PEOPLE) {
step = STEP.FOURTH;
} else {
step = STEP.ZERO;
}
}
result.step = step;
}
async getMyListNext({page, type, limit, uid}) {
try {
const result = await this.api.getMyList({page, type, uid, limit});
if (result.code !== 200) {
return {
error: '出错了'
};
}
return result.data;
} catch (e) {
return {
error: e
};
}
}
async getResourceCode(params) {
const result = await this.api._getResourceCode(params);
const url = _.get(result, '[0].data.list[0]', {});
url.width = _.get(result, '[0].data.imageWidth', 0);
url.height = _.get(result, '[0].data.imageHeight', 0);
return url;
}
async getDetailBanner() {
try {
const result = await this.getResourceCode({
contentCode: 'ccc32dbedf164a52b4efa34383878860'
});
if (!result.width) {
result.width = 750;
result.height = 140;
}
return result;
} catch (e) {
return {
error: '出错了'
};
}
}
async getBottomBanner() {
try {
const result = await this.getResourceCode({
contentCode: '5a2203f5656fbc9788bd8af70f2823d3'
});
if (!result.width) {
result.width = 750;
result.height = 234;
}
return result;
} catch (e) {
return {
error: '出错了'
};
}
}
async getCode({shareUid, uid, actPrizeId}) {
try {
let userInfo = await this.api._getUsreInfo(uid);
let userName = _.get(userInfo, 'data.nickname', '');
let userThumb = _.get(userInfo, 'data.head_ico', '');
const result = await this.api.fetchCode({
shareUid,
uid,
actPrizeId,
userThumb,
userName
});
if (result.code !== 200) {
logger.error(result);
return {
error: '错误'
};
}
if (userThumb.indexOf('?') > 0) {
userThumb = _.split(userThumb, '?')[0] + '?imageView2/2/w/70/h/70/q/60';
}
return _.assign({userThumb}, result.data);
} catch (e) {
logger.error(e);
return {
error: '出错了'
};
}
}
async getActivityCodeList(uid, actPrizeId) {
let result = await this.api.getMyListWithActid(uid, actPrizeId);
let codeList = [];
let nearAvatar = '//img10.static.yhbimg.com/headimg/2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100'; // eslint-disable-line
_.forEach(_.get(result, 'data', []), value => {
if (value.prize_code) {
if (value.user_thumb.indexOf('headimg') > 0) {
value.user_thumb = nearAvatar;
} else {
if (value.user_thumb.indexOf('?') > 0) {
value.user_thumb = _.split(value.user_thumb, '?')[0] + '?imageView2/2/w/70/h/70/q/60';
}
nearAvatar = value.user_thumb;
}
codeList.push({
prizeCode: value.prize_code,
userThumb: value.user_thumb
});
}
});
return codeList;
}
}
module.exports = {
YOLUCK_LIST_TYPE,
YoLuckService
};
... ...
... ... @@ -6,6 +6,7 @@
'use strict';
const _ = require('lodash');
const router = require('express').Router(); // eslint-disable-line
const cRoot = './controllers';
const auth = require('../../doraemon/middleware/auth');
... ... @@ -72,6 +73,7 @@ const haveGain = require(`${cRoot}/have-gain`);
const redPack = require(`${cRoot}/red-envelope`);
const yoluck = require(`${cRoot}/yoluck`);
const yoluckBack = require(`${cRoot}/yoluck-back`);
// routers
... ... @@ -356,13 +358,23 @@ router.post('/red-envelope/submitWxCode', auth, redPack.submitWxCode);
router.get('/have-gain/promo/:id.html', haveGain.promoDetail);
router.post('/have-gain/promo/:id', auth, haveGain.promoSubmit);
function swtichYoLuck(newMiddleware, oldMiddleware) {
return (req, res, next) => {
if (_.get(req.app.locals, 'wap.open.yoluck-down', false)) {
res.setHeader('yoluck-down', 'true');
return oldMiddleware(req, res, next);
}
return newMiddleware(req, res, next);
};
}
// yoluck
router.get('/yoluck/index.html', yoluck.index);
router.get('/yoluck/mylist.html', auth, yoluck.index);
router.get('/yoluck/next', yoluck.nextPage);
router.get('/yoluck/index.html', swtichYoLuck(yoluck.index, yoluckBack.index));
router.get('/yoluck/mylist.html', auth, swtichYoLuck(yoluck.index, yoluckBack.index));
router.get('/yoluck/next', swtichYoLuck(yoluck.nextPage, yoluckBack.nextPage));
router.get('/yoluck/:id.html', yoluck.detail);
router.post('/yoluck/:id.html', auth, yoluck.getCode);
router.post('/yoluck/detail/mylist.html', yoluck.getActivityCodeList);
router.get('/yoluck/:id.html', swtichYoLuck(yoluck.detail, yoluckBack.detail));
router.post('/yoluck/:id.html', auth, swtichYoLuck(yoluck.getCode, yoluckBack.getCode));
router.post('/yoluck/detail/mylist.html', swtichYoLuck(yoluck.getActivityCodeList, yoluckBack.getActivityCodeList));
module.exports = router;
... ...
{{#result}}
<div id="hide-info" data-username="{{userName}}"></div>
{{#if product.status}}
{{#unless @root.isApp}}
<div class="fellow-bar-wrap">
{{> yoluck-back/fellow-bar}}
</div>
{{/unless}}
{{/if}}
<div class="header">
{{> yoluck-back/product-detail-header product=product avatars=avatars}}
</div>
{{> yoluck-back/lottery-machine}}
<div class="help">
{{> yoluck-back/help}}
</div>
{{> yoluck-back/desc list=product.content resource=resource}}
<div class="line"></div>
<div class="action-bar-wrap">
{{> yoluck-back/action-bar status=actionStatus num=myPrizeCount actPrizeId=actPrizeId lotteryInfo=product.lottery_info}}
</div>
<div class="foot"></div>
<div class="js-luck-alert">
</div>
<div class="js-clipbroad"></div>
{{/result}}
... ...
{{#tabpanel}}
<div class="js-tab-comp" data-type="{{currentType}}">
<!--tab切-->
<div class="js-tabs tabs tabs-class">
{{#each tabs}}
<div class="js-tab tab {{#if active}}active{{/if}}" data-key="{{key}}" data-index="{{@index}}">
{{key}}
</div>
{{/each}}
</div>
<div class="list-top-blank"></div>
<!--panel体-->
<div class="js-panels panel-body">
{{#each panels}}
<div class="js-panel panel {{#if active}}active{{^}}inactive{{/if}}">
<!--头部-->
{{#ifcond @index '===' 0}}
{{#ifcond list.length '!==' 0}}
<div class="js-panel-header">
<img
src="//img11.static.yhbimg.com/yhb-img01/2018/12/07/15/0188307712613ce043d4b68a94761ee1ff.gif"
alt="">
</div>
{{/ifcond}}
{{/ifcond}}
<!--数据部-->
<div class="js-panel-body">
{{#ifcond @index '===' 3}}
{{> yoluck-back/prize-list running=list.[0] finished=list.[1] }}
{{^}}
{{#each list}}
{{> yoluck-back/product-item .}}
{{/each}}
{{/ifcond}}
</div>
<!--尾部-->
{{#ifcond @index '!==' 3}}
<div class="js-panel-footer">
{{#if ../resource.url}}
<a class="bottom-banner" href="{{../resource.url}}">
<img src="{{image2 ../resource.src w=../resource.width h=../resource.height}}" alt="">
</a>
{{/if}}
</div>
{{/ifcond}}
</div>
{{/each}}
</div>
<!--加载更多-->
<div class="list-foot-blank">暂无更多内容</div>
</div>
<div class="js-clipbroad"></div>
{{/tabpanel}}
... ...
{{#tabpanel}}
<div class="js-tab-comp">
<div class="js-tabs tabs tabs-class">
{{#each tabs}}
<div class="js-tab tab {{#if active}}active{{/if}}" data-key="{{key}}" data-index="{{@index}}">
{{key}}
</div>
{{/each}}
</div>
<div class="fellow-bar">
{{> yoluck-back/fellow-bar}}
</div>
<div class="list-head-blank"></div>
<div class="js-panels panel-body">
{{#each panels}}
<div class="js-panel panel {{#if active}}active{{^}}inactive{{/if}}">
{{#each list}}
{{> yoluck-back/prize-item .}}
{{/each}}
</div>
{{/each}}
</div>
<div class="list-foot-blank">暂无更多内容</div>
</div>
{{/tabpanel}}
... ...
<div class="action-bar-comp">
<div class="action-bar">
<a class="action-item action-list" href="/activity/yoluck/index.html">
<div class="action-image action-icon"></div>
</a>
{{#ifcond status '===' 1}}
<div class="action-item over">即将开始</div>
{{/ifcond}}
{{#ifcond status '===' 2}}
<div class="action-item ok js-join auth">
0元参加抽奖
</div>
{{/ifcond}}
{{#ifcond status '===' 3}}
<a class="action-item ok js-share auth" >
分享得更多抽奖码,增加中奖率
</a>
{{/ifcond}}
{{#ifcond status '===' 4}}
<a class="action-item confirm auth" href="/activity/yoluck/mylist.html?type=3">
我的抽奖码({{num}})
</a>
{{/ifcond}}
{{#ifcond status '===' 5}}
<a class="action-item confirm auth" href="/activity/yoluck/mylist.html?type=3">
我的抽奖码({{num}})
</a>
<div class="action-item ok js-lottery" data-lottery='{{lotteryInfo}}'>
查看开奖结果
</div>
{{/ifcond}}
{{#ifcond status '===' 6}}
<div class="action-item over">活动已结束</div>
{{/ifcond}}
</div>
</div>
... ...
<div class="avatar-comp">
<div class="swiper-container swiper">
<div class="swiper-wrapper">
{{#each list}}
<div class="swiper-slide avatar-item">
<img src="{{image2 user_thumb w=70 h=70 q=60}}"
class="avatar-image"/>
<div class="avatar-desc">{{user_name}}参与了抽奖</div>
</div>
{{/each}}
</div>
</div>
</div>
... ...
<div class="head-counter">
<div class="title">
<div class="txt">已有</div>
{{#each count}}
<div class="num-wrapper">
<span>{{.}}</span>
<div class="mask"></div>
</div>
{{/each}}
<div class="txt">参与</div>
</div>
{{#isEqualOr status 0}}
<div class="counter-num"> 活动结束 </div>
{{/isEqualOr}}
{{#isEqualOr status 1 2}}
<div class="counter-num"> 达到 {{num}} 人开奖 </div>
{{/isEqualOr}}
{{#isEqualOr status 3}}
<div class="counter-num" > 待开奖 </div>
{{/isEqualOr}}
{{#isEqualOr status 4}}
<div class="counter-num" > 已开奖 </div>
{{/isEqualOr}}
{{#isEqualOr status 5}}
<div class="counter-num" > 待开奖 </div>
{{/isEqualOr}}
</div>
... ...
<div class="desc-comp">
<div class="desc">
<div style="width: 100%;text-align: center;">
<div class="title">商品详情</div>
</div>
{{#if resource.url}}
<a class="banner" href="{{resource.url}}">
<img class="banner-img" src="{{image2 resource.src w=resource.width h=resource.height}}" alt="">
</a>
{{/if}}
<div class="desc-content">
{{#each list}}
{{#ifcond floor_type '===' 1}}
<div>{{content}}</div>
{{/ifcond}}
{{#ifcond floor_type '===' 2}}
<img class="desc-image" src="{{image2 content q=60}}" width="100%">
{{/ifcond}}
{{#ifcond floor_type '===' 3}}
<video class="desc-video" controls="controls">
<source src="{{content}}" type="video/mp4" />
</video>
{{/ifcond}}
{{/each}}
</div>
</div>
</div>
... ...
<div class="fellow-bar-comp">
<div id="fellow-bar" class="fellow-bar" data-type='{{product.notice.h5BtnType}}' data-tip='{{product.notice.h5Tip}}' data-copy='{{product.notice.h5Copy}}' data-link='{{product.notice.h5Link}}'>
<div class="title">{{product.notice.content}}</div>
<div class="btn js-fellow">{{product.notice.h5BtnName}}</div>
</div>
</div>
... ...
<i class="iconfont" style="font-size: 1rem; vertical-align: middle;">&#xe73b;</i>
<a class="help-comp" href="https://activity.yoho.cn/feature/2765.html?title=%E6%B4%BB%E5%8A%A8%E8%AF%B4%E6%98%8E&nodownload=1">
查看活动说明
</a>
... ...
<div class="lottery-machine">
<div class="machine">
<img src="//img12.static.yhbimg.com/sns/2018/12/21/14/0231fa07f32886117eccea846e03f453a3.png">
<div class="lottery-block">
<div id="lottery-list" class="lottery-list">
<div class="lottery lottery-tpl">
<div class="l-thumb"></div>
<p class="l-title">我的<br>抽奖码</p>
<p class="l-code"></p>
</div>
<p class="more-lottery">
<a href="/activity/yoluck/index.html?type=3">
<span class="iconfont">&#xe64f;</span>
</a>
</p>
</div>
</div>
</div>
</div>
... ...
<div class="modal-mask"></div>
<div class="modal-dialog">
<div class="modal-dialog-bg"></div>
<div class="code-alert">
<text class="code-title">参加抽奖成功</text>
<div class="code-bg">
<div class="title">你的抽奖码是</div>
<div class="code">{{code}}</div>
</div>
<a class="share">分享一下,中奖概率立马double</a>
<div class="share-desc">1个好友参加=1个抽奖码=中奖几率UP!</div>
</div>
</div>
... ...
<div class="more-comp">
<div class="more">
<div class='title'>更多活动</div>
</div>
{{#each list}}
{{> ./product-item .}}
{{/each}}
</div>
... ...
<div class="prize-item-comp">
<div class="prize-item js-prizeitem" data-id="{{act_prize_id}}">
<img class="product-image" src="{{cover_img}}" alt="">
<div class="content">
<div class="code">抽奖码
<text style="color: black;">{{prize_code}}</text>
</div>
<div class="product-name">{{name}}</div>
{{#ifcond status '===' 0}}
<div class="btn">活动结束</div>
{{/ifcond}}
{{#ifcond status '===' 3}}
<div class="btn">待开奖</div>
{{/ifcond}}
{{#ifcond status '===' 4}}
<div class="btn more js-fellow" data-id="{{act_prize_id}}" data-lottery="{{lottery_info}}">查看中奖信息</div>
{{/ifcond}}
{{#ifcond status '===' 5}}
<div class="btn">待开奖</div>
{{/ifcond}}
{{#isEqualOr status 1 2 6}}
<div class="btn more js-share"
data-img="{{cover_img}}"
data-name="{{name}}"
data-price="{{price}}"
data-id="{{act_prize_id}}"
>
获得更多抽奖码
</div>
{{/isEqualOr}}
</div>
</div>
</div>
... ...
<div style="width: 100%;background: white;">
<div class="title-view">
<span class="space-line"></span>
<span class="title">进行中</span>
</div>
</div>
{{#ifcond running.length '>' 0}}
{{#each running}}
{{> yoluck/prize-item .}}
{{/each}}
{{^}}
<div class="empty"> 您尚未参加任何活动 </div>
{{/ifcond}}
<div style="width: 100%;background: white;">
<div class="title-view">
<span class="space-line"></span>
<span class="title">已公布</span>
</div>
</div>
{{#ifcond finished.length '>' 0}}
{{#each finished}}
{{> yoluck/prize-item .}}
{{/each}}
{{^}}
<div class="empty"> 您尚未参加任何活动 </div>
{{/ifcond}}
... ...
<div class="prize-progress-comp">
<div class="prize-progress">
<div class="step">
{{#isEqualOr step 0}}
<div class="step-image step0"></div>
{{/isEqualOr}}
{{#isEqualOr step 1}}
<div class="step-image step1"></div>
{{/isEqualOr}}
{{#isEqualOr step 2}}
<div class="step-image step2"></div>
{{/isEqualOr}}
{{#isEqualOr step 3 4}}
<img class="step-image step3"></div>
{{/isEqualOr}}
</div>
<div class="desc">
<div class="title {{#ifcond step '>=' 1}}active{{/ifcond}}">参加抽奖</div>
<div class="title {{#ifcond step '>=' 2}}active{{/ifcond}}">邀请好友</div>
<div class="title {{#ifcond step '>=' 3}}active{{/ifcond}}">{{#ifcond step '===' 4}}人数不足{{^}}人满开奖{{/ifcond}}</div>
</div>
</div>
</div>
... ...
{{#ifcond product.status '===' 2}}
<div class="countdown_label">
<text class="countdown_labeltext">抽奖</text>
<text class="countdown_labeltext">倒计时</text>
</div>
<div class="product_countdown" data-endtime="{{product.end_time}}">
{{> yoluck/time-countdown time=product.countdown}}
</div>
{{/ifcond}}
<div class="avatarcontainer">
{{#ifcond product.status '===' 2}}
{{#ifcond avatars.length '>' 0}}
<div class="avatars">
{{> yoluck/avatar list=avatars}}
</div>
{{/ifcond}}
{{/ifcond}}
<img class="product_image" src="{{image2 product.cover_img q=60}}"/>
</div>
<div class="product_name"
data-id="{{product.id}}"
data-name="{{product.name}}"
data-img="{{image2 product.cover_img q=60}}"
data-price="{{product.price}}"
>
{{product.name}}
</div>
<div class="product_lucky_bg">
<div class="product_lucky">
<span>抽奖价¥<span class="lucky">0</span>
</span>
</div>
<div class="product_price">{{product.price}}</div>
</div>
{{#ifcond product.status '!==' 2}}
<div class="product_time">{{formatTime product.start_time product.end_time}}</div>
{{/ifcond}}
<div class="product_margin"></div>
... ...
{{#ifcond status '===' 2}}
<div class="product_countdown" data-endtime="{{end_time}}">
{{>yoluck/time-countdown time=countdown}}
</div>
{{/ifcond}}
<img class="product_image" src="{{image2 cover_img w=760 h=470 q=60}}" alt="" data-id="{{id}}">
<div class="product_name">{{name}}</div>
<div class="product_lucky_bg">
<div class="product_lucky"><span>抽奖价¥<span class="lucky">0</span></span></div>
<div class="product_price">{{price}}</div>
</div>
{{#ifcond status '!==' 2}}
<div class="product_time">{{formatTime start_time end_time}}</div>
{{/ifcond}}
<div class="product_margin"></div>
... ...
<div class="product-status">
{{#isEqualOr status 0}}
<div class="btn cancel">活动结束</div>
{{/isEqualOr}}
{{#isEqualOr status 1}}
<div class="btn cancel">即将开始</div>
{{/isEqualOr}}
{{#isEqualOr status 2}}
<a class="btn ok js-join" data-id="{{id}}">参加抽奖</a>
{{/isEqualOr}}
{{#isEqualOr status 3}}
<div class="btn cancel">待开奖</div>
{{/isEqualOr}}
{{#isEqualOr status 4}}
<div class="btn cancel">活动结束</div>
{{/isEqualOr}}
{{#isEqualOr status 5}}
<div class="btn cancel">待开奖</div>
{{/isEqualOr}}
</div>
... ...
<div class="product">
{{>yoluck/product-item-header}}
{{>yoluck/product-item-status}}
</div>
... ...
<div class="time-countdown-comp">
{{#each time}}
<div class="num-wrapper">
<div class="mask"></div>
<text class="num-text">{{.}}</text>
<div class="mask-left"></div>
<div class="mask-right"></div>
</div>
{{#ifcond @index "!==" 3}}
<div class="number-seprator">
:
</div>
{{/ifcond}}
{{/each}}
</div>
... ...
<div class="modal-mask"></div>
<div class="modal-dialog">
<div class="modal-dialog-bg"></div>
<div class="code-alert">
<text class="code-title">参加抽奖成功</text>
<div class="code-bg">
<div class="title">你的抽奖码是</div>
<div class="code">{{code}}</div>
</div>
<a class="share">分享一下,中奖概率立马double</a>
<div class="share-desc">1个好友参加=1个抽奖码=中奖几率UP!</div>
</div>
</div>
... ...
<div class="prize-item-comp">
<div class="prize-item js-prizeitem" data-id="{{act_prize_id}}">
<img class="product-image" src="{{cover_img}}" alt="">
<div class="content">
<div class="code">抽奖码
<text style="color: black;">{{prize_code}}</text>
</div>
<div class="product-name">{{name}}</div>
{{#ifcond status '===' 0}}
<div class="btn">活动结束</div>
{{/ifcond}}
{{#ifcond status '===' 3}}
<div class="btn">待开奖</div>
{{/ifcond}}
{{#ifcond status '===' 4}}
<div class="btn more js-fellow" data-id="{{act_prize_id}}">查看中奖信息</div>
{{/ifcond}}
{{#ifcond status '===' 5}}
<div class="btn">待开奖</div>
{{/ifcond}}
{{#is-equal-or status 1 2 6}}
<div class="btn more js-share"
data-img="{{cover_img}}"
data-name="{{name}}"
data-price="{{price}}"
data-id="{{act_prize_id}}"
>
获得更多抽奖码
</div>
{{/is-equal-or}}
</div>
</div>
</div>
... ...
<div style="width: 100%;background: white;">
<div class="title-view">
<span class="space-line"></span>
<span class="title">进行中</span>
</div>
</div>
{{#ifcond running.length '>' 0}}
{{#each running}}
{{> ./prize-item .}}
{{/each}}
{{^}}
<div class="empty"> 您尚未参加任何活动 </div>
{{/ifcond}}
<div style="width: 100%;background: white;">
<div class="title-view">
<span class="space-line"></span>
<span class="title">已公布</span>
</div>
</div>
{{#ifcond finished.length '>' 0}}
{{#each finished}}
{{> ./prize-item .}}
{{/each}}
{{^}}
<div class="empty"> 您尚未参加任何活动 </div>
{{/ifcond}}
... ...
{{#ifcond status '===' 2}}
<div class="product_countdown">
{{>./time-countdown time=countdown}}
</div>
{{/ifcond}}
<img class="product_image" src="{{image2 cover_img w=760 h=470 q=60}}" alt="" data-id="{{id}}">
<div class="product_name">{{name}}</div>
<div class="product_lucky_bg">
<div class="product_lucky"><span>抽奖价¥<span class="lucky">0</span></span></div>
<div class="product_price" >{{price}}</div>
</div>
{{#ifcond status '!==' 2}}
<div class="product_time">{{formatTime start_time end_time}}</div>
{{/ifcond}}
<div class="product_margin"></div>
... ...
<div class="product-status">
{{#is-equal-or status 0}}
<div class="btn cancel">活动结束</div>
{{/is-equal-or}}
{{#is-equal-or status 1}}
<div class="btn cancel">即将开始</div>
{{/is-equal-or}}
{{#is-equal-or status 2}}
<a class="btn ok js-join" data-id="{{id}}">参加抽奖</a>
{{/is-equal-or}}
{{#is-equal-or status 3}}
<div class="btn cancel">待开奖</div>
{{/is-equal-or}}
{{#is-equal-or status 4}}
<div class="btn cancel">活动结束</div>
{{/is-equal-or}}
{{#is-equal-or status 5}}
<div class="btn cancel">待开奖</div>
{{/is-equal-or}}
</div>
... ...
<div class="product">
{{> ./product-item-header}}
{{> ./product-item-status}}
</div>
... ...
<div class="time-countdown-comp">
{{#each time}}
<div class="num-wrapper">
<div class="mask"></div>
<text class="num-text">{{.}}</text>
<div class="mask-left"></div>
<div class="mask-right"></div>
</div>
{{#ifcond @index "!==" 3}}
<div class="number-seprator">
:
</div>
{{/ifcond}}
{{/each}}
</div>
... ...
import 'scss/activity/yoluck/yoluck-detail.page.scss';
const cookie = require('yoho-cookie');
let Swiper = require('yoho-swiper');
const loading = require('js/plugin/loading');
let timeCountDownTpl = require('hbs/activity/yoluck-back/time-countdown.hbs');
let luckAlertTpl = require('hbs/activity/yoluck-back/luck-alert.hbs');
let formatCountDown = require('./yoluck/formatCountDown');
let YolukcApi = require('./yoluck/api');
let api = new YolukcApi();
let tip = require('js/plugin/tip');
let dialog = require('js/plugin/dialog');
let yoSdk = require('yoho-activity-sdk');
let yoho = require('js/yoho-app');
let Clipboard = require('clipboard');
let makeShareData = require('./yoluck/share');
let Lottery = require('./yoluck/lottery');
let versionCompare = require('./yoluck/version');
function reload() {
window.location && window.location.reload(); //eslint-disable-line
}
require('js/plugin/modal.alert');
require('js/common');
let store = {
running: false,
shareUid: window.queryString.shareUid || '',
currentVersion: cookie.get('app_version'),
targetVersion: '6.8.3',
};
let hideInfo = $('#hide-info').remove().data();
let $fellowBar = $('#fellow-bar');
let $product = $('.product_name');
let name = $product.data('name');
let img = $product.data('img');
let price = $product.data('price');
let id = $product.data('id');
let user;
let shareData;
let lottery = new Lottery('#lottery-list');
let sharePlugin = require('js/common/share');
loading.init($(document.body), {timeout: 20000});
new Swiper('.swiper-container', {
direction: 'vertical',
lazyLoading: true,
lazyLoadingInPrevNext: true,
paginationClickable: true,
autoplay: 4000
});
function fellow(content) {
if (content) {
$.yAlert({
content: `<div class="fellow-tip-content">${content}</div>` // eslint-disable-line
});
return;
}
$.yAlert({
content: `<div>公众号
<span style="font-weight: bolder">“潮流有货”</span>已经复制成功,</div>
<div>打开微信搜索去添加吧~</div>` // eslint-disable-line
});
}
function alertVersion() {
$.yAlert({content: '您的版本较低,请更新最新版本体验'});
}
function getUser() {
try {
if (user) {
return Promise.resolve();
}
return yoSdk.getUser().then(u => {
user = u;
shareData = makeShareData({
name: name,
imgUrl: img,
price: price,
shareUid: user && user.uid,
userName: hideInfo && hideInfo.username,
actPrizeId: id
});
sharePlugin(shareData.h5);
});
} catch (e) {
return Promise.resolve();
}
}
getUser();
(function() {
if (!lottery.$list || !lottery.$list.length) {
return;
}
api.getDetailMyCode({id}).then(res => {
if (res.code !== 200) {
return;
}
lottery.print(res.data);
});
}());
function share() {
if (yoSdk.env === 'app') {
// 由于app版本兼容性问题
if (versionCompare(store.currentVersion, store.targetVersion) < 0) {
alertVersion();
return;
}
loading.showLoading();
if (store.running) {
return;
}
store.running = true;
getUser().then(() => {
yoho.invokeMethod('go.showshareaction', shareData && shareData.app);
loading.hideLoading();
store.running = false;
});
} else if (/QQ/i.test(navigator.userAgent) ||
/MicroMessenger/i.test(navigator.userAgent)) {
dialog.showDialog({hasClass: 'yoluck-guide-mask'});
} else if (yoSdk.env === 'h5') {
$('.js-clipbroad').trigger('click');
}
}
let luckAlert = {
$el: $('.js-luck-alert'),
init() {
this.bindEvent();
},
show(code) {
if (this.$el.find('.modal-mask').length === 0) {
this.$el.html(luckAlertTpl({
code
}));
} else {
this.$el.show();
}
},
hide() {
this.$el.hide();
},
bindEvent() {
this.$el.on('click', '.modal-mask', () => {
this.hide();
reload();
return true;
});
this.$el.on('click', '.share', function() {
share();
});
}
};
let fellowInfo = $fellowBar.data() || {};
if (+fellowInfo.type === 2) {
$fellowBar.on('click', '.js-fellow', function() {
if (fellowInfo.link) {
window.location.href = fellowInfo.link;
}
});
} else {
let clipboardFellow = new Clipboard('.js-fellow', {
text: function() {
return fellowInfo.copy || '潮流有货';
}
});
clipboardFellow.on('success', function(e) {
fellow(fellowInfo.tip);
tip.show('内容已复制', 2000);
e.clearSelection();
});
}
(function() {
let lotteryInfo = $('.js-lottery').data('lottery') || {};
let clipboardLottery = new Clipboard('.js-lottery', {
text: function() {
return lotteryInfo.h5Copy || '潮流有货';
}
});
clipboardLottery.on('success', function(e) {
fellow(lotteryInfo.h5Tip);
tip.show('内容已复制', 2000);
e.clearSelection();
});
let clickFn;
if (lotteryInfo) {
if (yoSdk.env === 'app' && lotteryInfo.app) {
clickFn = function() {
$.yAlert({
content: `<div>本期中奖号码: <span style="font-weight: bolder;">${lotteryInfo.app}</span></div>` // eslint-disable-line
});
};
} else if (yoSdk.env === 'h5' && +lotteryInfo.h5Type) {
if (+lotteryInfo.h5Type === 2 && lotteryInfo.h5Link) {
clickFn = function() {
window.location.href = lotteryInfo.h5Link;
};
}
}
}
if (clickFn) {
clipboardLottery.destroy();
$('.js-lottery').on('click', clickFn);
}
}());
let clipboardShare = new Clipboard('.js-clipbroad', {
text: function() {
return shareData && shareData.h5.copyDeac;
}
});
clipboardShare.on('success', function(e) {
if (yoSdk.env === 'app') {
return;
}
tip.show('复制成功,发送给好友为您助力', 3500);
e.clearSelection();
});
if (window.cookie('yoluck_share') && store.shareUid) {
window.setCookie('yoluck_share', null);
share();
}
luckAlert.init();
setInterval(() => {
let $countdown = $('.product_countdown');
const time = $countdown.data('endtime');
const formatTime = formatCountDown(time);
$countdown.html(timeCountDownTpl({
time: formatTime
}));
}, 1000);
// 助力
$('.action-bar-comp').on('click', '.js-join', function() {
if (store.running) {
return;
}
store.running = true;
api.getCode({shareUid: store.shareUid, ...yoSdk.getQueryObj()}).then(result => {
if (result.code === 200) {
lottery.print(result.data);
luckAlert.show(result.data.prizeCode);
} else {
if (result.code === 400) {
yoSdk.goLogin();
} else {
tip.show(result.message, 3500);
}
}
}).always(() => {
store.running = false;
});
});
// 分享
$('.action-bar-comp').on('click', '.js-share', function() {
share();
});
... ...
import 'scss/activity/yoluck/yoluck-list.page.scss';
const loading = require('js/plugin/loading');
let $ = require('yoho-jquery');
let Api = require('./yoluck/api');
let productTpl = require('hbs/activity/yoluck-back/product-item.hbs');
let prizeListTpl = require('hbs/activity/yoluck-back/prize-list.hbs');
let timeCountDownTpl = require('hbs/activity/yoluck-back/time-countdown.hbs');
let formatCountDown = require('./yoluck/formatCountDown');
let yoSdk = require('yoho-activity-sdk');
let yoho = require('js/yoho-app');
const DETAIL_URI = location.protocol + '//m.yohobuy.com/activity/yoluck';
let tip = require('js/plugin/tip');
let Clipboard = require('clipboard');
let publicCopyInfo = '';
require('js/plugin/modal.alert');
loading.init($(document.body), {timeout: 20000});
let footerText = ['内容加载中...', '暂无更多内容'];
let store = {
list: [{
page: 0,
}, {
page: 0,
}, {
page: 0,
}, {
page: 0
}],
tabIndex: 0,
footText: '',
running: false,
countDown: $(),
user: null,
shareData: null
};
let api = new Api();
let bus$ = $.Callbacks(); // eslint-disable-line
let $tabpanel = $('.js-tab-comp');
let tabpanelStore = {
tabs: [],
key: 0,
nodes: [],
currentKey: 0,
footer: null
};
let prizeListStore = {
push(arr) {
if (!arr || !arr.length) {
return;
}
this.list = this.list || {};
$.each(arr, (index, value) => {
if (value && value.act_prize_id) {
this.list[value.act_prize_id] = value;
}
});
},
get(id) {
return this.list && this.list[id];
}
};
function initStore() {
// 初始化为
let tabIndex = +$tabpanel.data('type');
store.list[tabIndex].page = 1;
store.tabIndex = tabIndex;
tabpanelStore.currentKey = tabIndex;
}
tabpanelStore.nodes = $tabpanel.find('.js-panel');
tabpanelStore.tabs = $tabpanel.find('.js-tab');
tabpanelStore.footer = $tabpanel.find('.list-foot-blank');
store.countDown = $tabpanel.find('.product_countdown');
function updateFooter(msg) {
tabpanelStore.footer.text(msg);
}
function updateTabs() {
tabpanelStore.nodes.each(function(index) {
let $this = $(this);
let active = index === tabpanelStore.key;
if (active) {
$this.addClass('active').removeClass('inactive');
} else {
$this.addClass('inactive').removeClass('active');
}
});
tabpanelStore.tabs.each(function() {
let $this = $(this);
let active = $this.data('index') === tabpanelStore.key;
if (active) {
$this.addClass('active').removeClass('inactive');
} else {
$this.addClass('inactive').removeClass('active');
}
});
}
function fetchPage(page, index) {
if (store.running) {
return;
}
store.running = true;
page++;
updateFooter(footerText[0]);
return api.getPage(page, index)
.then(result => {
if (result.code !== 200) {
if (result.code === 400) {
return yoSdk.goLogin();
}
return;
}
if (result.data.length === 0) {
return;
}
if (index === 3) {
let $node = tabpanelStore.nodes.eq(index);
let $products = prizeListTpl({running: result.data[0], finished: result.data[1]});
prizeListStore.push(result.data[1]);
$node.find('.js-panel-body').html($products);
} else {
let $node = tabpanelStore.nodes.eq(index);
let $products = result.data.map(r => {
const p = productTpl(r);
store.countDown = store.countDown.add($(p).find('.product_countdown'));
return p;
});
store.list[index].page = page;
$node.find('.js-panel-body').append($products);
}
})
.always(() => {
updateFooter(footerText[1]);
store.running = false;
});
}
function onTabClick(type, index) {
if (type !== 'tabClick') {
return;
}
store.tabIndex = index;
let page = store.list[index].page;
// 点击未开始则下走
if (page !== 0) {
return;
}
// 下一页
// page = 0
fetchPage(page, store.tabIndex);
}
function onReachBottom(type) {
if (type !== 'reachBottom') {
return;
}
let index = store.tabIndex;
let page = store.list[index].page;
if (page === 0) {
return;
}
// 下一页
// page != 0
fetchPage(page, store.tabIndex);
}
function fellow(id, lottery) {
let info = prizeListStore.get(id);
let lotteryInfo;
if (info && info.lottery_info) {
try {
lotteryInfo = $.parseJSON(info.lottery_info);
} catch(e) {} // eslint-disable-line
}
lotteryInfo = lotteryInfo || lottery;
if (lotteryInfo) {
if (yoSdk.env === 'app' && lotteryInfo.app) {
$.yAlert({
content: `<div class="modal-view-lottery">本期中奖号码: <span style="font-weight: bolder;">${lotteryInfo.app}</span></div>` // eslint-disable-line
});
return;
} else if (yoSdk.env === 'h5' && +lotteryInfo.h5Type) {
if (+lotteryInfo.h5Type === 1) {
$.yAlert({
content: `<div class="modal-view-lottery">${lotteryInfo.h5Tip}</div>` // eslint-disable-line
});
publicCopyInfo = lotteryInfo.h5Copy || '';
$('.js-clipbroad').trigger('click');
} else if (lotteryInfo.h5Link) {
window.location.href = lotteryInfo.h5Link;
}
return;
}
}
$.yAlert({
content: `<div>微信搜索公众号</div>
<div><span style="font-weight: bolder;">“潮流有货”</span>并关注,发送</div>
<div>关键词<span style="font-weight: bolder;">“开奖”</span>查询中奖信息</div>`
});
}
function getUser() {
try {
if (store.user) {
return Promise.resolve();
}
return yoSdk.getUser().then(u => {
store.user = u;
});
} catch (e) {
// pass
return Promise.resolve();
}
}
bus$.add(onTabClick);
bus$.add(onReachBottom);
function initClipboard() {
let _clipboard = new Clipboard('.js-clipbroad', {
text: function() {
return publicCopyInfo;
}
});
_clipboard.on('success', function() {
if (publicCopyInfo) {
tip.show('内容已复制', 2000);
}
});
}
initClipboard();
getUser();
$tabpanel.on('click', '.js-tab', function() {
let $tab = $(this);
let index = $tab.data('index');
if (index === tabpanelStore.key) {
return;
}
tabpanelStore.key = index;
updateTabs();
bus$.fire('tabClick', index);
});
$tabpanel
.on('click', '.js-prizeitem,.js-join,.product_image', function() {
let id = $(this).data('id');
let href = DETAIL_URI + '/' + id + '.html?t=1';
if (yoSdk.env === 'app') {
let link = yoho.parseUrl(href);
yoho.goH5(href, JSON.stringify({
action: 'go.h5',
params: {
islogin: 'N',
type: 0,
updateflag: Date.now() + '',
url: link.path,
param: link.query
}
}));
} else {
window.location.href = href;
}
return false;
})
.on('click', '.js-fellow', function() {
fellow($(this).data('id'), $(this).data('lottery'));
return false;
});
$(window).on('scroll', function() {
if ((($(document).height() - ($(window).height() + $(window).scrollTop())) / $(document).height()) === 0) {
bus$.fire('reachBottom');
}
});
setInterval(() => {
store.countDown.each(function() {
let $this = $(this);
const time = $this.data('endtime');
const formatTime = formatCountDown(time);
$this.html(timeCountDownTpl({
time: formatTime
}));
});
}, 1000);
initStore();
... ...