quanwei
2025-10-29 76ed09d116f484b261d44219de300b79eb2013b3
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
<template>
    <view class="visit-card">
        <view class="card-header">
            <image :src="visitInfo.avatar" mode="aspectFill" class="avatar"></image>
            <view class="header-info">
                <view class="visitor-name">{{visitInfo.name || '游客'}}</view>
                <view class="visit-time">{{formatTime(visitInfo.visit_time)}}</view>
            </view>
        </view>
        <view class="card-content">
            <view class="info-row" v-if="visitInfo.visit_count > 1">
                <text class="info-label">访问次数:</text>
                <text class="info-value">{{visitInfo.visit_count}}次</text>
            </view>
            <view class="info-row" v-if="visitInfo.device">
                <text class="info-label">使用设备:</text>
                <text class="info-value">{{visitInfo.device}}</text>
            </view>
            <view class="info-row" v-if="visitInfo.region">
                <text class="info-label">所在地区:</text>
                <text class="info-value">{{visitInfo.region}}</text>
            </view>
            <view class="info-row" v-if="visitInfo.source">
                <text class="info-label">来源渠道:</text>
                <text class="info-value">{{visitInfo.source}}</text>
            </view>
            <view class="action-buttons" v-if="showActions">
                <button class="btn-primary" @click="viewCard">查看名片</button>
                <button class="btn-secondary" @click="contactVisitor">联系访客</button>
            </view>
        </view>
    </view>
</template>
 
<script>
    export default {
        props: {
            visitInfo: {
                type: Object,
                default: () => ({
                    avatar: '',
                    name: '',
                    visit_time: '',
                    visit_count: 1,
                    device: '',
                    region: '',
                    source: ''
                })
            },
            showActions: {
                type: Boolean,
                default: true
            }
        },
        methods: {
            // 格式化时间
            formatTime(timeStr) {
                if (!timeStr) return '';
                const date = new Date(timeStr);
                const now = new Date();
                const diff = now - date;
                const days = Math.floor(diff / (1000 * 60 * 60 * 24));
                
                if (days === 0) {
                    const hours = Math.floor(diff / (1000 * 60 * 60));
                    if (hours === 0) {
                        const minutes = Math.floor(diff / (1000 * 60));
                        return minutes <= 1 ? '刚刚' : minutes + '分钟前';
                    } else {
                        return hours + '小时前';
                    }
                } else if (days === 1) {
                    return '昨天';
                } else if (days < 7) {
                    return days + '天前';
                } else {
                    return date.getMonth() + 1 + '月' + date.getDate() + '日';
                }
            },
            // 查看访客名片
            viewCard() {
                if (this.visitInfo.user_id) {
                    this.$emit('viewCard', this.visitInfo.user_id);
                }
            },
            // 联系访客
            contactVisitor() {
                this.$emit('contact', this.visitInfo);
            }
        }
    };
</script>
 
<style lang="scss">
    .visit-card {
        background: #fff;
        border-radius: 20rpx;
        padding: 20rpx;
        margin-bottom: 20rpx;
 
        .card-header {
            display: flex;
            align-items: center;
            padding-bottom: 20rpx;
            border-bottom: 1rpx solid #f0f0f0;
 
            .avatar {
                width: 80rpx;
                height: 80rpx;
                border-radius: 40rpx;
                margin-right: 20rpx;
            }
 
            .header-info {
                flex: 1;
 
                .visitor-name {
                    font-size: 32rpx;
                    font-weight: bold;
                    color: #333;
                    margin-bottom: 5rpx;
                }
 
                .visit-time {
                    font-size: 24rpx;
                    color: #999;
                }
            }
        }
 
        .card-content {
            padding-top: 20rpx;
 
            .info-row {
                display: flex;
                margin-bottom: 15rpx;
 
                .info-label {
                    font-size: 28rpx;
                    color: #666;
                    margin-right: 10rpx;
                }
 
                .info-value {
                    font-size: 28rpx;
                    color: #333;
                    flex: 1;
                }
            }
 
            .action-buttons {
                display: flex;
                margin-top: 20rpx;
 
                button {
                    flex: 1;
                    height: 70rpx;
                    line-height: 70rpx;
                    font-size: 28rpx;
                    border-radius: 35rpx;
                    margin: 0 10rpx;
                }
 
                .btn-primary {
                    background: #37bde6;
                    color: #fff;
                }
 
                .btn-secondary {
                    background: #f5f5f5;
                    color: #666;
                }
            }
        }
    }
</style>