|
@@ -15,6 +15,7 @@ Page({
|
|
|
data: {
|
|
|
pointerPos: 0,
|
|
|
hitPos: null,
|
|
|
+ isHit: null,
|
|
|
activityId: 0,
|
|
|
forbidTurn: false,
|
|
|
giftList: DEFAULT_GIFTS,
|
|
@@ -23,8 +24,15 @@ Page({
|
|
|
remainNumSplits: [],
|
|
|
showHitPrizeDlg: false,
|
|
|
showNoHitPrizeDlg: false,
|
|
|
+ showNeedShareDlg: false,
|
|
|
showPage: true,
|
|
|
- isLogin: false
|
|
|
+ isLogin: false,
|
|
|
+ hitResult: null,
|
|
|
+ noHitResult: null
|
|
|
+ },
|
|
|
+
|
|
|
+ popMessage(message) {
|
|
|
+ app.showToast(message, "none")
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -32,7 +40,7 @@ Page({
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
if (!options.id) {
|
|
|
- app.showToast ('入参错误');
|
|
|
+ this.popMessage ('入参错误');
|
|
|
wx.navigateTo({
|
|
|
url: './index',
|
|
|
})
|
|
@@ -52,7 +60,7 @@ Page({
|
|
|
}
|
|
|
}).catch(_ => {
|
|
|
console.log(_)
|
|
|
- app.showToast ('活动不存在');
|
|
|
+ this.popMessage('活动不存在');
|
|
|
wx.navigateTo({
|
|
|
url: './index',
|
|
|
})
|
|
@@ -103,8 +111,14 @@ Page({
|
|
|
beginTime: activity.beginTime,
|
|
|
endTime: activity.endTime,
|
|
|
timeType: activity.timeType,
|
|
|
+ dayBeginTime: activity.dayBeginTime,
|
|
|
+ dayEndTime: activity.dayEndTime,
|
|
|
giftList: this.data.giftList,
|
|
|
- ruleDesc: activity.ruleDesc || ''
|
|
|
+ ruleDesc: activity.ruleDesc || '',
|
|
|
+ forbidTurn: activity.status != 2,
|
|
|
+ opptyInitialVal: activity.opptyInitialVal || 0,
|
|
|
+ opptyMaxVal: activity.opptyMaxVal || 0,
|
|
|
+ status: activity.status
|
|
|
})
|
|
|
},
|
|
|
|
|
@@ -116,27 +130,101 @@ Page({
|
|
|
if (this.isLock || !this.data.isLogin) {
|
|
|
return
|
|
|
}
|
|
|
- this.isLock = false
|
|
|
+ // 预处理
|
|
|
+ if (this.data.remainNum <= 0) {
|
|
|
+ if (this.data.noHitResult != null ) {
|
|
|
+ // 可以通过分享获取
|
|
|
+ if (this.data.noHitResult.canShareGetTimes == 1) {
|
|
|
+ this.popNeedShareDlg()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (this.isSniffAgain) {
|
|
|
+ this.popMessage('抱歉,您的抽奖机会已用完');
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.isLock = true
|
|
|
+ this.isSniffAgain = false
|
|
|
+ let remainNum = this.data.remainNum - 1
|
|
|
+ if (remainNum < 0) {
|
|
|
+ this.isSniffAgain = true
|
|
|
+ remainNum = 0
|
|
|
+ }
|
|
|
+ this.setData({ remainNum })
|
|
|
// 开始动画,开始是快阶段
|
|
|
this.data.duration = 80
|
|
|
this.data.hitPos = -1
|
|
|
this.data.hitTime = 0
|
|
|
- this.data.isExcetion = false
|
|
|
- this.startTurnAnimationFast();
|
|
|
+ this.data.isHit = null;
|
|
|
+ this.data.stopNotify = false
|
|
|
+ this.startTurnAnimationFast()
|
|
|
// 开始调用后台
|
|
|
-
|
|
|
setTimeout(_ => {
|
|
|
this.data.hitTime = new Date().getTime()
|
|
|
- this.data.hitPos = 4
|
|
|
- //this.requestDrawPrize()
|
|
|
+ this.requestDrawPrize()
|
|
|
}, 2000)
|
|
|
},
|
|
|
-
|
|
|
- requestDrawPrize() {
|
|
|
+
|
|
|
+ requestDrawPrize: function() {
|
|
|
LuckDraw.drawPrize(this.data.activityId, getMobileCache()).then(res => {
|
|
|
- console.log(res)
|
|
|
+ if (res.code == 200) {
|
|
|
+ this.hitPrizeMapData(res.data)
|
|
|
+ }
|
|
|
}).catch(_ => {
|
|
|
- this.data.isExcetion = true
|
|
|
+ this.data.stopNotify = true
|
|
|
+ console.log(_)
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ hitPrizeMapData: function(hitData) {
|
|
|
+ if (hitData.isHit == 1) {
|
|
|
+ // 中奖
|
|
|
+ const hitResult = hitData.hitResult;
|
|
|
+ this.data.giftList.forEach((v, i) => {
|
|
|
+ if (v.goodsId == hitResult.goodsId) {
|
|
|
+ // 设置中奖
|
|
|
+ this.data.hitPos = i
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ hitResult,
|
|
|
+ isHit: 1,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // 未中奖
|
|
|
+ const noHitResult = hitData.noHitResult || {};
|
|
|
+ if (noHitResult.canShareGetTimes == 1) {
|
|
|
+ // 分享可获取抽奖机会,停止转动
|
|
|
+ this.data.stopNotify = true
|
|
|
+ this.setData({
|
|
|
+ noHitResult,
|
|
|
+ isHit: 0
|
|
|
+ })
|
|
|
+ this.isLock = false
|
|
|
+ this.popNeedShareDlg()
|
|
|
+ } else {
|
|
|
+ this.data.giftList.forEach((v, i) => {
|
|
|
+ if (v.goodsId == noHitResult.goodsId) {
|
|
|
+ // 设置中奖
|
|
|
+ this.data.hitPos = i
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ noHitResult,
|
|
|
+ isHit: 0,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 重刷次数
|
|
|
+ this.getDrawTimes()
|
|
|
+ },
|
|
|
+
|
|
|
+ popNeedShareDlg: function() {
|
|
|
+ this.setData({
|
|
|
+ showNeedShareDlg: true
|
|
|
})
|
|
|
},
|
|
|
|
|
@@ -179,7 +267,7 @@ Page({
|
|
|
},
|
|
|
|
|
|
startTurnAnimationFast: function() {
|
|
|
- if (this.data.isExcetion) {
|
|
|
+ if (this.data.stopNotify) {
|
|
|
// 异常停止转动
|
|
|
this.setActiveGift(-1)
|
|
|
this.timer&&clearTimeout(this.timer)
|
|
@@ -230,9 +318,16 @@ Page({
|
|
|
|
|
|
dealHitResult: function() {
|
|
|
setTimeout(_ => {
|
|
|
- this.setData({
|
|
|
- showHitPrizeDlg: true
|
|
|
- })
|
|
|
+ if (this.data.isHit == 1) {
|
|
|
+ this.setData({
|
|
|
+ showHitPrizeDlg: true
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.setData({
|
|
|
+ showNoHitPrizeDlg: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ this.isLock = false
|
|
|
}, 300)
|
|
|
},
|
|
|
|
|
@@ -294,7 +389,8 @@ Page({
|
|
|
closeDlg: function() {
|
|
|
this.setData({
|
|
|
showHitPrizeDlg: false,
|
|
|
- showNoHitPrizeDlg: false
|
|
|
+ showNoHitPrizeDlg: false,
|
|
|
+ showNeedShareDlg: false,
|
|
|
})
|
|
|
}
|
|
|
})
|