bobo 3 vuotta sitten
vanhempi
commit
9b14c9f2e0

+ 115 - 19
pages/luckDraw/detail.js

@@ -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,
         })
     }
 })

+ 26 - 6
pages/luckDraw/detail.wxml

@@ -61,9 +61,7 @@
         <view/>
     </view>
     <view class="rule-des">
-        <view>1. 每人每天可以抽奖100次</view>
-        <view>2. 当次数用完了, 可分享给好友获得额外xx次抽奖机会 </view>
-        <view>3. 抽奖奖品会再XXXX里兑换XXX</view>
+        <text>{{ruleDesc}}</text>
     </view>
 
     <!-- 中奖名单 -->
@@ -103,11 +101,12 @@
         <view class="prize-subtitle">抽到神秘大奖一份~</view>
         <view class="prize-figure">
            <!-- 图片封面 -->
-           <image src="/images/luck-draw/gift.png" />
+           <image wx:if="{{hitResult.goodsBigImage}}" src="{{hitResult.goodsBigImage}}" />
+           <image src="/images/luck-draw/gift.png" wx:else />
         </view>
-        <view class="prize-tip">某某优惠券</view>
+        <view class="prize-tip">{{hitResult.goodsName}}</view>
         <view class="btns">
-            <view class="_btn _confirm">确定</view>
+            <view class="_btn _confirm" catchtap="closeDlg">确定</view>
             <view class="_btn _exchange">去兑换</view>
         </view>
         <image class="_bg" src="/images/luck-draw/hitdlgbg.png" />
@@ -126,6 +125,27 @@
         <view class="prize-figure">
            <image src="/images/luck-draw/nogift.png" />
         </view>
+        <view class="prize-tip">点击确认继续抽奖!</view>
+        <view class="btns">
+            <view class="_btn _share" catchtap="closeDlg">确认</view>
+        </view>
+        <image class="_bg" src="/images/luck-draw/hitdlgbg.png" />
+    </view>
+    <view class="_layer" catchtap="closeDlg" />
+</view>
+
+
+<!-- 需要分享显示 -->
+<view class="dlg" wx:if="{{showNeedShareDlg}}">
+    <view class="prize-body">
+        <view class="prize-title">
+            再接再厉!
+            <image src="/images/luck-draw/hbar.png" />
+        </view>
+        <view class="prize-subtitle">离奖品只差一个手势~</view>
+        <view class="prize-figure">
+           <image src="/images/luck-draw/nogift.png" />
+        </view>
         <view class="prize-tip">分享可获得更多抽奖机会!</view>
         <view class="btns">
             <view class="_btn _share">分享</view>

+ 1 - 1
pages/luckDraw/index.js

@@ -98,7 +98,7 @@ Page({
             if (v.timeType == 1 || beginTime == null) {
                 beginTime = "2021.11.01"
             }
-            if (v.timeType == 2 || endTime == null) {
+            if (v.timeType == 1 || endTime == null) {
                 endTime = "2031.11.01"
             }
             v.beginTime = parseTime(beginTime, "{y}.{m}.{d}")

+ 1 - 1
pages/luckDraw/index.wxss

@@ -75,7 +75,7 @@ page {
     color: #BD1925;
 }
 
-._status1 {
+._status1, ._status4, ._status5 {
     border: 1rpx solid #EE7C00;
     background: #FFE6CB;
     color: #EE7C00;

+ 1 - 1
project.private.config.json

@@ -39,7 +39,7 @@
                 {
                     "name": "pages/luckDraw/detail",
                     "pathName": "pages/luckDraw/detail",
-                    "query": "id=7",
+                    "query": "id=5",
                     "scene": null
                 },
                 {

+ 1 - 0
utils/request.js

@@ -114,6 +114,7 @@ class request {
                   } else {
                     wx.showToast({
                         title: res?.data?.msg,
+                        icon: "none"
                     })
                       //其它错误,提示用户错误信息
                       if (this._errorHandler != null) {