Jacob
1 天以前 e6fea61c05d96ed2e6aa1aff9e7026e48b046332
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<template>
   <view class="sideBar_task" :style="isShow?'display:block':'display:none'">
       <view class="task_title">任务({{isFinish?'1':'0'}}/1)</view>
       <view class="task_progress"><view class="task_progress_bar" :style="'width:'+(isFinish?'100':(totalTime?(1-duration/totalTime)*100:0))+'%'"></view></view>
       <view class="task_status" v-if="isFinish">任务完成</view>
       <view class="task_status" v-else>
           <block v-if="type=='view'">{{'浏览'+totalTime+'秒'}}</block>
           <block v-if="type=='share'">首次分享</block>
       </view>
   </view>
</template>
 
<script>
   import {
       finishTaskApi
   } from '@/api/api.js';
   export default {
       name:"task",
       data() {
           return {
               isFinish:false,
               type:'view',
               timer:null,
               isShow:false,
               totalTime:0,
               duration:0,
               taskInfo:{}
           };
       },
       methods:{
           show(taskInfo){
               clearInterval(this.timer);
               this.taskInfo=taskInfo;
               this.isFinish=false;
               this.type=taskInfo.type.toLowerCase();
               this.isShow=true;
               if(this.type=='view'){
                   if(taskInfo.duration){
                       this.duration=Math.ceil(taskInfo.duration);
                       this.totalTime=Math.ceil(taskInfo.duration);
                   }else{
                       this.duration=10;
                   }
               }else{
                   this.duration=0;
               }
               
               if(this.type=='view'&&this.duration){
                   this.timer=setInterval(()=>{
                       this.duration-=1;
                       console.log('--------','show task',this.duration)
                       if(this.duration<=0){
                           this.finishTask();
                       }
                   },1000)
               }
           },
           finishTask(){
               clearInterval(this.timer);
               this.isFinish=true;
               finishTaskApi({
                   taskCode:this.taskInfo.code,
                   uid:this.taskInfo.uid
               }).then((res)=>{
                   console.log('task callback',res)
               }).catch((e)=>{
                   console.log('task callback',e)
               })
           },
           hide(){
               clearInterval(this.timer);
               this.isShow=false;
           }
       },
   }
</script>
 
<style>
.sideBar_task{
   position: fixed;
   right: 10rpx;
   top: 50%;
   width: 132rpx;
   height: 157rpx;
   background: url("https://ossacmall.bluedeer.com.cn/app/static/images/task_sideIcon.png") center top/contain no-repeat;
   pointer-events: none;
}
.task_title{
       font-size: 16rpx;
       line-height: 1.25em;
       color: #000000;
       font-weight: bold;
       position: absolute;
       left: 0;
       width: 100%;
       top: 72rpx;
       text-align: center;
   }
   .task_progress{
       width: 100rpx;
       height: 14rpx;
       border-radius: 7rpx;
       position: absolute;
       left: 16rpx;
       top: 104rpx;
       background-color: #ffffff;
       box-shadow: 0 3rpx 0 0 #f5c702;
   }
   .task_progress_bar{
       border-radius: 7rpx;
       height: 100%;
       background-color: #00c864;
       overflow: hidden;
   }
   .task_status{
       font-size: 16rpx;
       line-height: 1.25em;
       color: #000000;
       position: absolute;
       left: 0;
       width: 100%;
       top: 128rpx;
       text-align: center;
       font-weight: bold;
   }
</style>