longz
2026-07-08 700f9d0da314a4ea701fe9f68d305b67d72ec5fb
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
<script setup lang="ts">
import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app'
import { fetchVisitRecords } from '@/api/appointment'
import type { MiniVisitRecordItem } from '@/types/appointment'
import { normalizeVisitReasonText } from '@/utils/visitReason'
 
definePage({
  name: 'visitRecord',
  layout: 'default',
  style: {
    navigationStyle: 'custom',
  },
})
 
const props = withDefaults(defineProps<{
  title?: string
  futureOnly?: boolean
}>(), {
  title: '',
  futureOnly: false,
})
 
type VisitRecordCard = {
  id: number
  name: string
  totalPeople: number
  plateText: string
  reasonText: string
  time: string
}
 
const router = useRouter()
const sysInfo = uni.getSystemInfoSync()
const statusBarHeight = sysInfo.statusBarHeight || 0
const navBarHeight = 44
 
const searchKeyword = ref('')
const dateValue = ref('')
const showDatePicker = ref(false)
const loading = ref(false)
const refreshing = ref(false)
const records = ref<VisitRecordCard[]>([])
const pageTitle = ref(props.title || '来访记录')
 
const dateColumns = ref<string[][]>([[], [], []])
const datePickerIndex = ref([0, 0, 0])
 
function getCurrentDate() {
  return new Date()
}
 
function getDaysInMonth(year: number, month: number) {
  return new Date(year, month, 0).getDate()
}
 
function updateDateColumns(selection?: { year?: number, month?: number, day?: number }) {
  const now = getCurrentDate()
  const currentYear = now.getFullYear()
  const currentMonth = now.getMonth() + 1
  const currentDay = now.getDate()
 
  const years = Array.from({ length: 11 }, (_, index) => (currentYear - 5 + index).toString())
  const selectedYear = selection?.year && years.includes(selection.year.toString()) ? selection.year : currentYear
  const months = Array.from({ length: 12 }, (_, index) => (1 + index).toString())
  const selectedMonth = selection?.month && months.includes(selection.month.toString()) ? selection.month : currentMonth
  const maxDay = getDaysInMonth(selectedYear, selectedMonth)
  const days = Array.from({ length: maxDay }, (_, index) => (1 + index).toString())
  const selectedDay = selection?.day && days.includes(selection.day.toString()) ? selection.day : currentDay
 
  dateColumns.value = [years, months, days]
  datePickerIndex.value = [
    years.findIndex(item => item === selectedYear.toString()),
    months.findIndex(item => item === selectedMonth.toString()),
    days.findIndex(item => item === selectedDay.toString()),
  ]
}
 
function handleDateChange(e: any) {
  const selectedIndex = e.detail.value as number[]
  updateDateColumns({
    year: Number(dateColumns.value[0][selectedIndex[0]]),
    month: Number(dateColumns.value[1][selectedIndex[1]]),
    day: Number(dateColumns.value[2][selectedIndex[2]]),
  })
}
 
function handleDateConfirm() {
  const year = dateColumns.value[0][datePickerIndex.value[0]]
  const month = dateColumns.value[1][datePickerIndex.value[1]]
  const day = dateColumns.value[2][datePickerIndex.value[2]]
  dateValue.value = `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`
  showDatePicker.value = false
  void loadRecords()
}
 
function openDatePicker() {
  if (dateValue.value) {
    const [year, month, day] = dateValue.value.split('-').map(Number)
    updateDateColumns({ year, month, day })
  }
  else {
    updateDateColumns()
  }
  showDatePicker.value = true
}
 
function clearDateFilter() {
  dateValue.value = ''
  void loadRecords()
}
 
function formatDateFilterDisplay(value: string) {
  const text = (value || '').trim()
  if (!text) {
    return ''
  }
  return text.length >= 10 ? text.slice(2, 10) : text
}
 
function handleBack() {
  router.back()
}
 
function buildVisitTime(item: MiniVisitRecordItem) {
  const range = item.visitStartDate && item.visitEndDate && item.visitStartDate !== item.visitEndDate
    ? `${item.visitStartDate} 至 ${item.visitEndDate}`
    : item.visitStartDate || item.visitEndDate || '-'
  const slotMap: Record<string, string> = {
    ALL_DAY: '00:00-23:59',
    AM: '00:00-11:59',
    PM: '12:00-23:59',
  }
  const slotText = item.visitTimeMode === 'SINGLE' && item.visitTimeSlot
    ? ` ${slotMap[item.visitTimeSlot] || item.visitTimeSlot}`
    : ''
  return `${range}${slotText}`
}
 
