appointment-list.html
18.4 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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>绿纤协同平台 - 预约列表</title>
<!-- 引入配置文件 -->
<script src="config.js"></script>
<!-- 引入认证工具 -->
<script src="auth-utils.js"></script>
<style>
*, *::before, *::after { box-sizing: border-box; }
body {
font-family: 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
margin: 0;
min-height: 100vh;
background: linear-gradient(135deg, #e8f5e9 0%, #b2dfdb 100%);
padding: 20px;
}
.container {
width: 100%;
max-width: 480px;
margin: 0 auto;
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
}
.back-btn {
background: #fff;
border: none;
border-radius: 12px;
padding: 8px 12px;
color: #388e3c;
font-size: 0.9em;
cursor: pointer;
box-shadow: 0 2px 8px rgba(76, 175, 80, 0.15);
transition: all 0.2s ease;
}
.back-btn:hover {
box-shadow: 0 4px 16px rgba(76, 175, 80, 0.25);
transform: translateY(-1px);
}
h2 {
text-align: center;
color: #388e3c;
margin: 10px 0;
letter-spacing: 2px;
flex: 1;
}
.search-card {
background: #fff;
border-radius: 16px;
box-shadow: 0 4px 16px rgba(76, 175, 80, 0.1);
padding: 20px;
margin-bottom: 20px;
}
.search-input {
width: 100%;
padding: 12px 16px;
border: 1.5px solid #c8e6c9;
border-radius: 12px;
font-size: 1em;
background: #f9fff9;
color: #2e7d32;
transition: all 0.2s ease;
}
.search-input:focus {
outline: none;
border-color: #43a047;
box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
background: #fff;
}
.search-input::placeholder {
color: #6a9c6a;
}
.toolbar {
background: #fff;
border-radius: 16px;
box-shadow: 0 4px 16px rgba(76, 175, 80, 0.1);
padding: 20px;
margin-bottom: 20px;
display: flex;
gap: 12px;
align-items: center;
flex-wrap: wrap;
}
.btn {
padding: 12px 20px;
border: none;
border-radius: 10px;
font-size: 1em;
font-weight: bold;
cursor: pointer;
transition: all 0.2s ease;
letter-spacing: 1px;
text-decoration: none;
display: inline-block;
text-align: center;
}
.btn-primary {
background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
color: #fff;
box-shadow: 0 2px 8px rgba(67, 233, 123, 0.3);
}
.btn-primary:hover {
box-shadow: 0 4px 16px rgba(67, 233, 123, 0.4);
transform: translateY(-1px);
}
.btn-secondary {
background: #f5f5f5;
color: #666;
border: 1.5px solid #ddd;
}
.btn-secondary:hover {
background: #e8e8e8;
border-color: #ccc;
}
.list-card {
background: #fff;
border-radius: 16px;
box-shadow: 0 4px 16px rgba(76, 175, 80, 0.1);
overflow: hidden;
max-height: 70vh;
}
.list-header {
background: linear-gradient(120deg, #43e97b 0%, #38f9d7 100%);
padding: 16px 20px;
color: #fff;
font-weight: 600;
letter-spacing: 1px;
display: flex;
justify-content: space-between;
align-items: center;
}
.total-count {
font-size: 0.9em;
opacity: 0.9;
}
.list-content {
max-height: calc(70vh - 60px);
overflow-y: auto;
}
.list-item {
padding: 16px 20px;
border-bottom: 1px solid #f0f0f0;
cursor: pointer;
transition: all 0.2s ease;
position: relative;
}
.list-item:hover {
background: #f8fff8;
transform: translateX(4px);
}
.list-item:last-child {
border-bottom: none;
}
.item-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.customer-name {
font-weight: 600;
color: #2e7d32;
font-size: 1.05em;
}
.appointment-time {
font-size: 0.85em;
color: #6a9c6a;
}
.item-details {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 8px;
}
.detail-item {
display: flex;
align-items: center;
font-size: 0.9em;
color: #555;
}
.detail-label {
color: #6a9c6a;
margin-right: 6px;
font-size: 0.85em;
}
.item-footer {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 0.85em;
}
.appointment-status {
padding: 2px 8px;
border-radius: 12px;
font-size: 0.8em;
font-weight: 500;
}
.status-pending {
background: #fff3cd;
color: #856404;
}
.status-confirmed {
background: #d4edda;
color: #155724;
}
.status-completed {
background: #d1ecf1;
color: #0c5460;
}
.status-cancelled {
background: #f8d7da;
color: #721c24;
}
.loading {
text-align: center;
padding: 40px 20px;
color: #6a9c6a;
font-size: 0.9em;
}
.loading::after {
content: '';
display: inline-block;
width: 20px;
height: 20px;
border: 2px solid #c8e6c9;
border-radius: 50%;
border-top-color: #43a047;
animation: spin 1s linear infinite;
margin-left: 10px;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.empty-state {
text-align: center;
padding: 60px 20px;
color: #6a9c6a;
}
.empty-icon {
font-size: 3em;
margin-bottom: 16px;
opacity: 0.5;
}
.error-state {
text-align: center;
padding: 40px 20px;
color: #c62828;
}
.retry-btn {
background: #43a047;
color: #fff;
border: none;
border-radius: 8px;
padding: 8px 16px;
margin-top: 12px;
cursor: pointer;
font-size: 0.9em;
transition: all 0.2s ease;
}
.retry-btn:hover {
background: #388e3c;
}
.pagination {
display: flex;
justify-content: center;
align-items: center;
gap: 8px;
padding: 20px;
border-top: 1px solid #e0e0e0;
}
.page-btn {
padding: 8px 12px;
border: 1px solid #ddd;
background: #fff;
color: #666;
border-radius: 6px;
cursor: pointer;
transition: all 0.2s ease;
}
.page-btn:hover {
background: #f5f5f5;
border-color: #43a047;
}
.page-btn.active {
background: #43a047;
color: #fff;
border-color: #43a047;
}
.page-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
/* 消息提示样式 */
.message-toast {
position: fixed;
top: 20px;
right: 20px;
max-width: 300px;
padding: 16px 20px;
border-radius: 10px;
color: #fff;
font-weight: 500;
z-index: 2000;
transform: translateX(200%);
transition: all 0.3s ease;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}
.message-toast.show {
transform: translateX(0);
}
.message-toast.success {
background: linear-gradient(135deg, #4caf50 0%, #66bb6a 100%);
}
.message-toast.error {
background: linear-gradient(135deg, #f44336 0%, #ef5350 100%);
}
.message-toast.warning {
background: linear-gradient(135deg, #ff9800 0%, #ffb74d 100%);
}
.message-toast.info {
background: linear-gradient(135deg, #2196f3 0%, #42a5f5 100%);
}
@media (max-width: 520px) {
.container { max-width: 100%; }
.list-card { max-height: 65vh; }
.list-content { max-height: calc(65vh - 60px); }
.toolbar { flex-direction: column; align-items: stretch; }
.item-details { grid-template-columns: 1fr; }
.item-header { flex-direction: column; align-items: flex-start; gap: 8px; }
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<button class="back-btn" onclick="goBack()">← 返回</button>
<div></div>
</div>
<h2>预约列表</h2>
<div class="search-card">
<input
type="text"
class="search-input"
id="searchInput"
placeholder="搜索顾客姓名"
autocomplete="off"
>
</div>
<div class="list-card">
<div class="list-header">
<span>预约记录</span>
<span class="total-count" id="listCount">共 0 条记录</span>
</div>
<div class="list-content" id="listContent">
<div class="loading">正在加载预约数据...</div>
</div>
<div class="pagination" id="pagination" style="display: none;">
<button class="page-btn" id="prevBtn" onclick="changePage(-1)">上一页</button>
<span id="pageInfo">第 1 页,共 1 页</span>
<button class="page-btn" id="nextBtn" onclick="changePage(1)">下一页</button>
</div>
</div>
</div>
<!-- 消息提示 -->
<div id="messageToast" class="message-toast"></div>
<script>
// 全局变量
let currentPage = 1;
let pageSize = 10;
let totalPages = 1;
let totalCount = 0;
let appointmentList = [];
let filteredList = [];
let searchTerm = '';
let userInfo = JSON.parse(localStorage.getItem('userInfo'));
// 页面加载完成后初始化
document.addEventListener('DOMContentLoaded', function() {
initializePage();
bindEvents();
});
// 初始化页面
async function initializePage() {
await loadAppointmentList();
}
// 绑定事件
function bindEvents() {
// 搜索输入框事件 - 使用防抖处理
let searchTimeout;
document.getElementById('searchInput').addEventListener('input', function(e) {
searchTerm = e.target.value;
// 清除之前的定时器
clearTimeout(searchTimeout);
// 设置新的定时器,500ms后执行搜索
searchTimeout = setTimeout(() => {
handleSearch();
}, 500);
});
}
// 加载预约列表
async function loadAppointmentList() {
try {
showLoading();
// 构建API URL,包含搜索参数
let apiUrl = `${APP_CONFIG.getApiBaseUrl()}/api/Extend/LqYyjl?page=${currentPage}&pageSize=${pageSize}&yyr=${userInfo.userId}`;
// 如果有搜索条件,添加到URL参数中
if (searchTerm && searchTerm.trim()) {
apiUrl += `&gkxm=${encodeURIComponent(searchTerm.trim())}`;
}
console.log('请求URL:', apiUrl);
const response = await fetch(apiUrl, {
method: 'GET',
headers: {
'Authorization': `${getAuthToken()}`,
'Content-Type': 'application/json'
}
});
console.log('响应状态:', response.status);
if (response.ok) {
const result = await response.json();
console.log('接口返回数据:', result);
// 检查不同的数据结构可能性
if (result.code == 200) {
// 情况1: result.data 存在
if (result.data) {
appointmentList = result.data.list || result.data || [];
totalCount = result.data.pagination.total || 0;
console.log('使用 result.data 结构');
}
totalPages = Math.ceil(totalCount / pageSize);
console.log('解析后的数据:', {
appointmentList: appointmentList,
totalCount: totalCount,
totalPages: totalPages
});
// 更新列表计数
document.getElementById('listCount').textContent = `共 ${totalCount} 条记录`;
// 直接渲染列表,不再进行前端筛选
renderAppointmentList();
// 更新分页
updatePagination();
} else {
console.log('接口返回错误:', result);
showEmptyState(`获取预约列表失败: ${result.message || '未知错误'}`);
}
} else {
const errorText = await response.text();
console.log('HTTP错误:', response.status, errorText);
showEmptyState(`网络请求失败: ${response.status}`);
}
} catch (error) {
console.error('加载预约列表出错:', error);
showEmptyState('加载失败,请检查网络连接');
}
}
// 搜索处理函数(替换原来的过滤函数)
function handleSearch() {
// 重置到第一页
currentPage = 1;
// 重新加载数据
loadAppointmentList();
}
// 渲染预约列表(简化版本,直接使用appointmentList)
function renderAppointmentList() {
const listContent = document.getElementById('listContent');
if (!appointmentList || appointmentList.length === 0) {
if (searchTerm) {
showEmptyState('没有找到匹配的预约记录');
} else {
showEmptyState('暂无预约记录');
}
return;
}
listContent.innerHTML = '';
appointmentList.forEach(item => {
const listItem = createAppointmentItem(item);
listContent.appendChild(listItem);
});
}
// 创建预约项
function createAppointmentItem(item) {
const div = document.createElement('div');
div.className = 'list-item';
div.onclick = () => viewAppointmentDetail(item);
const status = getAppointmentStatus(item);
const statusText = getStatusText(status);
const appointmentTime = formatDateTime(item.createTime);
// 格式化开始时间和结束时间
const startTime = formatDateTime(item.yysj);
const endTime = formatDateTime(item.yyjs);
div.innerHTML = `
<div class="item-header">
<span class="customer-name">${item.gkxm || '未知顾客'}</span>
<span class="customer-name">${item.F_Status || '未知状态'}</span>
</div>
<div class="item-details">
<div class="detail-item">
<span class="detail-label">开始时间:</span>
<span>${startTime}</span>
</div>
<div class="detail-item">
<span class="detail-label">结束时间:</span>
<span>${endTime}</span>
</div>
</div>
`;
return div;
}
// 获取预约状态
function getAppointmentStatus(item) {
// 这里可以根据实际业务逻辑判断状态
// 暂时使用简单的逻辑
if (item.status === 'completed') return 'completed';
if (item.status === 'cancelled') return 'cancelled';
if (item.status === 'confirmed') return 'confirmed';
return 'pending';
}
// 获取状态文本
function getStatusText(status) {
const statusMap = {
'pending': '待确认',
'confirmed': '已确认',
'completed': '已完成',
'cancelled': '已取消'
};
return statusMap[status] || '未知';
}
// 格式化日期时间
function formatDateTime(dateTime) {
if (!dateTime) return '未知';
try {
const date = new Date(dateTime);
return date.toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
});
} catch (error) {
return dateTime;
}
}
// 显示加载状态
function showLoading() {
const listContent = document.getElementById('listContent');
listContent.innerHTML = '<div class="loading">正在加载预约数据...</div>';
}
// 显示空状态
function showEmptyState(message) {
const listContent = document.getElementById('listContent');
listContent.innerHTML = `
<div class="empty-state">
<div class="empty-icon">📅</div>
<div>${message}</div>
${searchTerm ? `<div style="margin-top: 8px; font-size: 0.9em; opacity: 0.7;">未找到匹配"${searchTerm}"的记录</div>` : ''}
</div>
`;
}
// 更新分页
function updatePagination() {
const pagination = document.getElementById('pagination');
const pageInfo = document.getElementById('pageInfo');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
if (totalPages <= 1) {
pagination.style.display = 'none';
return;
}
pagination.style.display = 'flex';
pageInfo.textContent = `第 ${currentPage} 页,共 ${totalPages} 页`;
prevBtn.disabled = currentPage <= 1;
nextBtn.disabled = currentPage >= totalPages;
}
// 切换页面
async function changePage(direction) {
const newPage = currentPage + direction;
if (newPage < 1 || newPage > totalPages) {
return;
}
currentPage = newPage;
await loadAppointmentList();
}
// 刷新列表
async function refreshList() {
currentPage = 1;
await loadAppointmentList();
showMessage('列表已刷新', 'success');
}
// 查看预约详情
function viewAppointmentDetail(item) {
if (item && item.id) {
// 跳转到详情页面,传递ID参数
window.location.href = `appointment-detail.html?id=${item.id}`;
} else {
showMessage('无法获取预约ID', 'error');
}
}
// 返回上一页
function goBack() {
if (window.history.length > 1) {
window.history.back();
} else {
window.location.href = 'index.html';
}
}
// 显示消息提示
function showMessage(message, type = 'info') {
const toast = document.getElementById('messageToast');
toast.textContent = message;
toast.className = `message-toast ${type}`;
// 显示提示
setTimeout(() => {
toast.classList.add('show');
}, 100);
// 自动隐藏
setTimeout(() => {
toast.classList.remove('show');
}, 3000);
}
</script>
</body>
</html>