<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>
|