wangzhibo
4 天以前 10595d8632f959d0954d1939243196f4eed02372
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
<!--
    再生资源回收 - 首页功能模块组件
    路径建议:/components/recycle-home.vue
    使用方式:在首页 <view class="hot"> 再生资源回收 </view> 区域直接引入
-->
 
<template>
    <view class="recycle-home">
        <!-- ===== 第一行:数据看板 ===== -->
        <view class="recycle-dashboard">
            <view class="dashboard-bg"></view>
            <view class="dashboard-inner">
                <view class="dash-item">
                    <text class="dash-num">{{ dashboard.carbonPoints ?? 0 }}</text>
                    <text class="dash-label">碳积分</text>
                </view>
                <view class="dash-divider"></view>
                <view class="dash-item">
                    <text class="dash-num">{{ dashboard.recycleCount ?? 0 }}</text>
                    <text class="dash-label">回收次数</text>
                </view>
                <view class="dash-divider"></view>
                <view class="dash-item">
                    <text class="dash-num dash-highlight">
                        {{ dashboard.overPercent ?? 0 }}%
                    </text>
                    <text class="dash-label">积分排名</text>
                </view>
            </view>
        </view>
 
        <!-- ===== 第二行:4 个功能按钮 ===== -->
        <view class="recycle-actions">
            <!-- ① 我的回收码 -->
            <view class="action-item" @tap="openQrcode">
                <view class="action-icon icon-green">
                    <image class="icon-img" :src="icons.qrcode" mode="aspectFit" />
                </view>
                <text class="action-text">我的回收码</text>
            </view>
 
            <!-- ② 回收记录 -->
            <view class="action-item" @tap="goRecord">
                <view class="action-icon icon-blue">
                    <image class="icon-img" :src="icons.record" mode="aspectFit" />
                </view>
                <text class="action-text">回收记录</text>
            </view>
 
            <!-- ③ 我要预约 -->
            <view class="action-item" @tap="goAppointment">
                <view class="action-icon icon-orange">
                    <image class="icon-img" :src="icons.appointment" mode="aspectFit" />
                </view>
                <text class="action-text">预约回收</text>
            </view>
 
            <!-- ④ 积分转赠 -->
            <view class="action-item" @tap="goTransfer">
                <view class="action-icon icon-purple">
                    <image class="icon-img" :src="icons.transfer" mode="aspectFit" />
                </view>
                <text class="action-text">积分转赠</text>
            </view>
        </view>
 
        <!-- ===== 二维码弹层 ===== -->
        <cl-popup v-model="showQrcode" direction="center" :close-on-click-overlay="true" background-color="transparent"
            @close="showQrcode = false">
            <view class="qrcode-popup" @tap.stop>
                <view class="qrcode-card">
                    <text class="qrcode-title">我的回收码</text>
                    <text class="qrcode-desc">向回收员出示此码完成回收</text>
                    <view class="qrcode-image-wrap">
                        <image class="qrcode-image" :src="qrcodeUrl" mode="aspectFit" />
                        
                    </view>
                    <text class="qrcode-code">回收码:{{ userCode }}</text>
                    <view class="qrcode-close" @tap="showQrcode = false">
                        <cl-icon name="close" :size="36" color="#999" />
                    </view>
                </view>
            </view>
        </cl-popup>
    </view>
</template>
 
<script lang="ts" setup>
    import { ref, onMounted } from "vue";
    import { router, useCool, useStore, usePager } from "/@/cool";
    import { onReady, onShareAppMessage } from "@dcloudio/uni-app";
 
    import { generateRecycleQrcode } from "/@/cool/utils/qrcode";
 
 
    const { user } = useStore();
 
    const { service, refs, setRefs } = useCool();
    const { onRefresh, onData } = usePager();
    // ========== 静态图标路径(4 个按钮图标) ==========
    // 实际项目中放到 /static/recycle/ 目录下
    const icons = {
        qrcode: "/static/recycle/qrcode.png",
        record: "/static/recycle/record.png",
        appointment: "/static/recycle/appointment.png",
        transfer: "/static/recycle/transfer.png",
    };
 
    // ========== 数据 ==========
    const dashboard = ref({
        carbonPoints: 0,
        recycleCount: 0,
        overPercent: 0,
    });
 
    const showQrcode = ref(false);
    const userCode = ref("");
    const qrcodeUrl = ref("");
 
    // ========== 初始化加载 ==========
    onMounted(() => {
        loadDashboard();
    });
 
    /** 加载首页数据看板 */
    async function loadDashboard() {
        try {
            const unionid = user.info?.phone||"18918594752";
            service.user.info.dashboard({ unionid:unionid  }).then((res) => {
                console.log("【再生资源看板数据】", res);
                dashboard.value = {
                    carbonPoints: res.carbonPoints ?? 0,
                    recycleCount: res.recycleCount ?? 0,
                    overPercent: res.overPercent ?? 0,
                };
            });
        } catch (e) {
            console.error("【再生资源看板加载失败】", e);
        }
    }
 
    /** 加载用户回收码 */
    async function loadMyCode() {
        try {
            const phone = user.info?.phone ?? "18918594752";
            const res = await generateRecycleQrcode(phone);
            userCode.value = phone;
            qrcodeUrl.value = res;
        } catch (e) {
            console.error("【回收码加载失败】", e);
            // 兜底:没有接口时给个默认值
            userCode.value = "RC-LOADING";
        }
    }
 
    // ========== 按钮事件 ==========
 
    /** ① 打开二维码 */
    function openQrcode() {
        loadMyCode();
        showQrcode.value = true;
    }
 
    /** ② 跳转回收记录 */
    function goRecord() {
        router.push("/pages/recycle/record");
    }
 
    /** ③ 跳转我要预约 */
    function goAppointment() {
        router.push("/pages/recycle/appointment");
    }
 
    /** ④ 跳转积分转赠 */
    function goTransfer() {
        router.push("/pages/recycle/transfer");
    }
