<template>
|
<view>
|
<header-bar title="访客记录" :isBack="true" @click="back"></header-bar>
|
<view class="content">
|
<!-- 搜索栏 -->
|
<view class="search-bar">
|
<view class="search-input">
|
<text class="icon iconfont icon-sousuo"></text>
|
<input type="text" v-model="search" placeholder="搜索访客姓名" @confirm="searchVisitor" />
|
</view>
|
</view>
|
|
<!-- 访客列表 -->
|
<scroll-view scroll-y="true" class="visitor-list" @scrolltolower="loadMore">
|
<view v-if="visitors.length > 0">
|
<view class="visitor-item" v-for="(visitor, index) in visitors" :key="index">
|
<image class="visitor-avatar" :src="visitor.avatar || '/static/default.png'" mode="aspectFill"></image>
|
<view class="visitor-info">
|
<view class="visitor-header">
|
<view class="visitor-name">{{visitor.user_name || '未知访客'}}</view>
|
<view class="visitor-time">{{formatTime(visitor.visit_time)}}</view>
|
</view>
|
<view v-if="visitor.company_name" class="visitor-company">{{visitor.company_name}}</view>
|
<view v-if="visitor.position" class="visitor-position">{{visitor.position}}</view>
|
<view class="visitor-action">
|
<view class="action-btn" @click="viewCard(visitor.business_card_id)">
|
<text class="icon iconfont icon-card"></text>
|
<text>查看名片</text>
|
</view>
|
<view class="action-btn" @click="contactVisitor(visitor)">
|
<text class="icon iconfont icon-message"></text>
|
<text>联系访客</text>
|
</view>
|
</view>
|
</view>
|
</view>
|
</view>
|
|
<!-- 无数据提示 -->
|
<view v-else-if="!loading" class="no-data">
|
<text class="icon iconfont icon-wushuju"></text>
|
<text class="text">暂无访客记录</text>
|
</view>
|
|
<!-- 加载中 -->
|
<view v-if="loading && visitors.length > 0" class="loading-more">
|
<text>加载中...</text>
|
</view>
|
|
<!-- 无更多数据 -->
|
<view v-if="!hasMore && visitors.length > 0" class="no-more">
|
<text>没有更多了</text>
|
</view>
|
</scroll-view>
|
</view>
|
</template>
|
|
<script>
|
export default {
|
data() {
|
return {
|
visitors: [],
|
loading: false,
|
page: 1,
|
list_rows: 10,
|
hasMore: true,
|
search: ''
|
};
|
},
|
onLoad() {
|
this.getVisitors();
|
},
|
methods: {
|
back() {
|
uni.navigateBack();
|
},
|
// 获取访客列表
|
getVisitors() {
|
let _this = this;
|
_this.loading = true;
|
const params = {
|
page: _this.page,
|
list_rows: _this.list_rows
|
};
|
if (_this.search) {
|
params.search = _this.search;
|
}
|
_this._post('plus.business.business/getVisitors', params, function(res) {
|
_this.loading = false;
|
if (_this.page === 1) {
|
_this.visitors = res.data.list;
|
} else {
|
_this.visitors = _this.visitors.concat(res.data.list);
|
}
|
// 判断是否还有更多数据
|
_this.hasMore = _this.visitors.length < res.data.total;
|
});
|
},
|
// 搜索访客
|
searchVisitor() {
|
this.page = 1;
|
this.getVisitors();
|
},
|
// 加载更多
|
loadMore() {
|
if (!this.loading && this.hasMore) {
|
this.page++;
|
this.getVisitors();
|
}
|
},
|
// 查看访客名片
|
viewCard(business_card_id) {
|
this.gotoPage(`/pages/plus/business/detail?business_card_id=${business_card_id}`);
|
},
|
// 联系访客
|
contactVisitor(visitor) {
|
// 这里可以根据系统功能扩展,比如发送消息、拨打电话等
|
uni.showActionSheet({
|
itemList: ['发送消息', '拨打电话'],
|
success: (res) => {
|
if (res.tapIndex === 0) {
|
// 发送消息
|
this.showError('消息功能暂未开放');
|
} else if (res.tapIndex === 1) {
|
// 拨打电话
|
if (visitor.phone) {
|
uni.makePhoneCall({
|
phoneNumber: visitor.phone
|
});
|
} else {
|
this.showError('暂无联系电话');
|
}
|
}
|
}
|
});
|
},
|
// 格式化时间
|
formatTime(time) {
|
if (!time) return '';
|
const date = new Date(time);
|
const now = new Date();
|
const diff = now - date;
|
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
if (days === 0) {
|
return '今天 ' + date.getHours() + ':' + (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
|
} else if (days === 1) {
|
return '昨天 ' + date.getHours() + ':' + (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
|
} else if (days < 7) {
|
return days + '天前';
|
} else {
|
return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
|
}
|
}
|
}
|
};
|
</script>
|
|
<style lang="scss">
|
.content {
|
padding: 20rpx;
|
}
|
|
.search-bar {
|
background: #fff;
|
padding: 20rpx;
|
border-radius: 10rpx;
|
margin-bottom: 20rpx;
|
|
.search-input {
|
display: flex;
|
align-items: center;
|
background: #f5f5f5;
|
border-radius: 60rpx;
|
padding: 0 30rpx;
|
|
.icon {
|
font-size: 32rpx;
|
color: #999;
|
margin-right: 20rpx;
|
}
|
|
input {
|
flex: 1;
|
height: 80rpx;
|
font-size: 28rpx;
|
color: #333;
|
}
|
}
|
}
|
|
.visitor-list {
|
height: calc(100vh - 200rpx);
|
|
.visitor-item {
|
background: #fff;
|
border-radius: 20rpx;
|
padding: 30rpx;
|
margin-bottom: 20rpx;
|
display: flex;
|
|
.visitor-avatar {
|
width: 120rpx;
|
height: 120rpx;
|
border-radius: 50%;
|
background: #f5f5f5;
|
}
|
|
.visitor-info {
|
flex: 1;
|
margin-left: 30rpx;
|
|
.visitor-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
margin-bottom: 10rpx;
|
|
.visitor-name {
|
font-size: 34rpx;
|
font-weight: bold;
|
color: #333;
|
}
|
|
.visitor-time {
|
font-size: 24rpx;
|
color: #999;
|
}
|
}
|
|
.visitor-company,
|
.visitor-position {
|
font-size: 28rpx;
|
color: #666;
|
margin-bottom: 5rpx;
|
}
|
|
.visitor-action {
|
display: flex;
|
margin-top: 20rpx;
|
|
.action-btn {
|
display: flex;
|
align-items: center;
|
margin-right: 40rpx;
|
|
.icon {
|
font-size: 28rpx;
|
color: #37bde6;
|
margin-right: 8rpx;
|
}
|
|
text {
|
font-size: 26rpx;
|
color: #37bde6;
|
}
|
}
|
}
|
}
|
}
|
|
.no-data {
|
display: flex;
|
flex-direction: column;
|
align-items: center;
|
justify-content: center;
|
height: 400rpx;
|
|
.icon {
|
font-size: 120rpx;
|
color: #ccc;
|
margin-bottom: 30rpx;
|
}
|
|
.text {
|
font-size: 30rpx;
|
color: #999;
|
}
|
}
|
|
.loading-more,
|
.no-more {
|
text-align: center;
|
padding: 30rpx 0;
|
font-size: 28rpx;
|
color: #999;
|
}
|
}
|
</style>
|