ReceptionHome.uvue
11.6 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
<template>
<!-- 接待中心首页:Tab 聚合页 -->
<view class="reception-home-page">
<!-- 顶部安全区 -->
<view class="reception-safe-top-spacer" :style="receptionSafeTopSpacerStyle"></view>
<!-- 导航栏 -->
<un-navbar title="接待中心" left-icon="" />
<!-- Tab 切换 -->
<view class="reception-home-tabs">
<un-tabs
:current="currentTabIndex"
@change="onTabChange"
>
<un-tab-item text="业绩看板"></un-tab-item>
<un-tab-item text="客户列表"></un-tab-item>
</un-tabs>
</view>
<!-- Tab 内容区域 -->
<view class="reception-home-content">
<!-- Tab 1: 业绩看板 -->
<view v-if="currentTabIndex == 0" class="tab-panel tab-panel-dashboard">
<DashboardPanel
:performance-data="performanceData"
:metrics-visible="performanceMetricsVisible"
:selected-brand="selectedBrand"
:selected-brand-value="selectedBrandValue"
@brand-change="onBrandChange"
@toggle-metrics="togglePerformanceMetricsVisibility"
/>
</view>
<!-- Tab 2: 客户列表 -->
<view v-if="currentTabIndex == 1" class="tab-panel tab-panel-list">
<CustomerListPanel
:customer-list="customerList"
:entry-filter-index="entryFilterIndex"
:show-customer-empty="showCustomerEmpty"
:customer-list-loading-more="customerListLoadingMore"
:customer-list-has-more="customerListHasMore"
@entry-click="onListCustomerEntryClick"
@entry-edit="onListCustomerEntryEdit"
@entry-delete="onListCustomerEntryDelete"
@switch-entry-filter="switchEntryFilterTab"
@customer-entry-click="onCustomerEntryClick"
/>
</view>
</view>
<!-- 全局弹窗复用(保持原有逻辑) -->
<un-picker :show="show" :columns="columns" @close="onClose" @cancel="onClose" @confirm="onConfirm" />
<!-- 客户档案详情全屏层 -->
<view v-if="showReceptionDetail" class="form-detail-inner">
<FormDetail
:show="showReceptionDetail"
:detail="receptionDetailItem"
@close="onReceptionDetailClose"
/>
</view>
</view>
</template>
<script setup lang="uts">
import { ref, computed, onMounted, onUnmounted } from 'vue'
// ✅ UVUE 类型导入:uview-unix 模块为二进制文件,使用本地定义的类型
import { type UnPickerColumn, type UnPickerColumnItem, type UnPickerConfirmEvent } from '@/types/uview-unix-types.uts'
import DashboardPanel from './panels/DashboardPanel.uvue'
import CustomerListPanel from './panels/CustomerListPanel.uvue'
import FormDetail from './forms/FormDetail.uvue'
import { storage } from '@/utils/storage.uts'
// ========== 状态管理 ==========
const currentTabIndex = ref(0) // 0=业绩看板,1=客户列表
// ========== 业绩看板数据(与原有逻辑一致) ==========
const performanceData = ref<UTSJSONObject>({})
const performanceMetricsVisible = ref(true)
const selectedBrand = ref<string>('')
const selectedBrandValue = ref<number>(1)
const show = ref(false)
// ========== 客户列表数据(与原有逻辑一致) ==========
const customerList = ref<UTSJSONObject[]>([])
const entryFilterIndex = ref(1)
const customerFilePageNum = ref(1)
const CUSTOMER_FILE_PAGE_SIZE = 10
const customerListLoadingMore = ref(false)
const customerListHasMore = ref(true)
// ========== 详情弹窗 ==========
const showReceptionDetail = ref(false)
const receptionDetailItem = ref<UTSJSONObject | null>(null)
// ========== 顶部安全区 ==========
const receptionPageInsetTopPx = ref(0)
const receptionSafeTopSpacerStyle = computed((): UTSJSONObject => {
return {
height: `${receptionPageInsetTopPx.value}px`,
width: '100%',
} as UTSJSONObject
})
function syncReceptionDashboardLayout(): void {
const info = uni.getWindowInfo()
let topInset = 0
const insets = info.safeAreaInsets
if (insets != null) {
const t = insets.top
if (t != null && t > 0) {
topInset = Math.round(t)
}
}
if (topInset <= 0) {
const safe = info.safeArea
if (safe != null) {
const st = safe.top
if (st != null && st > 0) {
topInset = Math.round(st)
}
}
}
if (topInset <= 0) {
const sb = info.statusBarHeight
if (sb != null && sb > 0) {
topInset = Math.round(sb)
}
}
receptionPageInsetTopPx.value = topInset
}
// ========== Tab 切换 ==========
function onTabChange(e: any): void {
currentTabIndex.value = e.index ?? 0
console.log('[ReceptionHome] Tab 切换:', currentTabIndex.value)
// Tab 切换时刷新对应数据
if (currentTabIndex.value == 0) {
// 切换到业绩看板
void loadPerformanceData()
} else {
// 切换到大客户列表
customerFilePageNum.value = 1
void getCustomerList(false)
}
}
function onTopTabClick(index: number): void {
if (currentTabIndex.value == index) {
return
}
onTabChange({ index } as UTSJSONObject)
}
// ========== 品牌选择 ==========
type PerformanceTypeItem = { label: string; value: number }
function performanceTypeList(): UnPickerColumn {
const list: PerformanceTypeItem[] = [
{ label: '问界', value: 1 },
{ label: '鸿蒙', value: 2 },
]
const items: UnPickerColumn = []
let i = 0
while (i < list.length) {
items.push({ text: list[i].label, value: list[i].value } as UnPickerColumnItem)
i++
}
return items
}
const columns = computed((): UnPickerColumn[] => {
return [performanceTypeList()]
})
const onConfirm = (e: UnPickerConfirmEvent): void => {
const items = e.value
if (items != null && items.length > 0) {
selectedBrand.value = items[0].text
selectedBrandValue.value = items[0].value as number
}
show.value = false
}
const onClose = (): void => {
show.value = false
}
function onBrandChange(brand: string, brandValue: number): void {
selectedBrand.value = brand
selectedBrandValue.value = brandValue
void loadPerformanceData()
}
function togglePerformanceMetricsVisibility(): void {
performanceMetricsVisible.value = !performanceMetricsVisible.value
}
// ========== 业绩数据加载 ==========
async function loadPerformanceData(): Promise<void> {
const rawUser = storage.get('userInfo') as UTSJSONObject | null
if (rawUser == null) { return }
const merchantId = rawUser['shopMerchantId']
const sceneType = rawUser['sceneType']
// 模拟数据(实际应调用接口)
performanceData.value = {
cumulativeDeliveryCount: 128,
actualContactCount: 96,
contactRate: 75,
achievementRatio: 85.5,
excellentStoreAvgDealRate: 42,
thisStoreDealRate: 38,
personalDealRate: 35,
actualProduction: 12.8,
personalProduction: 4.2,
excellentStoreAvgDeal: 12500,
thisStoreKdj: 10800,
personalKdj: 9500,
targetProduction: 199,
productionContribution: 100,
} as UTSJSONObject
console.log('[ReceptionHome] 业绩数据加载完成')
}
// ========== 客户列表加载 ==========
function getDefaultCustomerFileParams(): UTSJSONObject | null {
const rawUser = storage.get('userInfo') as UTSJSONObject | null
if (rawUser == null) { return null }
const merchantId = rawUser['shopMerchantId']
const sceneType = rawUser['sceneType']
const sceneBussiness = sceneType == 0 ? 1 : 2
const params = {
"pageNum": customerFilePageNum.value,
"pageSize": CUSTOMER_FILE_PAGE_SIZE,
"receptionStatus": 1,
"merchantId": merchantId,
"bussinessScene": sceneBussiness,
} as UTSJSONObject
if (entryFilterIndex.value == 0) {
const now = new Date()
const y = now.getFullYear()
const m = (now.getMonth() + 1).toString().padStart(2, '0')
const day = now.getDate().toString().padStart(2, '0')
const dateStr = `${y}-${m}-${day}`
params['startTime'] = `${dateStr} 00:00:00`
params['endTime'] = `${dateStr} 23:59:59`
}
return params
}
async function getCustomerList(append: boolean): Promise<void> {
if (append) {
if (customerListHasMore.value != true || customerListLoadingMore.value == true) {
return
}
customerFilePageNum.value++
customerListLoadingMore.value = true
}
const fileParams = getDefaultCustomerFileParams()
if (fileParams == null) {
console.warn('[ReceptionHome] 无登录门店信息,跳过客户列表请求')
return
}
try {
// TODO: 调用实际接口
console.log('[ReceptionHome] 请求客户列表:', fileParams)
// 模拟数据
const mockList: UTSJSONObject[] = []
for (let i = 0; i < 5; i++) {
mockList.push({
id: `mock_${Date.now()}_${i}`,
ownerName: `车主${i}`,
ownerPhone: `1380013800${i}`,
brandModel: '问界 M5',
receptionSceneName: '首次到店',
arrivalDate: '2026-04-03',
} as UTSJSONObject)
}
if (append) {
customerList.value = [...customerList.value, ...mockList]
} else {
customerList.value = mockList
}
customerListHasMore.value = customerList.value.length < 50 // 模拟还有更多
} catch (err) {
console.error('[ReceptionHome] 客户列表加载失败:', err)
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
customerListLoadingMore.value = false
}
}
function switchEntryFilterTab(index: number): void {
entryFilterIndex.value = index
customerFilePageNum.value = 1
void getCustomerList(false)
}
// ========== 事件处理 ==========
function onListCustomerEntryClick(item: UTSJSONObject): void {
// 与 FormAdd 打开方式一致:navigateTo + query record(JSON)
uni.navigateTo({
url: `/pages/receptionCenter/forms/FormDetail?record=${encodeURIComponent(JSON.stringify(item))}`
})
}
function onListCustomerEntryEdit(item: UTSJSONObject): void {
uni.navigateTo({
url: `/pages/receptionCenter/FormAdd?record=${encodeURIComponent(JSON.stringify(item))}`
})
}
function onListCustomerEntryDelete(item: UTSJSONObject): void {
const idStr = item['id']
customerList.value = customerList.value.filter(row => row['id'] != idStr)
uni.showToast({ title: '已删除', icon: 'none' })
}
function onCustomerEntryClick(): void {
uni.navigateTo({
url: '/pages/receptionCenter/FormAdd'
})
}
function onReceptionDetailClose(): void {
showReceptionDetail.value = false
receptionDetailItem.value = null
}
// ========== 生命周期 ==========
onMounted(() => {
syncReceptionDashboardLayout()
// 默认加载第一个 Tab 的数据
if (currentTabIndex.value == 0) {
void loadPerformanceData()
} else {
void getCustomerList(false)
}
})
onUnmounted(() => {
// 清理逻辑
})
</script>
<style lang="scss" scoped>
.reception-home-page {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
overflow: hidden;
background-color: #f8f9fa;
}
.reception-safe-top-spacer {
width: 100%;
flex-shrink: 0;
}
.reception-home-tabs {
background-color: #ffffff;
padding-bottom: 0;
flex-shrink: 0;
}
.top-tabs {
height: 50px;
flex-direction: row;
align-items: center;
justify-content: center;
}
.top-tab-item {
min-width: 110px;
height: 50px;
flex-direction: column;
align-items: center;
justify-content: flex-start;
padding-top: 6px;
box-sizing: border-box;
}
.top-tab-text {
font-size: 16px;
color: #667085;
font-weight: 500;
}
.top-tab-text-active {
color: #1677ff;
font-weight: 700;
}
.top-tab-line {
width: 24px;
height: 3px;
border-radius: 2px;
background-color: #1677ff;
margin-top: 9px;
}
.reception-home-content {
flex: 1;
overflow: hidden;
}
.tab-panel {
width: 100%;
height: 100%;
}
.tab-panel-dashboard {
background-color: #f8f9fa;
}
.tab-panel-list {
background-color: #f8f9fa;
}
.form-detail-inner {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
z-index: 999;
background-color: #fff;
}
</style>