function mapRecord(item: MiniVisitRecordItem): VisitRecordCard {
  const visitorDisplay = (item.visitorDisplayText || '').trim()
  const fallbackName = item.visitorNames.join('、').trim()
  return {
    id: item.orderId,
    name: visitorDisplay || fallbackName || '-',
    totalPeople: item.visitorNames.length,
    plateText: (item.plateNoText || '').trim(),
    reasonText: normalizeVisitReasonText(item.visitReasonText) || '-',
    time: buildVisitTime(item),
  }
}
 
async function loadRecords() {
  if (loading.value) {
    return
  }
  loading.value = true
  try {
    const result = await fetchVisitRecords({
      page: 1,
      size: 50,
      futureOnly: props.futureOnly,
      visitorNameKeyword: searchKeyword.value.trim() || undefined,
      visitDate: dateValue.value || undefined,
    })
    records.value = result.records.map(mapRecord)
  }
  catch (error) {
    uni.showToast({
      title: error instanceof Error ? error.message : '加载来访记录失败',
      icon: 'none',
    })
  }
  finally {
    loading.value = false
  }
}
 
function handleSearch() {
  void loadRecords()
}
 
async function handlePullRefresh() {
  if (refreshing.value) {
    return
  }
  refreshing.value = true
  try {
    await loadRecords()
  }
  finally {
    refreshing.value = false
  }
}
 
updateDateColumns()
 
onLoad((options) => {
  pageTitle.value = options?.title
    ? decodeURIComponent(options.title)
    : (props.title || '来访记录')
})
 
onShow(() => {
  void loadRecords()
})
 
onPullDownRefresh(async () => {
  try {
    await loadRecords()
  }
  finally {
    uni.stopPullDownRefresh()
  }
})
</script>
 
