绿满眶商城微信小程序-uniapp
zxl
2025-06-04 b62daf4aaca5fcb8eea7bfd4149dbb92b10f50de
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<template>
  <view class="activity-container">
    <u-navbar :is-back="true" title="我的活动" title-color="#333" back-icon-color="#333"></u-navbar>
    
    <!-- 顶部 Tab 导航 -->
    <view class="tab-nav">
      <view 
        v-for="(tab, index) in tabs" 
        :key="index" 
        class="tab-item"
        :class="{active: currentTab === index}"
        @click="switchTab(index)"
      >
        {{tab}}
        <view class="tab-indicator" v-if="currentTab === index"></view>
      </view>
    </view>
    
    <!-- 活动列表 -->
    <view class="activity-list">
      <!-- 已报名活动 -->
      <view v-if="currentTab === 0">
        <view v-if="signedActivities.length > 0">
          <view 
            v-for="(item, idx) in signedActivities" 
            :key="idx" 
            class="activity-item card"
          >
            <!-- 封面区域 -->
            <view class="cover-container">
              <block v-if="item.coverType === '图片' || item.coverType === '视频'">
                <image :src="getPreviewUrl(item.cover)" mode="aspectFill" class="activity-cover" />
              </block>
              <block v-if="item.coverType === '文字'">
                <view class="activity-cover text-cover">{{ item.cover }}</view>
              </block>
            </view>
    
            <!-- 活动信息 -->
            <view class="activity-info">
              <view class="info-header">
                <view class="activity-title">{{ item.activityName }}</view>
                <view class="activity-status signed">已报名</view>
              </view>
              
              <view class="activity-meta">
                <view class="meta-item">
                  <u-icon name="calendar" size="16" color="#999"></u-icon>
                  <text class="activity-time">{{ item.startTime }} - {{ item.endTime }}</text>
                </view>
                <view class="meta-item">
                  <u-icon name="map" size="16" color="#999"></u-icon>
                  <text class="activity-location">{{ item.activityLocation || '待定' }}</text>
                </view>
              </view>
              
              <view class="action-container">
                <button 
                  class="cancel-btn" 
                  @click="handleActivityCancel(item.id)"
                  hover-class="cancel-btn-hover"
                >
                  取消报名
                </button>
              </view>
            </view>
          </view>
        </view>
        <view v-else class="empty-state">
    
          <text class="empty-text">暂无已报名活动</text>
        </view>
      </view>
      
      <!-- 已结束活动 -->
      <view v-if="currentTab === 1">
        <view v-if="endedActivities.length > 0">
          <view 
            v-for="(item, idx) in endedActivities" 
            :key="idx" 
            class="activity-item card"
          >
            <view class="cover-container">
              <block v-if="item.coverType === '图片' || item.coverType === '视频'">
                <image :src="getPreviewUrl(item.cover)" mode="aspectFill" class="activity-cover" />
              </block>
              <block v-if="item.coverType === '文字'">
                <view class="activity-cover text-cover">{{ item.cover }}</view>
              </block>
            </view>
                  
            <!-- 活动信息 -->
            <view class="activity-info">
              <view class="info-header">
                <view class="activity-title">{{ item.activityName }}</view>
                <view class="activity-status ended">已结束</view>
              </view>
              
              <view class="activity-meta">
                <view class="meta-item">
                  <u-icon name="calendar" size="16" color="#999"></u-icon>
                  <text class="activity-time">{{ item.startTime }} - {{ item.endTime }}</text>
                </view>
                <view class="meta-item">
                  <u-icon name="map" size="16" color="#999"></u-icon>
                  <text class="activity-location">{{ item.activityLocation || '待定' }}</text>
                </view>
              </view>
            </view>
          </view>
        </view>
        <view v-else class="empty-state">
        
          <text class="empty-text">暂无已结束活动</text>
        </view>
      </view>
      
      <!-- 已取消活动 -->
      <view v-if="currentTab === 2">
        <view v-if="canceledActivities.length > 0">
          <view 
            v-for="(item, idx) in canceledActivities" 
            :key="idx" 
            class="activity-item card"
          >
            <view class="cover-container">
              <block v-if="item.coverType === '图片' || item.coverType === '视频'">
                <image :src="getPreviewUrl(item.cover)" mode="aspectFill" class="activity-cover" />
              </block>
              <block v-if="item.coverType === '文字'">
                <view class="activity-cover text-cover">{{ item.cover }}</view>
              </block>
            </view>
                  
            <!-- 活动信息 -->
            <view class="activity-info">
              <view class="info-header">
                <view class="activity-title">{{ item.activityName }}</view>
                <view class="activity-status canceled">已取消</view>
              </view>
              
              <view class="activity-meta">
                <view class="meta-item">
                  <u-icon name="calendar" size="16" color="#999"></u-icon>
                  <text class="activity-time">{{ item.startTime }} - {{ item.endTime }}</text>
                </view>
                <view class="meta-item">
                  <u-icon name="map" size="16" color="#999"></u-icon>
                  <text class="activity-location">{{ item.activityLocation || '待定' }}</text>
                </view>
              </view>
            </view>
          </view>
        </view>
        <view v-else class="empty-state">
          <text class="empty-text">暂无已取消活动</text>
        </view>
      </view>
    </view>
  </view>
</template>
 