</script>
 
<style lang="scss" scoped>
    .recycle-home {
        padding: 0 24rpx;
 
        /* ========== 数据看板 ========== */
        .recycle-dashboard {
            position: relative;
            border-radius: 24rpx;
            overflow: hidden;
            margin-bottom: 30rpx;
            box-shadow: 0 8rpx 24rpx rgba(46, 204, 113, 0.2);
 
            .dashboard-bg {
                position: absolute;
                inset: 0;
                background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
                z-index: 0;
            }
 
            .dashboard-inner {
                position: relative;
                z-index: 1;
                display: flex;
                align-items: center;
                justify-content: space-around;
                padding: 36rpx 20rpx;
            }
 
            .dash-item {
                display: flex;
                flex-direction: column;
                align-items: center;
                flex: 1;
            }
 
            .dash-num {
                font-size: 44rpx;
                font-weight: 700;
                color: #ffffff;
                line-height: 1.2;
            }
 
            .dash-highlight {
                color: #ffd700;
                text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.15);
            }
 
            .dash-label {
                font-size: 22rpx;
                color: rgba(255, 255, 255, 0.85);
                margin-top: 8rpx;
            }
 
            .dash-divider {
                width: 2rpx;
                height: 50rpx;
                background-color: rgba(255, 255, 255, 0.3);
            }
        }
 
        /* ========== 4 个功能按钮 ========== */
        .recycle-actions {
            display: flex;
            justify-content: space-around;
            align-items: center;
            background-color: #fff;
            border-radius: 20rpx;
            padding: 28rpx 10rpx;
            margin-bottom: 20rpx;
            box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
        }
 
        .action-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            transition: transform 0.15s ease;
 
            &:active {
                transform: scale(0.92);
            }
        }
 
        .action-icon {
            width: 96rpx;
            height: 96rpx;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 14rpx;
 
            .icon-img {
                width: 52rpx;
                height: 52rpx;
            }
 
            &.icon-green {
                background: linear-gradient(135deg, #e8f8f0, #d5f5e3);
            }
 
            &.icon-blue {
                background: linear-gradient(135deg, #eaf4fc, #d6eaf8);
            }
 
            &.icon-orange {
                background: linear-gradient(135deg, #fef5e7, #fdebd0);
            }
 
            &.icon-purple {
                background: linear-gradient(135deg, #f5eef8, #ebdef0);
            }
        }
 
        .action-text {
            font-size: 24rpx;
            color: #333;
            font-weight: 500;
        }
 
        /* ========== 二维码弹层 ========== */
        .qrcode-popup {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 100%;
        }
 
        .qrcode-card {
            position: relative;
            width: 600rpx;
            background: #fff;
            border-radius: 28rpx;
            padding: 50rpx 40rpx 40rpx;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
 
        .qrcode-title {
            font-size: 34rpx;
            font-weight: 700;
            color: #333;
            margin-bottom: 10rpx;
        }
 
        .qrcode-desc {
            font-size: 24rpx;
            color: #999;
            margin-bottom: 36rpx;
        }
 
        .qrcode-image-wrap {
            width: 480rpx;
            height: 480rpx;
            border-radius: 16rpx;
            overflow: hidden;
            background: #f7f7f7;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 28rpx;
        }
 
        .qrcode-image {
            width: 100%;
            height: 100%;
        }
 
        .qrcode-code {
            font-size: 26rpx;
            color: #666;
            letter-spacing: 2rpx;
        }
 
        .qrcode-close {
            position: absolute;
            top: 20rpx;
            right: 20rpx;
            width: 60rpx;
            height: 60rpx;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            background: #f5f5f5;
        }
    }
</style>