绿满眶商城微信小程序-uniapp
zxl
3 天以前 a8e2f971ecaa34570f679ec6f33c9a48cf109f82
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
<template>
    <view class="container"  @touchstart="touchStart" @touchend="touchEnd">
        <!-- 顶部海报图 -->
        <!-- 动态封面区域 -->
        <view class="cover-container">
            <!-- 图片类型 -->
            <block v-if="activityInfo.coverType === 'image'">
                <image :src="activityInfo.url" class="activity-cover" />
            </block>
            <block v-if=" activityInfo.coverType === 'video'">
                <video :src="activityInfo.url" @play="handleVideoPlay" class="activity-cover"></video>
            </block>
            <!-- 文字类型 -->
            <block v-if="activityInfo.coverType === 'text'">
                <view class="text-cover">
                    <text class="cover-text">{{ activityInfo.cover }}</text>
                </view>
            </block>
        </view>
 
        <!-- 活动基本信息 -->
        <view class="info-section">
            <text class="title">{{ activityInfo.activityName }}</text>
            <view class="meta-info">
                <view>
                    <text class="time">
                        开始时间:{{ activityInfo.startTime }}
                    </text>
 
                </view>
                <view>
                    <text class="time">
                        结束时间:{{ activityInfo.endTime }}
                    </text>
                </view>
                <view>
                    <text class="location">地点:{{ activityInfo.activityLocation || '暂无' }}</text>
                </view>
                <view>
                    <text class="location">最大人数:{{ activityInfo.limitUserNum || '暂无' }}</text>
                </view>
                <view>
                    <text class="location">活动类型:{{ activityInfo.activityType || '暂无' }}</text>
                </view>
            </view>
            <view class="tags">
                <text v-for="(tag, index) in activityInfo.tags" :key="index" class="tag">{{ tag }}</text>
            </view>
        </view>
 
 
 
        <!-- 活动详情内容 -->
        <view class="rich-text-container">
            <rich-text :nodes="activityInfo.activityContent" class="rich-text-content"></rich-text>
        </view>
        <!-- 报名状态 -->
        <view class="status-bar" :style="{ backgroundColor: statusBarColor }">
            <u-button class="signup-btn" @click.stop="activityReport()"
                :disabled="reportBtn">{{ reportBtn ? '已报名': '立即报名'}}</u-button>
            <view class="collect-icon" @click.stop="collect()">
                <u-icon :name="isCollect ? 'star-fill' : 'star'" size="52"
                    :color="isCollect ? '#ffcc00' : '#999'"></u-icon>
            </view>
        </view>
    </view>
</template>
 
<script>
    import '@/components/uview-components/uview-ui';
    import {changeCollect} from '@/api/collect.js'
    import {getActivityDetail, activityReport} from '@/api/activity.js';
    export default {
        data() {
            return {
                startX: 0,
                activityInfo: {
                    coverType: '',
                    cover: '',
                    activityName: '',
                    startTime: '', // 时间戳
                    endTime: '',
                    activityLocation: '',
                    tags: [],
                    activityContent: '',
                    activityType: '',
                    limitUserNum: '',
                    url: '',
                },
                isCollect: false,
                reportBtn: false,
                detailId: null, // 存储接收的参数
                reportFrom: {
                    activityId: '',
                    cancel: false, //报名接口默认我false
                },
                collectForm: {
                    collectType: '',
                    refId: '',
                },
            };
        },
        onLoad(options) {
            // 接收 URL 参数
            if (options.id) {
                this.detailId = options.id;
                // 可在此处发起请求,根据 ID 加载详情数据
                this.loadDetailData();
            }
        },
        methods: {
            /**
             * 触摸开始
             * @param {Object} e
             */
            touchStart(e) {
                if (e.touches.length == 1) {
                    //设置触摸起始点水平方向位置
                    this.startX = e.touches[0].clientX;
                }
            },
 
            touchEnd(e) {
                if (e.changedTouches.length == 1) {
                    //手指移动结束后水平位置
                    var endX = e.changedTouches[0].clientX;
                    let diff = endX - this.startX;
                    if (Math.abs(diff) > 20) {
                        if (diff > 0) {
                            console.log("左滑...");
 
                        } else {
                            console.log("右滑...");
                        }
                    }
                }
            },
            collect() {
                this.collectForm.collectType = 'activity'
                this.collectForm.refId = this.detailId
                changeCollect(this.collectForm).then(res => {
                    if (res.statusCode === 200) {
                        this.isCollect = true;
                        uni.showToast({
                            title: res.data.msg, // 提示文字
                            icon: 'success', // 图标类型(success/loading/none)
                            mask: true // 是否显示透明蒙层(防止触摸穿透)
                        });
                    }
                    this.getActivityDetail(this.detailId);
                })
 
            },
            //报名
            activityReport() {
                this.reportFrom.activityId = this.detailId
                activityReport(this.reportFrom).then(res => {
                    if (res.statusCode === 200) {
                        this.reportBtn = true;
                        uni.showToast({
                            title: res.data.msg, // 提示文字
                            icon: 'success', // 图标类型(success/loading/none)
                            mask: true // 是否显示透明蒙层(防止触摸穿透)
                        });
                    }
 
                })
 
            },
            getActivityDetail(id) {
                uni.showLoading({
                    title: '加载中'
                });
                getActivityDetail(id).then(res => {
                    uni.hideLoading();
                    console.log(res.data)
                    if (res.statusCode === 200) {
                        //赋值
                        this.activityInfo.coverType = res.data.data.coverType;
                        this.activityInfo.cover = res.data.data.cover;
                        this.activityInfo.activityName = res.data.data.activityName;
                        this.activityInfo.startTime = res.data.data.startTime;
                        this.activityInfo.endTime = res.data.data.endTime;
                        this.activityInfo.activityLocation = res.data.data.activityLocation;
                        this.activityInfo.activityContent = '<h2>活动介绍</h2>' + res.data.data.activityContent;
                        this.activityInfo.activityType = res.data.data.activityType;
                        this.activityInfo.limitUserNum = res.data.data.limitUserNum;
                        this.reportBtn = res.data.data.isReport;
                        this.isCollect = res.data.data.isCollect;
                        this.activityInfo.url = res.data.data.url;
                    }
                })
            },
            loadDetailData() {
                //获得详情接口
                this.getActivityDetail(this.detailId);
 
 
 
            }
        }
    };
