绿满眶商城微信小程序-uniapp
peng
1 天以前 89efee9a2e20fc04b4537d859917b47cf68a814c
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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<template>
    <view class="coupon-center">
        <div class="swiper-box">
            <div class="swiper-item">
                <div class="scroll-v" enableBackToTop="true" scroll-y>
                    <!-- 空状态优化 -->
                    <u-empty 
                        mode="coupon" 
                        icon="http://cdn.uviewui.com/uview/empty/coupon.png"
                        style='margin-top: 30%;' 
                        text="暂无优惠券" 
                        v-if="whetherEmpty"
                    >
                        <view class="empty-tip">快去领取更多优惠吧~</view>
                    </u-empty>
                    
                    <!-- 优惠券列表 -->
                    <view class="coupon-list" v-else>
                        <view 
                            class="coupon-item" 
                            v-for="(item, index) in couponList" 
                            :key="index"
                            :class="{ 
                                'coupon-used': item.claimStatus === 'CLAIMED',
                                'coupon-expired': item.status === 'EXPIRED'
                            }"
                            :data-item="JSON.stringify(item)"
                        >
                            <!-- 左侧优惠券主体 -->
                            <view class="left">
                                <!-- 波浪分隔线 -->
                                <view class="wave-line">
                                    <view class="wave" v-for="(w, i) in 12" :key="i"></view>
                                </view>
                                
                                <!-- 优惠券信息 -->
                                <view class="message">
                                    <view class="coupon-name">{{ item.skuName }}</view>
                                    <view class="coupon-no">券号: {{ item.couponNo }}</view>
                                    <view class="order-id" v-if="item.orderId">订单: {{ item.orderId }}</view>
 
                                </view>
                                
                                <!-- 圆形装饰 -->
                                <view class="circle circle-top"></view>
                                <view class="circle circle-bottom"></view>
                            </view>
                            
                            <!-- 右侧状态区域 -->
                            <view class="right">
                                <view class="status-group">
                                    <view class="status-tag" 
                                      :class="{
                                        'unclaimed': item.claimStatus === 'NOT_CLAIM',
                                        'claimed': item.claimStatus === 'CLAIM'
                                      }">
                                      {{ item.claimStatus === 'NOT_CLAIM' ? '未领取' : '已领取' }}
                                    </view>
                                    
                                    <view class="status-tag" 
                                      :class="{
                                        'unshared': item.shareStatus === 'NOT_SHARE',
                                        'shared': item.shareStatus === 'SHARED'
                                      }">
                                      {{ item.shareStatus === 'NOT_SHARE' ? '未分享' : '已分享' }}
                                    </view>
                                </view>
                            </view>
                            
                            <!-- 分享按钮 -->
                            <view v-if="item.claimStatus !== 'CLAIM'" class="share-btn-container">
                                <button class="action-btn shared" open-type="share" :data-item="JSON.stringify(item)">
                                    <uni-icons class="share-icon" type="redo" size="20" color="#FFFFFF"></uni-icons>
                                </button>
                            </view>
                        </view>
                    </view>
                    
                    <!-- 加载更多提示 -->
                    <view class="load-more" v-if="couponList.length > 0">
                        <text v-if="loadStatus === 'more'">上拉加载更多</text>
                        <text v-else-if="loadStatus === 'loading'">加载中...</text>
                        <text v-else>没有更多了</text>
                    </view>
                </div>
            </div>
        </div>
    </view>
</template>
 