<template>
  <view class="min-h-screen bg-[#F6FBFF] w-full relative box-border flex flex-col">
    <view class="fixed left-0 top-0 z-0 h-[500rpx] w-full" style="background: linear-gradient(180deg, #5398FF 0%, #A9D0FF 50%, #F6FBFF 100%);" />
 
    <view class="fixed top-0 left-0 w-full z-50 flex flex-col">
      <view class="absolute left-0 top-0 z-[-1] w-full overflow-hidden" :style="{ height: (statusBarHeight + navBarHeight + uni.upx2px(120)) + 'px' }">
        <view class="w-full h-[500rpx] absolute top-0 left-0" style="background: linear-gradient(180deg, #5398FF 0%, #A9D0FF 50%, #F6FBFF 100%);" />
      </view>
 
      <view class="relative w-full shrink-0" :style="{ height: (statusBarHeight + navBarHeight) + 'px' }">
        <view class="flex items-center justify-between w-full absolute left-0" :style="{ top: statusBarHeight + 'px', height: navBarHeight + 'px' }">
          <view class="flex h-full w-[88rpx] items-center justify-center relative z-10" @click="handleBack">
            <wd-icon name="arrow-left" size="40rpx" color="#ffffff" />
          </view>
          <view class="absolute left-0 w-full text-center text-[34rpx] font-medium text-white z-0">
            {{ pageTitle }}
          </view>
          <view class="w-[88rpx]" />
        </view>
      </view>
 
      <view class="px-[28rpx] w-[702rpx] pt-[24rpx] pb-[16rpx] box-border">
        <view class="bg-white rounded-[16rpx] h-[104rpx] flex items-center px-[24rpx] shadow-[0_4rpx_8rpx_rgba(6,47,108,0.1608)] w-full shrink-0 justify-between">
          <view class="bg-[#F5F5F5] w-[140rpx] px-[40rpx] h-[64rpx] rounded-[44rpx] flex items-center mr-[20rpx]">
              <input
                v-model="searchKeyword"
                type="text"
                placeholder="来访人姓名"
                placeholder-class="text-[#B3B3B3] text-[26rpx]"
                class="w-full text-[26rpx] text-[#333333] h-full"
                confirm-type="search"
                @confirm="handleSearch"
              />
          </view>
 
          <view class="flex items-center mr-[20rpx] bg-[#F5F5F5] w-[220rpx] h-[64rpx] rounded-[44rpx]" @click="openDatePicker">
            <view class="flex items-center">
              <text class="text-[24rpx] pl-[32rpx] mr-[12rpx] max-w-[120rpx] truncate" :class="dateValue ? 'text-[#0068FF] font-medium' : 'text-[#333333]'">{{ dateValue ? formatDateFilterDisplay(dateValue) : '来访日期' }}</text>
              <view v-if="dateValue" class="w-[32rpx] h-[32rpx] flex items-center justify-center mr-[6rpx]" @click.stop="clearDateFilter">
                <wd-icon name="close-circle-filled" size="24rpx" color="#999999" />
              </view>
              <wd-icon name="arrow-down" size="24rpx" :color="dateValue ? '#0068FF' : '#000000'" />
            </view>
          </view>
 
          <view class="w-[156rpx] h-[64rpx] rounded-[32rpx] border-[2rpx] border-solid border-[#0068FF] flex items-center justify-center box-border bg-white" @click="handleSearch">
            <wd-icon name="search" size="28rpx" color="#0068FF" class="mr-[10rpx]" />
            <text class="text-[#0068FF] text-[26rpx] ml-[10rpx] font-medium">查询</text>
          </view>
        </view>
      </view>
    </view>
 
    <view :style="{ height: (statusBarHeight + navBarHeight + uni.upx2px(144)) + 'px' }" class="shrink-0" />
 
    <view class="relative z-10 px-[24rpx] flex-1 flex flex-col min-h-0 box-border pt-[16rpx]">
      <scroll-view
        scroll-y
        class="flex-1 min-h-0"
        :show-scrollbar="false"
        refresher-enabled
        :refresher-triggered="refreshing"
        @refresherrefresh="handlePullRefresh"
      >
        <view class="pb-[48rpx]">
          <view v-for="item in records" :key="item.id" class="bg-white rounded-[8rpx] shadow-[0_4rpx_8rpx_rgba(6,47,108,0.1608)] mb-[24rpx] px-[40rpx]">
            <view class="flex items-center h-[96rpx]">
              <text class="text-[#333333] text-[28rpx] font-bold shrink-0 w-[120rpx] mr-[12rpx]">访客姓名:</text>
              <view class="flex-1 h-full flex items-center border-b1 min-w-0">
                <view class="flex items-center min-w-0">
                  <text class="text-[#333333] text-[28rpx] truncate">{{ item.name }}</text>
                  <view v-if="item.plateText" class="ml-[10rpx] h-[36rpx] min-w-[64rpx] px-[12rpx] rounded-[18rpx] bg-[#E6F0FF] flex items-center justify-center shrink-0">
                  <text class="text-[#0068FF] text-[20rpx] leading-none">车辆</text>
                  </view>
                </view>
              </view>
            </view>
 
            <view class="flex items-center h-[96rpx]">
              <text class="text-[#333333] text-[28rpx] font-bold shrink-0 w-[120rpx] mr-[12rpx]">共计:</text>
              <view class="flex-1 h-full flex items-center border-b1">
                <text class="text-[#616161] text-[28rpx]">{{ item.totalPeople }}人</text>
              </view>
            </view>
 
            <view v-if="item.plateText" class="flex items-center h-[96rpx]">
              <text class="text-[#333333] text-[28rpx] font-bold shrink-0 w-[120rpx] mr-[12rpx]">访客车辆:</text>
              <view class="flex-1 h-full flex items-center border-b1">
                <text class="text-[#616161] text-[28rpx]">{{ item.plateText }}</text>
              </view>
            </view>
 
            <view class="flex items-center h-[96rpx]">
              <text class="text-[#333333] text-[28rpx] font-bold shrink-0 w-[120rpx] mr-[12rpx]">来访时间:</text>
              <view class="flex-1 h-full flex items-center border-b1">
                <text class="text-[#616161] text-[28rpx]">{{ item.time }}</text>
              </view>
            </view>
 
            <view class="flex items-center h-[96rpx]">
              <text class="text-[#333333] text-[28rpx] font-bold shrink-0 w-[120rpx] mr-[12rpx]">拜访事由:</text>
              <view class="flex-1 h-full flex items-center">
                <text class="text-[#616161] text-[28rpx]">{{ item.reasonText }}</text>
              </view>
            </view>
          </view>
 
          <view v-if="loading" class="text-center text-[#999999] text-[24rpx] py-[24rpx]">
            加载中...
          </view>
          <view v-else-if="records.length === 0" class="text-center text-[#999999] text-[24rpx] py-[80rpx]">
            暂无{{ pageTitle }}
          </view>
        </view>
      </scroll-view>
    </view>
 
    <wd-popup v-model="showDatePicker" position="bottom" custom-class="date-popup" z-index="100">
      <view class="flex flex-col bg-white rounded-t-[32rpx] overflow-hidden h-[830rpx]">
        <view class="relative flex items-center justify-center shrink-0 h-[96rpx] border-b border-[#F5F5F5] border-solid">
          <view class="absolute left-[32rpx] flex items-center justify-center w-[48rpx] h-[48rpx]" @click="showDatePicker = false">
            <wd-icon name="close-outline" size="40rpx" color="#333333" />
          </view>
          <text class="text-[32rpx] text-[#333333] font-medium">选择来访日期</text>
        </view>
 
        <view class="px-[32rpx] flex-1 flex flex-col justify-center relative">
          <view class="flex items-center absolute top-[40rpx] left-[32rpx] right-[32rpx] z-10 text-[24rpx] text-[#333333] font-medium">
            <view class="flex-1 flex justify-center"><text class="bg-[#F5F5F5] rounded-[8rpx] px-[24rpx] py-[8rpx]">年</text></view>
            <view class="flex-1 flex justify-center"><text class="bg-[#F5F5F5] rounded-[8rpx] px-[24rpx] py-[8rpx]">月</text></view>
            <view class="flex-1 flex justify-center"><text class="bg-[#F5F5F5] rounded-[8rpx] px-[24rpx] py-[8rpx]">日</text></view>
          </view>
          <picker-view class="custom-picker-view date-picker-view mt-[60rpx]" :value="datePickerIndex" indicator-style="height: 48px;" style="width: 100%; height: 192px;" @change="handleDateChange">
            <picker-view-column v-for="(col, index) in dateColumns" :key="index">
              <view v-for="(item, itemIndex) in col" :key="itemIndex" class="flex items-center justify-center h-[48px]" :class="{ 'wd-picker-view-column__item--active': datePickerIndex[index] === itemIndex, 'wd-picker-view-column__item': true }">
                {{ item }}
              </view>
            </picker-view-column>
          </picker-view>
        </view>
 
        <view class="px-[32rpx] pb-[48rpx] shrink-0">
          <wd-button type="primary" size="large" block custom-class="popup-submit-btn" @click="handleDateConfirm">
            确认
          </wd-button>
        </view>
      </view>
    </wd-popup>
  </view>
