expansion-list.vue
10 KB
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<template>
<view class="container">
<!-- 搜索栏 -->
<view class="search-card">
<u-search v-model="searchKeyword" placeholder="搜索顾客姓名" @search="handleSearch" @clear="handleClear"
@custom="handleSearch" class="search-input">
</u-search>
</view>
<!-- 数据列表 -->
<view class="list-card">
<view class="list-header">
<text class="header-text">拓客记录</text>
<text class="total-count">共 {{ totalCount }} 条</text>
</view>
<scroll-view scroll-y class="list-content" @scrolltolower="loadMore">
<view v-for="(item, index) in dataList" :key="index" class="list-item" @click="goToDetail(item)">
<view class="item-header">
<view class="customer-name">{{ item.customerName || '未知' }}</view>
<view class="expansion-time">{{ utils.formatTime(item.expansionTime || item.tksj) }}</view>
</view>
<view class="item-details">
<view class="detail-item">
<text class="detail-label">电话:</text>
<text>{{ item.customerPhone || '未知' }}</text>
</view>
</view>
<view class="item-actions" style="justify-content: right;">
<view class="invite-btn" @click.stop="handleInvite(item)">邀约</view>
</view>
</view>
<!-- 空状态 -->
<view v-if="!loading && dataList.length === 0" class="empty-state">
<view class="empty-icon">📋</view>
<view>暂无拓客数据</view>
<view v-if="searchKeyword" class="empty-search-tip">未找到匹配"{{ searchKeyword }}"的记录</view>
</view>
<!-- 加载状态 -->
<view v-if="loading && dataList.length === 0" class="loading">正在加载数据...</view>
<!-- 加载更多 -->
<u-loadmore v-if="dataList.length > 0" :status="loadmoreStatus" :load-text="loadText"></u-loadmore>
</scroll-view>
</view>
</view>
</template>
<script>
import {
mapState
} from 'vuex'
export default {
data() {
return {
loading: false,
searchKeyword: '',
dataList: [],
currentPage: 1,
pageSize: 10,
totalCount: 0,
hasMore: true,
searchTimer: null,
loadmoreStatus: 'loadmore',
loadText: {
loadmore: '点击或上拉加载更多',
loading: '正在加载...',
nomore: '没有更多了'
},
userInfo: uni.getStorageSync('userInfo'),
newuserInfo: uni.getStorageSync('newuserInfo'),
}
},
onLoad() {
this.initializePage()
},
onShow() {
// 页面显示时刷新数据
// this.refreshData()
},
onUnload() {
// 页面卸载时清理定时器
if (this.searchTimer) {
clearTimeout(this.searchTimer)
this.searchTimer = null
}
},
methods: {
// 初始化页面
async initializePage() {
try {
// 检查登录状态
await this.checkLoginStatus()
// 加载第一页数据
await this.loadExpansionList()
} catch (error) {
console.error('页面初始化失败:', error)
this.showErrorState('页面初始化失败,请刷新重试')
}
},
// 检查登录状态
async checkLoginStatus() {
const token = uni.getStorageSync('token')
if (!token) {
uni.reLaunch({
url: '/pages/login/login'
})
return
}
},
// 加载拓客列表
async loadExpansionList() {
if (this.loading) return
try {
this.loading = true
this.showLoadingState()
const params = {
currentPage: this.currentPage,
pageSize: this.pageSize
}
// 添加用户ID参数
if(this.newuserInfo.gw == '店助' || this.newuserInfo.gw == '店长') {
params.storeId = this.newuserInfo.mdid || '暂无'
} else {
if (this.userInfo && this.userInfo.userId) {
params.expansionUserId = this.userInfo.userId
}
}
// 添加搜索关键字
if (this.searchKeyword) {
params.keyword = this.searchKeyword
}
const res = await this.API.getExpansionList(params)
if (res.code === 200) {
const data = res.data
this.totalCount = data.pagination?.total || 0
const list = data.list || []
if (this.currentPage === 1) {
// 第一页,清空列表
this.dataList = list
} else {
// 加载更多,追加到列表
this.dataList = [...this.dataList, ...list]
}
// 判断是否还有更多数据
this.hasMore = list.length === this.pageSize
// 更新加载状态
if (this.hasMore) {
this.loadmoreStatus = 'loadmore'
} else {
this.loadmoreStatus = 'nomore'
}
} else {
throw new Error(res.message || '获取数据失败')
}
} catch (error) {
console.error('加载拓客列表失败:', error)
if (this.currentPage === 1) {
this.showErrorState('加载数据失败,请重试')
} else {
this.showMessage('加载更多数据失败', 'error')
}
} finally {
this.loading = false
}
},
// 搜索
handleSearch() {
// 清除之前的定时器
if (this.searchTimer) {
clearTimeout(this.searchTimer)
}
// 设置新的定时器,延迟500ms执行搜索
this.searchTimer = setTimeout(() => {
this.resetAndSearch()
}, 500)
},
// 清空搜索
handleClear() {
this.searchKeyword = ''
this.resetAndSearch()
},
// 重置并搜索
async resetAndSearch() {
this.currentPage = 1
this.hasMore = true
this.loadmoreStatus = 'loadmore'
this.dataList = []
await this.loadExpansionList()
},
// 刷新数据
refreshData() {
this.currentPage = 1
this.hasMore = true
this.loadmoreStatus = 'loadmore'
this.dataList = []
this.loadExpansionList()
},
// 加载更多
async loadMore() {
if (this.loading || !this.hasMore || this.loadmoreStatus === 'nomore') return
this.loadmoreStatus = 'loading'
this.currentPage++
await this.loadExpansionList()
},
// 跳转到详情页
goToDetail(item) {
console.error(item)
uni.navigateTo({
url: `/pages/expansion-detail/expansion-detail?id=${item.id}`
})
},
// 邀约
handleInvite(item) {
uni.navigateTo({
url: '/pages/invite/invite?tkbh='+item.id+'&customerPhone='+item.customerPhone
})
},
// 返回上一页
goBack() {
uni.navigateBack({
delta: 1
})
},
// 显示加载状态
showLoadingState() {
// 加载状态由模板控制
},
// 显示错误状态
showErrorState(message) {
uni.showToast({
title: message,
icon: 'none'
})
},
// 显示消息提示
showMessage(message, type = 'info') {
uni.showToast({
title: message,
icon: type === 'error' ? 'error' : 'none'
})
}
}
}
</script>
<style lang="scss" scoped>
.container {
height: 100vh;
background: linear-gradient(135deg, #e8f5e9 0%, #b2dfdb 100%);
padding: 40rpx 40rpx;
box-sizing: border-box;
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 40rpx;
}
.back-btn {
background: #fff;
border: none;
border-radius: 24rpx;
padding: 16rpx 24rpx;
color: #388e3c;
font-size: 28rpx;
box-shadow: 0 4rpx 16rpx rgba(76, 175, 80, 0.15);
transition: all 0.2s ease;
}
.header-title {
text-align: center;
color: #388e3c;
font-size: 36rpx;
font-weight: bold;
letter-spacing: 4rpx;
flex: 1;
}
.search-card {
background: #fff;
border-radius: 32rpx;
box-shadow: 0 8rpx 32rpx rgba(76, 175, 80, 0.1);
padding: 40rpx;
margin-bottom: 40rpx;
}
.list-card {
background: #fff;
border-radius: 32rpx;
box-shadow: 0 8rpx 32rpx rgba(76, 175, 80, 0.1);
overflow: hidden;
max-height: 70vh;
}
.list-header {
background: linear-gradient(120deg, #43e97b 0%, #38f9d7 100%);
padding: 32rpx 40rpx;
color: #fff;
font-weight: 600;
letter-spacing: 2rpx;
display: flex;
justify-content: space-between;
align-items: center;
}
.header-text {
font-size: 32rpx;
}
.total-count {
font-size: 28rpx;
opacity: 0.9;
}
.list-content {
max-height: calc(70vh - 120rpx);
overflow-y: auto;
}
.list-item {
padding: 32rpx 40rpx;
border-bottom: 2rpx solid #f0f0f0;
cursor: pointer;
transition: all 0.2s ease;
position: relative;
}
.list-item:hover {
background: #f8fff8;
transform: translateX(8rpx);
}
.list-item:last-child {
border-bottom: none;
}
.item-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16rpx;
}
.customer-name {
font-weight: 600;
color: #2e7d32;
font-size: 32rpx;
}
.expansion-time {
font-size: 24rpx;
color: #6a9c6a;
}
.item-details {
display: grid;
grid-template-columns: 1fr;
gap: 16rpx;
margin-bottom: 16rpx;
}
.detail-item {
display: flex;
align-items: center;
font-size: 28rpx;
color: #555;
}
.detail-label {
color: #6a9c6a;
margin-right: 12rpx;
font-size: 24rpx;
}
.item-actions {
display: flex;
justify-content: flex-start;
align-items: center;
margin-top: 24rpx;
}
.invite-btn {
background: linear-gradient(120deg, #43e97b 0%, #38f9d7 100%);
color: #fff;
padding: 16rpx 32rpx;
border-radius: 24rpx;
font-size: 28rpx;
font-weight: 500;
box-shadow: 0 4rpx 12rpx rgba(67, 233, 123, 0.3);
transition: all 0.2s ease;
cursor: pointer;
}
.invite-btn:active {
transform: scale(0.95);
box-shadow: 0 2rpx 8rpx rgba(67, 233, 123, 0.2);
}
.loading {
text-align: center;
padding: 80rpx 40rpx;
color: #6a9c6a;
font-size: 28rpx;
}
.empty-state {
text-align: center;
padding: 120rpx 40rpx;
color: #6a9c6a;
}
.empty-icon {
font-size: 120rpx;
margin-bottom: 32rpx;
opacity: 0.5;
}
.empty-search-tip {
margin-top: 16rpx;
font-size: 28rpx;
opacity: 0.7;
}
/* #ifdef H5 */
// 自定义搜索框样式
:deep(.u-search) {
background: #f9fff9;
border-radius: 24rpx;
}
:deep(.u-search__content) {
background: #f9fff9;
border: 3rpx solid #c8e6c9;
border-radius: 24rpx;
padding: 24rpx 32rpx;
font-size: 28rpx;
color: #2e7d32;
}
:deep(.u-search__content--focus) {
border-color: #43a047;
background: #fff;
}
:deep(.u-search__content__input) {
color: #2e7d32;
}
:deep(.u-search__content__input::placeholder) {
color: #6a9c6a;
}
/* #endif */
</style>