<script>
    import configs from '@/config/config'
    import {getPage,changShareStatus} from '@/api/couponVirtual.js'
    import storage from "@/utils/storage.js";
    // 引入uni-icons组件
    import uniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue'
    export default {
        // 注册组件
        components: {
            uniIcons
        },
        data() {
            return {
               loadStatus: "more", //下拉状态
               whetherEmpty: false, //是否为空
               couponList: [], // 优惠券列表
               params: {
                   pageNumber: 1,
                   pageSize: 10,
                orderId:'',
               },
               storeId: "", //店铺 id,
               couponData: "",
            };
        },
        onShareAppMessage(e){
            const userInfo = storage.getUserInfo();
            if(!userInfo) {
                console.log("未登录不能分享");
                return
            }
            console.log('------------------------->',e)
            const shareItem = e.target?.dataset?.item ? JSON.parse(e.target.dataset.item) : this.item;2
            changShareStatus(shareItem.id);
            return {
                title: shareItem.name,
                path: `/pages/order/claim-coupon/claim-coupon?id=${shareItem.id}`,
                imageUrl:shareItem.original
            }
        },
         onLoad(options) {
            // options 中包含 URL 传递的所有参数
            console.log("接收的 id 值:", options.sn); // 打印参数,用于调试
            
            // 将获取到的 id 存储到 data 中,方便页面使用
            this.params.orderId = options.sn;
            this.getPage()
          },
          onReachBottom() {
              this.loadMore()
          },
        methods: {
            getPage(){
                uni.showLoading({
                    title: "加载中",
                    mask: true
                });
                let submitData = {
                    ...this.params
                };
                getPage(submitData).then(res =>{
                    uni.hideLoading()
                    if(res.statusCode === 200){
                        this.couponData = res.data
                        if (this.couponData.total == 0) {
                            // 当本次请求数据为空展示空信息
                            this.whetherEmpty = true;
                        } else {
                            this.couponList.push(...this.couponData.data);
                            this.loadStatus = this.couponData.total > this.params.pageNumber * this.params.pageSize ? "more" : "noMore";
                        }
                    }
                    
                }).catch(err => {
                    uni.hideLoading()
                    uni.showToast({
                        title: '加载失败',
                        icon: 'none'
                    })
                })
                
            },
            loadMore() {
                if (this.couponData.total > this.params.pageNumber * this.params.pageSize) {
                    this.params.pageNumber++;
                    this.loadStatus = "loading";
                    this.getPage();
                } else {
                    this.loadStatus = "noMore";
                }
            },
            
        }
    }
</script>
<style>
    page {
        height: 100%;
        background-color: #f7f8fa;
    }
</style>
 
