绿满眶商城微信小程序-uniapp
peng
2 天以前 2a0d988b1439a9e2d3604350fa14034191f50140
pages/prize/PrizeDetail/PrizeDetail.vue
@@ -96,7 +96,6 @@
               <button class="chance-item" open-type="share">
                  <view class="chance-icon">👥</view>
                  <text class="chance-title">分享好友</text>
                  <text class="chance-subtitle">+1次机会</text>
               </button>
               <!--                <view class="chance-item" @tap="shareToTimeline">
                  <view class="chance-icon">🌐</view>
@@ -106,17 +105,14 @@
               <view class="chance-item" @tap="watchVideo">
                  <view class="chance-icon">🎬</view>
                  <text class="chance-title">浏览视频</text>
                  <text class="chance-subtitle">+1次机会</text>
               </view>
               <view class="chance-item" @tap="browseProduct">
                  <view class="chance-icon">🛍️</view>
                  <text class="chance-title">浏览商品</text>
                  <text class="chance-subtitle">+1次机会</text>
               </view>
               <view class="chance-item " @tap="goShopping">
                  <view class="chance-icon">🛒</view>
                  <text class="chance-title">去购物</text>
                  <text class="chance-subtitle">享受购物乐趣</text>
               </view>
            </view>
@@ -148,11 +144,14 @@
</template>
<script>
   import bgConfig from '@/pages/prize/PrizeDetail/prize-bgConfig.js'
   import { getSessionId, userAction ,userShare } from "@/api/userAction.js";
   import {
      prizeInfo,
      prizeNum,
      prize,
      grantRecord
      grantRecord,
      addPrizeNum
   } from '@/api/prize.js'
   export default {
      data() {
@@ -212,7 +211,23 @@
            shareTimelineAttempt: false,
            activityCover: '',
            activityName: '',
            couponId: ''
            couponId: '',
             pageSessionNo:"",
             actionParam:{
               sessionId:'',
               actionType:"PAGE",
               joinType:"SELF",
               pageCode:"PRIZE_DETAIL",
               pageParams:"{}",
               pageStatus:"JOIN",
               pageType:"DETAIL"
            },
            shareParam:{
               pageCode:"PRIZE_DETAIL",
               shareOption:"{}",
               pageType:"DETAIL"
            },
            shareId:'',
         };
      },
      computed: {
@@ -221,7 +236,54 @@
            return [...this.originalWinners]
         }
      },
    onUnload() {
      let param = Object.assign({}, this.actionParam);
      if (this.sendOnShow)return
      param.pageStatus = "LEAVE"
      userAction(param)
    },
    onHide() {
      this.startHidenTime = Date.now()
      let   param = Object.assign({}, this.actionParam);
      this.sendOnShow = true;
      param.pageStatus = "LEAVE"
      userAction(param)
    },
      onShow() {
        getSessionId().then(res=>{
         this.pageSessionNo = res.data.data
         this.actionParam.sessionId = res.data.data
         if(this.pageSessionNo){
         let   param = Object.assign({}, this.actionParam);
            param.sessionId = this.pageSessionNo
            userAction(param)
         }
        })
        const shareId =   uni.getStorageSync("shareId");
        if(shareId){
        let param = {
           addType:"SHARE_USER_REGISTRY",
           extend:"",
        }
        let extend = {shareId:shareId}
        param.extend = JSON.stringify(extend)
        addPrizeNum(param);
        let param2 = {
           addType:"USER_STAY_TIME",
           extend:"",
        }
        addPrizeNum(param2);
        }
      },
      async onLoad(option) {
         if(option.shareId){
            this.actionParam.shareId = option.shareId;
            this.actionParam.joinType = 'SHARE'
            console.log('触发onLoad')
         }
         this.actionParam.pageParams = JSON.stringify(option)
         const pages = getCurrentPages()
         console.log('================pages ', pages)
         this.activityId = option.id
@@ -266,17 +328,38 @@
         // this.startAutoScroll()
      },
      onShareAppMessage() {
         return {
        // 返回一个Promise
        return new Promise((resolve) => {
         this.shareId = '';
         this.shareParam.shareOption = JSON.stringify({
            id:this.activityId
         })
         userShare(this.shareParam).then(res => {
           this.shareId = res.data.data;
           console.log('------------------1》', this.shareId);
           // 当获取到shareId后,再resolve分享配置
           resolve({
            title: this.activityName,
            path: '/pages/prize/PrizeDetail/PrizeDetail?id=' + this.activityId,
            path: '/pages/prize/PrizeDetail/PrizeDetail?id=' + this.activityId + '&shareId=' + this.shareId,
            imageUrl: this.activityCover,
            success(e) {
               console.log("分享成功", e)
              console.log("分享成功", e);
            },
            fail(e) {
               console.log('分享失败', e)
              console.log('分享失败', e);
            }
         }
           });
         }).catch(err => {
           // 处理错误情况,例如使用默认参数
           console.error('获取分享ID失败', err);
           resolve({
            title: this.activityName,
            path: '/pages/prize/PrizeDetail/PrizeDetail?id=' + this.activityId,
            imageUrl: this.activityCover
           });
         });
        });
      },
      beforeDestroy() {
         this.stopAutoScroll()