Selaa lähdekoodia

优化小程序打卡逻辑代码

yanj 1 kuukausi sitten
vanhempi
commit
bc0ef1a1d5
4 muutettua tiedostoa jossa 139 lisäystä ja 104 poistoa
  1. 1 1
      api/checkIn.js
  2. 19 7
      pages/checkIn/checkInRoute.vue
  3. 110 95
      pages/user/award.vue
  4. 9 1
      pages/user/index.vue

+ 1 - 1
api/checkIn.js

@@ -4,7 +4,7 @@ export const getRouteList = get('/api/activity/route/list')
 export const getActivityInfo = get('/api/activity/info')
 export const qrcodeDecode =  post('/api/activity/qrcode/decode')
 
-export const giftList = get('/api/activity/gift/list')
+export const getGiftList = get('/api/activity/gift/list')
 export const checkInCount = get('/api/activity/route/checkin-count')
 export const claim = post('/api/activity/gift/claim')
 export const receiptNote = post('/api/activity/gift/receipt-note')

+ 19 - 7
pages/checkIn/checkInRoute.vue

@@ -1,7 +1,8 @@
 <template>
   <page-layout>
     <nav-bar title="逛展打卡路线" @init="onInitNavbar"></nav-bar>
-    <scroll-view id="scrollContainer" scroll-with-animation="true" :scroll-top="scroll_top" :scroll-y="true" style="height: 100vh" :scroll-into-view="scrollIntoViewId">
+    <scroll-view id="scrollContainer" scroll-with-animation="true" :scroll-top="scroll_top" :scroll-y="true"
+                 style="height: 100vh" :scroll-into-view="scrollIntoViewId">
       <view class="outter">
         <view class="body">
           <view class="theme-title">
@@ -16,7 +17,7 @@
             </view>
             <view class="page">
               <view v-show="current_page" class="page-item">
-                 <mp-html  :content="routeInfoData.description"></mp-html>
+                <mp-html :content="routeInfoData.description"></mp-html>
               </view>
               <view v-show="!current_page" class="page-item">
                 <view style="margin-bottom: 24rpx;">2025慕尼黑上海电子展展会现场将设有9条热门路线。观众可参与打卡调整。
@@ -61,7 +62,9 @@
                   </view>
                 </view>
                 <view class="progress">
-                  <view class="text" v-if="getProcess(route.exhibitors,true)">打卡已完成{{ getProcess(route.exhibitors, false) }}</view>
+                  <view class="text" v-if="getProcess(route.exhibitors,true)">
+                    打卡已完成{{ getProcess(route.exhibitors, false) }}
+                  </view>
                   <view class="text disable_text" v-else>未开始{{ getProcess(route.exhibitors, false) }}</view>
                   <view class="inner">
                     <view :style="{width:getProcess(route.exhibitors,true)*100+'%'}" class="inner-process">
@@ -151,6 +154,7 @@ export default {
       current_page: true,
       current_unfold: -1,
       scroll_top: 0,
+      is_receipts: null,
       routeInfoData: []
     };
   },
@@ -227,15 +231,22 @@ export default {
       return {a: a, t: t}
     }
     ,