<style lang="scss" scoped>
    // 颜色变量
    $primary: #FF6B3B; // 主色调-橙色
    $primary-light: #FF8A65; // 主色调-浅橙
    $success: #4CAF50; // 成功色-绿色
    $warning: #FF9800; // 警告色-橙色
    $info: #2196F3; // 信息色-蓝色
    $gray: #9E9E9E; // 灰色
    $light-gray: #E0E0E0; // 浅灰色
    $white: #FFFFFF; // 白色
    $bg-color: #f7f8fa; // 背景色
    $text-dark: #333333; // 深色文字
    $text-light: #666666; // 浅色文字
    
    // 页面头部
    .page-header {
        padding: 30rpx 36rpx;
        background: linear-gradient(135deg, $primary, $primary-light);
        color: $white;
        box-shadow: 0 4rpx 16rpx rgba(255, 107, 59, 0.3);
        position: relative;
        z-index: 10;
        
        .title {
            font-size: 36rpx;
            font-weight: 600;
            text-align: center;
            letter-spacing: 1rpx;
        }
    }
    
    .coupon-center {
        height: 100%;
        position: relative;
        background: linear-gradient(to bottom, $primary 160rpx, $bg-color 160rpx);
        
        .swiper-box {
            position: relative;
            z-index: 5;
            
            .swiper-item {
                .scroll-v {
                    height: calc(100vh - 100rpx);
                    padding: 30rpx 24rpx 30rpx;
                }
            }
        }
        
        // 空状态提示
        .empty-tip {
            color: $gray;
            font-size: 28rpx;
            margin-top: 20rpx;
            text-align: center;
        }
        
        // 优惠券列表容器
        .coupon-list {
            display: flex;
            flex-direction: column;
            gap: 30rpx;
        }
        
        // 优惠券项
        .coupon-item {
            display: flex;
            height: 240rpx;
            border-radius: 20rpx;
            overflow: hidden;
            box-shadow: 0 6rpx 24rpx rgba(0, 0, 0, 0.08);
            background-color: $white;
            transition: all 0.3s ease;
            position: relative;
            
            &:active {
                transform: translateY(4rpx);
                box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
            }
            
            // 已使用样式
            &.coupon-used {
                .left {
                    background: linear-gradient(135deg, #E0E0E0, #BDBDBD);
                    
                    .wave-line {
                        background: linear-gradient(135deg, #E0E0E0, #BDBDBD);
                    }
                    
                    .message {
                        color: #757575;
                        
                        .coupon-desc {
                            color: #9E9E9E;
                        }
                    }
                }
                
                &::after {
                    content: "已使用";
                    position: absolute;
                    top: 30rpx;
                    right: 30rpx;
                    font-size: 24rpx;
                    color: #9E9E9E;
                    background: rgba(255, 255, 255, 0.8);
                    padding: 6rpx 16rpx;
                    border-radius: 20rpx;
                    font-weight: 500;
                }
            }
            
            // 已过期样式
            &.coupon-expired {
                .left {
                    background: linear-gradient(135deg, #BDBDBD, #9E9E9E);
                    
                    .wave-line {
                        background: linear-gradient(135deg, #BDBDBD, #9E9E9E);
                    }
                    
                    .message {
                        color: #616161;
                        
                        .coupon-desc {
                            color: #757575;
                        }
                    }
                }
                
                &::after {
                    content: "已过期";
                    position: absolute;
                    top: 30rpx;
                    right: 30rpx;
                    font-size: 24rpx;
                    color: #F5F5F5;
                    background: rgba(97, 97, 97, 0.8);
                    padding: 6rpx 16rpx;
                    border-radius: 20rpx;
                    font-weight: 500;
                }
            }
        }
        
        // 左侧区域
        .left {
            width: 440rpx;
            background: linear-gradient(135deg, $primary, $primary-light);
            position: relative;
            padding: 30rpx;
            display: flex;
            align-items: center;
            
            // 波浪分隔线
            .wave-line {
                position: absolute;
                top: 0;
                right: 0;
                height: 100%;
                width: 16rpx;
                background: linear-gradient(135deg, $primary, $primary-light);
                display: flex;
                flex-direction: column;
                justify-content: space-around;
                align-items: flex-end;
                padding: 12rpx 0;
                
                .wave {
                    width: 16rpx;
                    height: 20rpx;
                    background-color: $white;
                    border-radius: 0 12rpx 12rpx 0;
                }
            }
            
            // 信息区域
            .message {
                color: $white;
                width: 100%;
                
                .coupon-name {
                    font-size: 32rpx;
                    font-weight: 600;
                    margin-bottom: 16rpx;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    display: -webkit-box;
                    -webkit-line-clamp: 1;
                    -webkit-box-orient: vertical;
                }
                
                .coupon-no, .order-id, .valid-date {
                    font-size: 24rpx;
                    margin-bottom: 8rpx;
                    opacity: 0.9;
                }
                
                .order-id {
                    word-break: break-all;
                    white-space: normal;
                }
                
                .valid-date {
                    margin-top: 16rpx;
                    font-size: 22rpx;
                    opacity: 0.8;
                }
            }
            
            // 圆形装饰
            .circle {
                width: 32rpx;
                height: 32rpx;
                background-color: $bg-color;
                border-radius: 50%;
                position: absolute;
                right: -16rpx;
                z-index: 2;
            }
            
            .circle-top {
                top: -16rpx;
            }
            
            .circle-bottom {
                bottom: -16rpx;
            }
        }
        
        // 右侧区域
        .right {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 0 20rpx;
            background: $white;
            
            // 状态标签组
            .status-group {
                display: flex;
                flex-direction: column;
                align-items: center;
                gap: 20rpx;
                width: 100%;
                
                .status-tag {
                    font-size: 24rpx;
                    padding: 8rpx 16rpx;
                    border-radius: 20rpx;
                    text-align: center;
                    white-space: nowrap;
                    width: fit-content;
                    font-weight: 500;
                }
                
                // 状态样式
                .unclaimed {
                    background-color: rgba(255, 107, 59, 0.1);
                    color: $primary;
                    border: 1rpx solid rgba(255, 107, 59, 0.3);
                }
                
                .claimed {
                    background-color: rgba(76, 175, 80, 0.1);
                    color: $success;
                    border: 1rpx solid rgba(76, 175, 80, 0.3);
                }
                
                .unshared {
                    background-color: rgba(33, 150, 243, 0.1);
                    color: $info;
                    border: 1rpx solid rgba(33, 150, 243, 0.3);
                }
                
                .shared {
                    background-color: rgba(158, 158, 158, 0.1);
                    color: $gray;
                    border: 1rpx solid rgba(158, 158, 158, 0.3);
                }
            }
        }
        
        // 分享按钮容器
        .share-btn-container {
            position: absolute;
            top: 0rpx;
            right: 0rpx;
            z-index: 10;
        }
        
        // 操作按钮
        .action-btn {
            background: linear-gradient(135deg, $primary, $primary-light);
            width: 50rpx;
            height: 50rpx;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0 4rpx 12rpx rgba(255, 107, 59, 0.3);
            border: none;
            padding: 0;
            margin: 0;
            
            &.shared {
                background: linear-gradient(135deg, $info, #42A5F5);
                box-shadow: 0 4rpx 12rpx rgba(33, 150, 243, 0.3);
            }
            
            &.disabled {
                background: linear-gradient(135deg, #BDBDBD, #9E9E9E);
                box-shadow: 0 4rpx 12rpx rgba(158, 158, 158, 0.3);
            }
            
            .share-icon {
                width: 100%;
                height: 100%;
                display: flex;
                align-items: center;
                justify-content: center;
            }
        }
        
        // 加载更多提示
        .load-more {
            text-align: center;
            padding: 30rpx;
            color: $gray;
            font-size: 26rpx;
            background-color: $bg-color;
        }
    }
</style>