</template>
 
<style scoped>
.border-b1 {
  border-bottom: 2rpx solid #F5F5F5;
}
 
::-webkit-scrollbar {
  display: none;
  width: 0 !important;
  height: 0 !important;
  -webkit-appearance: none;
  background: transparent;
}
 
:deep(.date-popup) {
  border-top-left-radius: 32rpx;
  border-top-right-radius: 32rpx;
  overflow: hidden;
  background-color: transparent !important;
}
 
.wd-picker-view-column__item {
  color: #B3B3B3 !important;
  font-size: 28rpx !important;
  background-color: transparent !important;
  transition: all 0.3s;
  z-index: 10;
  position: relative;
}
 
:deep(picker-view-column) {
  background-color: transparent !important;
}
 
.custom-picker-view .wd-picker-view-column__item {
  font-size: 28rpx;
  color: #999999;
  transition: all 0.3s;
  position: relative;
  z-index: 10;
}
 
.wd-picker-view-column__item--active {
  color: #0068FF !important;
  font-weight: 500;
  font-size: 28rpx !important;
  background-color: #F4F8FF !important;
  z-index: 10;
}
 
:deep(.custom-picker-view .wx-picker-view-indicator) {
  border-top: none !important;
  border-bottom: none !important;
  background-color: #F4F8FF !important;
  border-radius: 8rpx;
  z-index: 1 !important;
}
 
:deep(.custom-picker-view .wx-picker-view-indicator::before),
:deep(.custom-picker-view .wx-picker-view-indicator::after) {
  display: none !important;
}
 
:deep(.date-picker-view picker-view-column:nth-child(1)),
:deep(.date-picker-view picker-view-column:nth-child(2)),
:deep(.date-picker-view picker-view-column:nth-child(3)) {
  flex: 1 !important;
  width: auto;
  padding: 0 !important;
  z-index: 10;
}
 
:deep(.date-picker-view picker-view-column:nth-child(1) .wd-picker-view-column__item),
:deep(.date-picker-view picker-view-column:nth-child(2) .wd-picker-view-column__item),
:deep(.date-picker-view picker-view-column:nth-child(3) .wd-picker-view-column__item) {
  width: 100% !important;
  text-align: center;
  padding: 0 !important;
}
 
:deep(.popup-submit-btn) {
  height: 96rpx !important;
  border-radius: 48rpx !important;
  font-size: 32rpx !important;
  font-weight: 500 !important;
  background: #0068FF !important;
}
</style>