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