</script>
<style lang="scss">
    /* 封面容器 */
    .cover-container {
        position: relative;
        width: 100%;
        height: 400rpx;
        overflow: hidden;
        background-color: #f5f5f5;
    }
 
    /* 图片/视频封面样式 */
    .activity-cover {
        width: 100%;
        height: 100%;
        border-radius: 0;
        /* 与列表页保持一致 */
    }
 
    /* 文字封面样式 - 与列表页保持一致 */
    .text-cover {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
        padding: 40rpx;
    }
 
    .cover-text {
        color: #fff;
        font-size: 36rpx;
        font-weight: bold;
        text-align: center;
        line-height: 1.4;
        text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.2);
    }
 
    .header-image {
        width: 100%;
        height: 400rpx;
    }
 
    .info-section {
        padding: 30rpx;
        background: #fff;
        margin-top: 20rpx;
    }
 
    .title {
        font-size: 40rpx;
        font-weight: bold;
        color: #333;
        display: block;
        margin-bottom: 20rpx;
    }
 
    .meta-info {
        margin-bottom: 20rpx;
        color: #666;
    }
 
    .time {
        margin-right: 30rpx;
    }
 
    .tags {
        display: flex;
        flex-wrap: wrap;
        margin-top: 20rpx;
    }
 
    .tag {
        font-size: 24rpx;
        padding: 8rpx 20rpx;
        background: #f0f0f0;
        border-radius: 30rpx;
        margin-right: 15rpx;
        margin-bottom: 15rpx;
    }
 
    .status-bar {
        display: flex;
        align-items: center;
        padding: 10px 15px;
        justify-content: space-between;
    }
 
    .signup-btn {
        flex: 1;
        margin-right: 15px;
    }
 
    .collect-icon {
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #f5f5f5;
        border-radius: 8px;
    }
 
    .footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 100rpx;
        background: #fff;
        display: flex;
        justify-content: space-around;
        align-items: center;
        border-top: 1rpx solid #eee;
        padding: 20rpx 0;
    }
 
    .footer-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        font-size: 24rpx;
        color: #666;
    }
 
    .footer-icon {
        width: 40rpx;
        height: 40rpx;
        margin-bottom: 10rpx;
    }
 
    .btn-container {
        display: flex;
        justify-content: center;
        align-items: center;
        margin-top: 8px;
        /* 与上方标题保持间距 */
    }
 
    .rich-text-container {
        padding: 15px;
    }
 
    .rich-text-content {
        line-height: 1.6;
        color: #333;
        font-size: 16px;
    }
 
    .rich-text-content img {
        max-width: 100%;
        height: auto;
        display: block;
        margin: 10px auto;
    }
 
    .rich-text-content video {
        max-width: 100%;
        height: auto;
        display: block;
        margin: 10px auto;
    }
 
    .rich-text-content p {
        margin-bottom: 10px;
    }
 
    .rich-text-content h1,
    .rich-text-content h2,
    .rich-text-content h3,
    .rich-text-content h4 {
        margin: 20px 0 10px;
        color: #222;
    }
 
    .rich-text-content h1 {
        font-size: 24px;
    }
 
    .rich-text-content h2 {
        font-size: 22px;
    }
 
    .rich-text-content h3 {
        font-size: 20px;
    }
 
    .rich-text-content h4 {
        font-size: 18px;
    }
</style>