-    scanCodeEvent(route, r_index, e_index,exhibit) {
+    scanCodeEvent(route, r_index, e_index, exhibit) {
       if (exhibit.checkin_status === 1) {
         return false
       }
+      if (this.is_receipts > 0) {
+        Dialog.alert({
+          message: '已经确认领取奖品,不能继续打卡',
+        }).then(() => {
+        });
+        return false
+      }
       let that = this
       wx.scanCode({
         onlyFromCamera: true,
         success(res) {
-          console.log(res,'qrcode_res')
+          console.log(res, 'qrcode_res')
           let scene = res.path.split('scene=')
           const decoded = decodeURIComponent(scene[1])
               .replace(/\%/g, '%25'); // 防止二次解码丢失%
@@ -269,6 +280,7 @@ export default {
     ,
     getRouteListEvent(callback) {
       getRouteList().then(res => {
+        this.is_receipts = res.data.is_receipts
         this.routeInfoData = res.data
         if (callback) {
           callback()
@@ -327,13 +339,13 @@ export default {
   },
 
   onLoad(option) {
-    console.log(option,'option')
+    console.log(option, 'option')
     if (!store.getters.user) {
       this.navigateTo('/pages/user/login?redirect=' + encodeURIComponent('/pages/checkIn/checkInRoute?scene=' + option.scene))
       return false
     }
     this.scene = decodeURIComponent(option.scene || '');
-    console.log(this.scene,'option_this.scene')
+    console.log(this.scene, 'option_this.scene')
 
     this.initSceneEvent()
     if (option.rule === 'true')

+ 110 - 95
pages/user/award.vue

@@ -34,9 +34,7 @@
             </view>
             <view class="award-list">
               <view v-for="(item,index) in giftList" :key="item.id" class="award-list-item">
-                <image
-                    src="https://oss.productronicachina.com.cn/resources/common/up/0000001002/20250224/67bbd36f30962.png"
-                    alt="image" mode="widthFix"></image>
+                <image :src="item.picture_url" alt="image" mode="widthFix"></image>
                 <view class="award-info">
                   <view class="award-info-title">
                     {{ item.name }}
@@ -49,8 +47,8 @@
                   <mp-html class="award-info-desc" :content="item.description"></mp-html>
                 </view>
                 <view class="award-option">
-                  <view @click="getGift(item)" :class="['award-option-btn',getClass(item)]">
-                    {{ getText(item) }}
+                  <view @click="getGift(item,index)" :class="['award-option-btn',getClass(item,index)]">
+                    {{ getText(item, index) }}
                   </view>
                 </view>
               </view>
@@ -126,8 +124,7 @@ import UScrollView from "@/components/common/u-scroll-view";
 import NewsItem from "@/pages/news/components/news-item";
 import DisclaimerText from "@/components/disclaimer-text";
 import floatButton from "@/components/layout/float-button";
-import VanDialog from "@/wxcomponents/vant/dialog/dialog.js";
-import {giftList, checkInCount, claim, receiptNote, getActivityInfo, getRouteList} from "@/api/checkIn";
+import {checkInCount, claim, receiptNote, getActivityInfo, getRouteList, getGiftList} from "@/api/checkIn";
 
 export default {
   components: {
@@ -141,6 +138,7 @@ export default {
   },
   data() {
     return {
+      activeIndex: null,
       awardProgressValue: '0%',
       giftList: [],
       routes: [],
@@ -150,7 +148,9 @@ export default {
       show_qr: false,
       qr_code: '',
       check_finish: false,
-      current_gift: {},
+      current_gift: {
+
+      },
       timer: null,
       rule: '',
       rule_title: '',
@@ -163,8 +163,7 @@ export default {
     };
   },
   mounted() {
-    this.getGiftList()
-    this.getCheckinCount()
+    this.getGiftListEvent()
     this.getActiveInfo()
     this.getRouteListInfo()
   },
@@ -172,32 +171,38 @@ export default {
     clearTimeout(this.timer)
   },
   computed: {
-    getProcess(){
-    		  let subList = []
-    		  for (var i = this.giftList.length-1; i > 0; i--) {
-    		  	subList.unshift(this.giftList[i].route_count - this.giftList[i-1].route_count)
-    		  }
-    		  subList.unshift(this.giftList[0].route_count)
-
-    		  let process = 0
-    		  let count = this.checked
-    		  let per_process = 100/this.giftList.length
-    		  subList.forEach(item => {
-    		  	if(count>=item){
-    				count -= item
-    				process += per_process
-    			}else{
-    				process += per_process*(count/item)
-    				count = 0
-    			}
-    		  })
-    		  return process+'%'
+    getProcess() {
+      if (!(this.giftList && this.giftList.length > 0)) {
+        return '0%'
+      }
+      let subList = []
+      for (var i = this.giftList.length - 1; i > 0; i--) {
+        subList.unshift(this.giftList[i].route_count - this.giftList[i - 1].route_count)
+      }
+      subList.unshift(this.giftList[0].route_count)
+
+      let process = 0
+      let count = this.checked
+      let per_process = 100 / this.giftList.length
+      subList.forEach(item => {
+        if (count >= item) {
+          count -= item
+          process += per_process
+        } else {
+          process += per_process * (count / item)
+          count = 0
+        }
+      })
+      return process + '%'
     },
   },
   methods: {
-    getRouteListInfo() {
+    getRouteListInfo(callback) {
       getRouteList().then(res => {
         this.is_receipts = res.data.is_receipts
+        if (callback) {
+          callback()
+        }
       })
     },
     getActiveInfo() {
@@ -206,18 +211,27 @@ export default {
         this.rule_title = res.data.gifts_rules_name
       })
     },
-    getGiftList() {
-      giftList().then(res => {
-		  console.log(res)
+    getGiftListEvent() {
+      getGiftList().then(res => {
         this.giftList = res.data;
+        this.getCheckinCount()
       })
     },
-    getCheckinCount() {
+    getCheckinCount(callback) {
       checkInCount().then(res => {
-		  console.log(res)
         this.routes = res.data.routes
         this.route_count = res.data.route_count
         this.checked = res.data.route_checkin_count
+        console.log(this.checked, 'this.checked')
+        console.log(this.giftList)
+        this.giftList.forEach((item, index) => {
+          if (this.checked >= item.route_count) {
+            this.activeIndex = index
+          }
+        })
+        if (callback) {
+          callback()
+        }
       })
     },
     gotoCheck() {
@@ -229,56 +243,53 @@ export default {
       this.show_qr = false;
       clearTimeout(this.timer)
     },
-    getGift(item) {
-      if (item.route_count > this.checked) {
-        uni.showToast({
-          title: '不可领取',
-          icon: 'none'
-        })
-        return
-      }
-      if (this.is_receipts) {
-        this.current_gift = item
-        claim({
-          gift_id: item.id,
-        }).then(res => {
-          if (item.route_count === 9) {
-            this.pop_up = true
-          } else {
-            this.qr_code = res.data.qrcode_url
-            this.show_qr = true
-            this.checkGiftState()
-          }
-        })
-      } else {
-        uni.showModal({
-          title: '确定领取该奖品吗?',
-          content: '领取该礼品后将无法再领取其它礼品',
-          success: (res) => {
-            if (res.confirm) {
-              this.current_gift = item
-              console.log(item)
-              claim({
-                gift_id: item.id,
-              }).then(res => {
-                console.log(res,'rrrrrrrrr')
-                if(res.code === 0) {
-                  if (item.route_count === 9) {
-                    this.pop_up = true
-                  } else {
-                    this.qr_code = res.data.qrcode_url
-                    this.show_qr = true
-                    this.checkGiftState()
-                  }
-                }
-              })
+    claimDataEvent() {
+      //生成二维码方法
+      claim({
+        gift_id: this.current_gift.id,
+      }).then(res => {
+        if (res.code === 0) {
+          this.qr_code = res.data.qrcode_url
+          this.current_gift.form_id = res.data.id
+          //展示二维码
+          this.show_qr = true
+          this.checkGiftState(() => {
+            if (this.current_gift.route_count === 9) {
+              //轮询确认核销后,展示抽奖环节
+              this.pop_up = true
             }
-          }
-        })
+          })
+        }
+      })
+    },
+    getGift(item, index) {
+      //获取当前产品信息
+      if (item.is_receipts > 0 || this.activeIndex !== index) {
+        return false
       }
+      this.current_gift = item
+      this.getRouteListInfo(() => {
+        //获取当前是否生成过奖品二维码 is_receipts
+        if (this.is_receipts > 0) {
+          //获取二维码
+          this.claimDataEvent()
+        } else {
+          //确认是否领取奖品
+          uni.showModal({
+            title: '确定领取该奖品吗?',
+            content: '领取该礼品后将无法再领取其它礼品',
+            success: (res) => {
+              if (res.confirm) {
+                //获取二维码
+                this.claimDataEvent()
+              }
+            }
+          })
+        }
+      })
     },
-    checkGiftState() {
-      giftList().then(res => {
+    checkGiftState(callback) {
+      getGiftList().then(res => {
         this.giftList = res.data;
         this.giftList.forEach(item => {
           if (item.id === this.current_gift.id) {
@@ -286,29 +297,33 @@ export default {
               console.log('轮询已核销')
               clearTimeout(this.timer)
               this.checkAnimation()
+              if (callback) {
+                callback()
+              }
             } else {
               console.log('轮询未核销')
               this.timer = setTimeout(() => {
-                this.checkGiftState()
+                this.checkGiftState(callback)
               }, 1000)
             }
           }
         })
       })
     },
-    getClass(item) {
+    getClass(item, index) {
       if (item.is_receipts)
         return 'cheked'
-      if (item.route_count > this.checked)
+      if (this.activeIndex !== index)
         return 'disable'
     },
-    getText(item) {
+    getText(item, index) {
       if (item.is_receipts)
         return '已领取奖品'
-      if (item.route_count > this.checked)
-        return '不可领取'
-      if (item.route_count <= this.checked)
+      if (this.activeIndex === index) {
         return '立即领取'
+      } else {
+        return '不可领取'
+      }
     },
     getNow() {
       if (this.verify_note.company_name == '' || this.verify_note.verify_name == '' || this.verify_note.verify_phone == '') {
@@ -318,15 +333,15 @@ export default {
         })
       } else {
         receiptNote({
-          id: this.current_gift.id,
+          id: this.current_gift.form_id,
           verify_note: this.verify_note
         }).then(res => {
           uni.showToast({
-            title: '抽奖成功',
+            title: '提交抽奖信息成功',
             icon: 'none'
           })
           this.pop_up = false
-          this.getGiftList()
+          this.getGiftListEvent()
           this.getCheckinCount()
         })
 
@@ -686,11 +701,11 @@ export default {
           flex-direction: column;
           align-items: center;
           top: -12rpx;
-		  transform: translateX(-50%);
+          transform: translateX(-50%);
 
           & > text {
             margin-top: 12rpx;
-			white-space: nowrap;
+            white-space: nowrap;
             font-size: $fontSize1;
           }
 

+ 9 - 1
pages/user/index.vue

@@ -54,7 +54,7 @@
             <text class="user-item-text">我的奖品</text>
             <view class="iconfont icon-Left-1"></view>
           </view>
-          <view class="user-item" @click="scanCodeEvent()">
+          <view class="user-item" @click="scanCodeEvent()" v-if="is_super">
             <view class="iconfont icon-saoyisao_1"></view>
             <text class="user-item-text">奖品核销</text>
             <view class="iconfont icon-Left-1"></view>
@@ -148,6 +148,14 @@ export default {
       } else {
         return ''
       }
+    },
+    is_super() {
+      const user = this.$store.getters.user
+      if (user) {
+        return user.is_super === 2
+      } else {
+        return ''
+      }
     }
   },
   data() {