<script>
import {getMyActivityList,collectCancel,activityCancel} from '@/api/activity.js'
import {getPreviewUrl} from '@/api/common.js'
export default {
  data() {
    return {
      currentTab: 0, // 当前选中的tab索引
      tabs: ['已报名', '已结束', '已取消'],
      signedActivities: [], // 已报名列表
      endedActivities: [],// 已结束列表
      canceledActivities: [],//已取消列表
      query:{
        status:'',
        cancel:false,
      },      
    }
  },
  onLoad(){
    this.currentTab = 0;
    this.getMyActivityList(this.currentTab);
  },
  methods: {
    handleActivityCancel(activityId){
      activityCancel(activityId).then(res =>{
        if(res.statusCode == 200){
          uni.showToast({
            title: res.data.msg,
            icon: 'success',
            mask: true,
            duration: 2000,
            success: () => {
              setTimeout(() => {
                this.getMyActivityList(this.currentTab);
              }, 2000);
            }
          });
        }
      })
    },
    getPreviewUrl(params){
      return getPreviewUrl(params);
    },
    switchTab(index) {
      if (this.currentTab !== index) {
        this.currentTab = index;
        this.getMyActivityList(index)
      }
    },
    getMyActivityList(index){
      uni.showLoading({
        title: '加载中'
      });
      if(index === 0){
        this.query.cancel = false;
        getMyActivityList(this.query).then(res =>{
          uni.hideLoading();
          if(res.statusCode === 200){
            this.signedActivities = res.data.data
          }
        })
      }else if(index === 1){
        this.query.status = '已结束';
        this.query.cancel = false;
        getMyActivityList(this.query).then(res =>{
          uni.hideLoading();
          if(res.statusCode === 200){
            this.endedActivities = res.data.data
          }
        })
      }else if(index === 2){
        this.query.cancel = true;
        getMyActivityList(this.query).then(res =>{
          uni.hideLoading();
          if(res.statusCode === 200){
            this.canceledActivities = res.data.data
          }
        })
      }
      this.query.status = '';
      this.query.cancel=  false;
    },
  }
}
</script>
 
<style lang="scss">
.activity-container {
  padding: 0;
  background-color: #f7f8fa;
  min-height: 100vh;
}
 
/* Tab 导航样式 */
.tab-nav {
  display: flex;
  background-color: #fff;
  margin-bottom: 16rpx;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
}
 
.tab-item {
  flex: 1;
  text-align: center;
  padding: 28rpx 0;
  font-size: 30rpx;
  color: #666;
  position: relative;
  transition: all 0.3s ease;
  
  &.active {
    color: #2979ff;
    font-weight: 500;
  }
  
  .tab-indicator {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 80rpx;
    height: 6rpx;
    background-color: #2979ff;
    border-radius: 3rpx;
    animation: scaleIn 0.3s ease;
  }
}
 
@keyframes scaleIn {
  from { transform: translateX(-50%) scaleX(0); }
  to { transform: translateX(-50%) scaleX(1); }
}
 
/* 活动列表样式 */
.activity-list {
  padding: 20rpx 24rpx;
}
 
.card {
  background: #fff;
  border-radius: 16rpx;
  margin-bottom: 24rpx;
  overflow: hidden;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  
  &:active {
    transform: scale(0.98);
    box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  }
}
 
.activity-item {
  display: flex;
  padding: 24rpx;
}
 
.cover-container {
  position: relative;
  width: 200rpx;
  height: 200rpx;
  border-radius: 12rpx;
  overflow: hidden;
  margin-right: 24rpx;
  flex-shrink: 0;
}
 
.activity-cover {
  width: 100%;
  height: 100%;
  border-radius: 12rpx;
}
 
.text-cover {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
  color: #fff;
  font-size: 28rpx;
  padding: 16rpx;
  line-height: 1.4;
}
 
.activity-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}
 
.info-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16rpx;
}
 
.activity-title {
  flex: 1;
  font-size: 32rpx;
  color: #333;
  font-weight: 500;
  margin-right: 16rpx;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  line-height: 1.4;
}
 
.activity-meta {
  font-size: 24rpx;
  color: #999;
  margin-bottom: 16rpx;
}
 
.meta-item {
  display: flex;
  align-items: center;
  margin-bottom: 12rpx;
  
  .u-icon {
    margin-right: 8rpx;
  }
}
 
.activity-status {
  font-size: 24rpx;
  padding: 6rpx 16rpx;
  border-radius: 20rpx;
  flex-shrink: 0;
  
  &.signed {
    color: #2979ff;
    background-color: rgba(41, 121, 255, 0.1);
  }
  
  &.ended {
    color: #909399;
    background-color: rgba(144, 147, 153, 0.1);
  }
  
  &.canceled {
    color: #fa3534;
    background-color: rgba(250, 53, 52, 0.1);
  }
}
 
/* 操作按钮 */
.action-container {
  display: flex;
  justify-content: flex-end;
  margin-top: auto;
  padding-top: 16rpx;
}
 
.cancel-btn {
  background: #fef0f0;
  color: #fa3534;
  border: none;
  border-radius: 40rpx;
  padding: 0 32rpx;
  height: 64rpx;
  line-height: 64rpx;
  font-size: 26rpx;
  transition: all 0.3s ease;
  
  &::after {
    border: none;
  }
  
  &.cancel-btn-hover {
    background: #fde2e2;
    transform: scale(0.98);
  }
}
 
/* 空状态 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100rpx 0;
  text-align: center;
  
  .empty-image {
    width: 300rpx;
    height: 300rpx;
    opacity: 0.6;
    margin-bottom: 40rpx;
  }
  
  .empty-text {
    font-size: 28rpx;
    color: #999;
    margin-top: 20rpx;
  }
}
</style>