-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperty_dashboard.html
More file actions
953 lines (867 loc) · 63.2 KB
/
property_dashboard.html
File metadata and controls
953 lines (867 loc) · 63.2 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
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>物业工作台 - 幸福小区</title>
<script src="js/Taildwind-browser@4.js"></script>
<script src="js/lucide.js"></script>
<script src="js/jquery-3.7.1.min.js"></script>
<style>
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
.fade-in { animation: fadeIn 0.3s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.modal-enter { animation: modalIn 0.2s ease-out forwards; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.progress-bar { transition: width 1s ease-in-out; }
.ios-scroll { -webkit-overflow-scrolling: touch; }
.hidden-view { display: none !important; }
.toggle-checkbox:checked { right: 0; border-color: #10B981; }
.toggle-checkbox:checked + .toggle-label { background-color: #10B981; }
</style>
</head>
<body class="bg-[#F5F7FA] font-sans text-slate-800 min-h-screen select-none pb-28 overflow-x-hidden">
<div id="view-dashboard" class="page-view fade-in">
<header class="px-6 pt-12 pb-6 flex justify-between items-center bg-white sticky top-0 z-20 shadow-sm rounded-b-[2rem]">
<div>
<p class="text-xs text-slate-400 font-bold tracking-wider mb-1">PROPERTY MANAGER</p>
<h1 class="text-2xl font-bold text-slate-900">物业工作台</h1>
</div>
<div class="flex items-center gap-3">
<button class="relative p-2 text-slate-400 hover:text-slate-600">
<i data-lucide="bell" width="24" height="24"></i>
<span class="absolute top-2 right-2 w-2 h-2 bg-red-500 rounded-full hidden" id="has-notification"></span>
</button>
<div class="w-10 h-10 rounded-full overflow-hidden border-2 border-blue-100">
<img id="dash-avatar" src="https://images.unsplash.com/photo-1560250097-0b93528c311a?ixlib=rb-1.2.1&auto=format&fit=crop&w=100&q=80" class="w-full h-full object-cover">
</div>
</div>
</header>
<main class="mt-6">
<section class="mb-8 px-6">
<h3 class="text-lg font-bold text-slate-900 mb-4 flex items-center gap-2">
<i data-lucide="bar-chart-2" width="20" height="20" class="text-[#3B82F6]"></i>
今日概览
</h3>
<div class="grid grid-cols-2 gap-4">
<div class="bg-white p-4 rounded-[1.5rem] shadow-sm">
<p class="text-xs text-slate-400 mb-1">本月缴费率</p>
<div class="text-2xl font-bold text-slate-900 mb-2" id="stat-payment">--%</div>
<div class="w-full h-2 bg-slate-100 rounded-full overflow-hidden">
<div id="prog-payment" class="h-full bg-[#3B82F6] w-0 progress-bar"></div>
</div>
</div>
<div class="bg-white p-4 rounded-[1.5rem] shadow-sm">
<p class="text-xs text-slate-400 mb-1">业主满意度</p>
<div class="text-2xl font-bold text-slate-900 mb-2" id="stat-satisfaction">--</div>
<div class="flex text-yellow-400">
<i data-lucide="star" width="12" height="12" fill="currentColor"></i><i data-lucide="star" width="12" height="12" fill="currentColor"></i><i data-lucide="star" width="12" height="12" fill="currentColor"></i><i data-lucide="star" width="12" height="12" fill="currentColor"></i><i data-lucide="star" width="12" height="12" fill="currentColor"></i>
</div>
</div>
<div onclick="switchTab('orders')" class="bg-gradient-to-br from-orange-50 to-white p-4 rounded-[1.5rem] shadow-sm border border-orange-100 active:scale-95 transition-transform cursor-pointer">
<p class="text-xs text-orange-400 mb-1 font-bold">待处理报修</p>
<div class="text-3xl font-bold text-slate-900" id="stat-repair-count">--</div>
</div>
<div onclick="switchTab('orders')" class="bg-gradient-to-br from-red-50 to-white p-4 rounded-[1.5rem] shadow-sm border border-red-100 active:scale-95 transition-transform cursor-pointer">
<p class="text-xs text-red-400 mb-1 font-bold">设备报警</p>
<div class="text-3xl font-bold text-slate-900" id="stat-alert-count">--</div>
</div>
</div>
</section>
<section class="mb-8">
<div class="px-6 mb-4"><h3 class="text-lg font-bold text-slate-900">快捷管理</h3></div>
<div class="flex overflow-x-auto pb-8 gap-4 snap-x mandatory no-scrollbar ios-scroll">
<div onclick="openAnnouncementModal()" class="ml-6 min-w-[150px] w-[42%] bg-white rounded-[2rem] p-5 flex flex-col justify-between h-56 shadow-[0_4px_20px_rgb(0,0,0,0.03)] snap-start shrink-0 active:scale-95 transition-transform duration-200">
<div class="text-[#3B82F6] mb-4"><i data-lucide="megaphone" width="40" height="40" stroke-width="1.5"></i></div>
<div><h4 class="text-xl font-bold mb-1 text-[#3B82F6]">发公告</h4><p class="text-gray-400 text-xs leading-relaxed">发布社区通知消息</p></div>
</div>
<div onclick="openAddResidentModal()" class="min-w-[150px] w-[42%] bg-white rounded-[2rem] p-5 flex flex-col justify-between h-56 shadow-[0_4px_20px_rgb(0,0,0,0.03)] snap-start shrink-0 active:scale-95 transition-transform duration-200">
<div class="text-emerald-500 mb-4"><i data-lucide="user-plus" width="40" height="40" stroke-width="1.5"></i></div>
<div><h4 class="text-xl font-bold mb-1 text-emerald-500">录业主</h4><p class="text-gray-400 text-xs leading-relaxed">录入新住户信息</p></div>
</div>
<div onclick="openCreateBillModal()" class="min-w-[150px] w-[42%] bg-white rounded-[2rem] p-5 flex flex-col justify-between h-56 shadow-[0_4px_20px_rgb(0,0,0,0.03)] snap-start shrink-0 active:scale-95 transition-transform duration-200">
<div class="text-amber-500 mb-4"><i data-lucide="receipt-japanese-yen" width="40" height="40" stroke-width="1.5"></i></div>
<div><h4 class="text-xl font-bold mb-1 text-amber-500">建账单</h4><p class="text-gray-400 text-xs leading-relaxed">生成物业缴费单</p></div>
</div>
<div class="w-2 shrink-0"></div>
</div>
</section>
<section class="px-6 mb-8">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-bold text-slate-900">最新待办</h3>
<button onclick="switchTab('orders')" class="text-xs text-[#3B82F6] font-bold">查看全部</button>
</div>
<div id="dashboard-task-list" class="space-y-4"></div>
</section>
<section class="px-6">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-bold text-slate-900">最新公告</h3>
</div>
<div id="dashboard-announcement-list" class="space-y-4"></div>
</section>
</main>
</div>
<div id="view-orders" class="page-view hidden-view fade-in">
<header class="px-6 pt-12 pb-4 bg-white sticky top-0 z-20 border-b border-slate-100">
<h1 class="text-2xl font-bold text-slate-900 mb-4">工单中心</h1>
<div class="flex bg-slate-100 p-1 rounded-xl">
<button onclick="filterOrders('submitted')" class="order-filter-btn flex-1 py-2 rounded-lg text-sm font-bold text-slate-600 bg-white shadow-sm transition-all" data-status="submitted">待处理</button>
<button onclick="filterOrders('active')" class="order-filter-btn flex-1 py-2 rounded-lg text-sm font-bold text-slate-400 transition-all" data-status="active">处理中</button>
<button onclick="filterOrders('completed')" class="order-filter-btn flex-1 py-2 rounded-lg text-sm font-bold text-slate-400 transition-all" data-status="completed">已完成</button>
</div>
</header>
<main class="px-6 mt-4 pb-20">
<div id="orders-list-container" class="space-y-4"></div>
</main>
</div>
<div id="view-residents" class="page-view hidden-view fade-in">
<header class="px-6 pt-12 pb-4 bg-white sticky top-0 z-20 border-b border-slate-100">
<h1 class="text-2xl font-bold text-slate-900 mb-4">住户管理</h1>
<div class="relative">
<i data-lucide="search" class="absolute left-4 top-3.5 text-slate-400 w-5 h-5"></i>
<input type="text" id="resident-search" class="w-full bg-slate-50 border-none rounded-xl py-3 pl-12 pr-4 text-sm focus:ring-2 focus:ring-blue-100 transition-all outline-none" placeholder="搜索姓名、房号、手机号...">
</div>
</header>
<main class="px-6 mt-4 pb-20">
<div id="residents-list-container" class="space-y-3"></div>
</main>
<button onclick="openAddResidentModal()" class="fixed bottom-24 right-6 w-14 h-14 bg-[#10B981] text-white rounded-full flex items-center justify-center shadow-[0_4px_14px_rgba(16,185,129,0.4)] active:scale-90 transition-transform z-30"><i data-lucide="plus" width="28" height="28"></i></button>
</div>
<div id="view-settings" class="page-view hidden-view fade-in">
<header class="px-6 pt-12 pb-6"><h1 class="text-2xl font-bold text-slate-900">系统设置</h1></header>
<main class="px-6 space-y-6">
<div class="bg-white rounded-[2rem] p-6 flex items-center gap-4 shadow-sm">
<div class="w-16 h-16 rounded-full overflow-hidden"><img src="https://images.unsplash.com/photo-1560250097-0b93528c311a?ixlib=rb-1.2.1&auto=format&fit=crop&w=100&q=80" class="w-full h-full object-cover"></div>
<div><h2 class="text-xl font-bold text-slate-900" id="setting-username">Admin</h2><p class="text-sm text-slate-500">物业管理员</p></div>
</div>
<div class="space-y-3">
<button onclick="openChangePasswordModal()" class="w-full bg-white p-4 rounded-2xl flex items-center justify-between active:bg-slate-50 transition-colors">
<div class="flex items-center gap-3"><div class="w-8 h-8 rounded-full bg-blue-50 text-blue-500 flex items-center justify-center"><i data-lucide="lock" width="18" height="18"></i></div><span class="font-bold text-slate-700">修改密码</span></div><i data-lucide="chevron-right" class="text-slate-300" width="20" height="20"></i>
</button>
<button onclick="openLogsModal()" class="w-full bg-white p-4 rounded-2xl flex items-center justify-between active:bg-slate-50 transition-colors">
<div class="flex items-center gap-3"><div class="w-8 h-8 rounded-full bg-orange-50 text-orange-500 flex items-center justify-center"><i data-lucide="file-text" width="18" height="18"></i></div><span class="font-bold text-slate-700">操作日志</span></div><i data-lucide="chevron-right" class="text-slate-300" width="20" height="20"></i>
</button>
</div>
<button onclick="logout()" class="w-full bg-red-50 text-red-500 font-bold py-4 rounded-2xl mt-8 hover:bg-red-100 transition-colors">退出管理端</button>
</main>
</div>
<div class="fixed bottom-6 left-6 right-6 z-50">
<nav class="bg-white/95 backdrop-blur-md rounded-[2rem] shadow-[0_8px_30px_rgb(0,0,0,0.08)] px-6 py-3 flex justify-between items-center border border-white/50">
<button onclick="switchTab('dashboard')" class="nav-item dashboard-btn relative flex flex-col items-center gap-1 w-12 text-[#3B82F6] -translate-y-1 transition-all duration-300">
<i data-lucide="layout-dashboard" width="24" height="24" stroke-width="2.5"></i><span class="text-[10px] font-medium">工作台</span>
<span class="indicator absolute -bottom-2 left-1/2 -translate-x-1/2 w-1 h-1 bg-[#3B82F6] rounded-full"></span>
</button>
<button onclick="switchTab('orders')" class="nav-item orders-btn relative flex flex-col items-center gap-1 w-12 text-slate-400 transition-all duration-300">
<i data-lucide="wrench" width="24" height="24" stroke-width="2"></i><span class="text-[10px] font-medium">工单</span>
<span class="indicator absolute -bottom-2 left-1/2 -translate-x-1/2 w-1 h-1 bg-[#3B82F6] rounded-full hidden"></span>
</button>
<button onclick="switchTab('residents')" class="nav-item residents-btn relative flex flex-col items-center gap-1 w-12 text-slate-400 transition-all duration-300">
<i data-lucide="users" width="24" height="24" stroke-width="2"></i><span class="text-[10px] font-medium">住户</span>
<span class="indicator absolute -bottom-2 left-1/2 -translate-x-1/2 w-1 h-1 bg-[#3B82F6] rounded-full hidden"></span>
</button>
<button onclick="switchTab('settings')" class="nav-item settings-btn relative flex flex-col items-center gap-1 w-12 text-slate-400 transition-all duration-300">
<i data-lucide="settings" width="24" height="24" stroke-width="2"></i><span class="text-[10px] font-medium">设置</span>
<span class="indicator absolute -bottom-2 left-1/2 -translate-x-1/2 w-1 h-1 bg-[#3B82F6] rounded-full hidden"></span>
</button>
</nav>
</div>
<div id="handle-modal" class="fixed inset-0 bg-black/40 z-[60] hidden flex items-center justify-center fade-in">
<div class="bg-white rounded-[2rem] p-6 w-[85%] max-w-sm shadow-2xl">
<h3 class="text-xl font-bold text-slate-900 mb-4" id="modal-title">处理工单</h3>
<p class="text-sm text-slate-500 mb-6" id="modal-task-title">...</p>
<input type="hidden" id="handle-action-type">
<textarea id="handle-note" class="w-full bg-slate-50 rounded-xl p-3 text-sm mb-4 outline-none border border-slate-100" rows="3" placeholder="请输入处理备注..."></textarea>
<div class="flex gap-3">
<button onclick="$('#handle-modal').addClass('hidden')" class="flex-1 py-3 rounded-xl bg-slate-100 text-slate-600 font-bold text-sm">取消</button>
<button onclick="submitHandle()" class="flex-1 py-3 rounded-xl bg-[#3B82F6] text-white font-bold text-sm shadow-md" id="modal-submit-btn">确认</button>
</div>
</div>
</div>
<div id="detail-modal" class="fixed inset-0 z-[70] hidden">
<div class="absolute inset-0 bg-black/40 backdrop-blur-sm transition-opacity" onclick="closeDetailModal()"></div>
<div class="absolute bottom-0 left-0 right-0 bg-white rounded-t-[2rem] p-6 max-h-[90vh] overflow-y-auto modal-enter flex flex-col">
<div class="w-12 h-1.5 bg-gray-200 rounded-full mx-auto mb-6 shrink-0"></div>
<div class="flex justify-between items-start mb-6 shrink-0">
<div>
<div class="flex items-center gap-2 mb-1">
<span id="detail-no" class="text-[10px] text-gray-400 font-mono">REP...</span>
<span id="detail-type" class="text-[10px] px-1.5 py-0.5 rounded bg-gray-100 text-gray-600 font-medium">类型</span>
</div>
<h3 id="detail-title" class="text-xl font-bold text-slate-900 leading-tight">加载中...</h3>
</div>
<button onclick="closeDetailModal()" class="text-gray-400 p-1 -mr-2"><i data-lucide="x" width="24"></i></button>
</div>
<div class="flex-1 overflow-y-auto space-y-6 pb-6">
<div class="grid grid-cols-2 gap-4">
<div class="bg-gray-50 p-3 rounded-xl"><p class="text-xs text-gray-400 mb-1">报修人</p><p id="detail-reporter" class="text-sm font-medium text-slate-800">--</p></div>
<div class="bg-gray-50 p-3 rounded-xl"><p class="text-xs text-gray-400 mb-1">联系电话</p><p id="detail-phone" class="text-sm font-medium text-slate-800 font-mono">--</p></div>
<div class="bg-gray-50 p-3 rounded-xl"><p class="text-xs text-gray-400 mb-1">位置</p><p id="detail-location" class="text-sm font-medium text-slate-800 break-words">--</p></div>
<div class="bg-gray-50 p-3 rounded-xl"><p class="text-xs text-gray-400 mb-1">紧急程度</p><p id="detail-urgency" class="text-sm font-medium text-slate-800">--</p></div>
<div class="bg-gray-50 p-3 rounded-xl col-span-2"><p class="text-xs text-gray-400 mb-1">申请时间</p><p id="detail-date" class="text-sm font-medium text-slate-800 font-mono">--</p></div>
</div>
<div><h4 class="text-sm font-bold text-slate-900 mb-2">故障描述</h4><div class="bg-gray-50 rounded-xl p-4 text-sm text-slate-600 leading-relaxed" id="detail-desc">--</div></div>
<div id="process-section" class="hidden border-t border-dashed border-gray-200 pt-6">
<h4 class="text-sm font-bold text-slate-900 mb-2">维修进度</h4>
<div class="bg-indigo-50/50 rounded-xl p-4 space-y-3">
<div id="assigned-info" class="hidden"><p class="text-xs text-indigo-400 mb-0.5">指派时间</p><p id="detail-assigned-at" class="text-sm font-medium text-indigo-900 font-mono">--</p></div>
<div id="completed-info" class="hidden">
<p class="text-xs text-indigo-400 mb-0.5 mt-2">完成说明</p><p id="detail-notes" class="text-sm font-medium text-indigo-900">--</p>
<p class="text-xs text-indigo-400 mb-0.5 mt-2">实际完成时间</p><p id="detail-completed-at" class="text-sm font-medium text-indigo-900 font-mono">--</p>
</div>
</div>
</div>
<div id="evaluation-section" class="hidden border-t border-dashed border-gray-200 pt-6">
<h4 class="text-sm font-bold text-slate-900 mb-4 flex items-center gap-1.5"><i data-lucide="star" width="16" class="text-yellow-500"></i> 业主评价</h4>
<div class="bg-yellow-50/50 rounded-xl p-4">
<div class="flex items-center gap-1 text-yellow-500 mb-2" id="display-stars"></div>
<p id="display-comment" class="text-sm text-slate-600 italic">"默认好评"</p>
</div>
</div>
</div>
</div>
</div>
<div id="resident-detail-modal" class="fixed inset-0 z-[70] hidden">
<div class="absolute inset-0 bg-black/40 backdrop-blur-sm transition-opacity" onclick="closeResidentDetailModal()"></div>
<div class="absolute bottom-0 left-0 right-0 bg-white rounded-t-[2rem] p-6 max-h-[85vh] overflow-y-auto modal-enter flex flex-col">
<div class="w-12 h-1.5 bg-gray-200 rounded-full mx-auto mb-6 shrink-0"></div>
<div class="flex justify-between items-start mb-6 shrink-0 relative">
<button onclick="confirmDeleteResident()" class="p-2 -ml-2 text-red-400 hover:text-red-600 bg-red-50 hover:bg-red-100 rounded-full transition-colors">
<i data-lucide="trash-2" width="20"></i>
</button>
<h3 class="text-xl font-bold text-slate-900 absolute left-1/2 -translate-x-1/2">住户档案</h3>
<button onclick="closeResidentDetailModal()" class="text-gray-400 p-1 -mr-2"><i data-lucide="x" width="24"></i></button>
</div>
<div class="flex flex-col items-center mb-6">
<div class="w-20 h-20 rounded-full bg-blue-50 text-blue-500 flex items-center justify-center text-2xl font-bold border-4 border-white shadow-md mb-3" id="res-detail-avatar">U</div>
<h2 id="res-detail-name" class="text-2xl font-bold text-slate-900">--</h2>
<div id="res-detail-status" class="mt-1 px-3 py-0.5 rounded-full text-xs font-bold bg-green-100 text-green-600">正常</div>
</div>
<div class="space-y-4">
<div class="bg-gray-50 rounded-2xl p-4">
<h4 class="text-sm font-bold text-slate-900 mb-3 flex items-center gap-2"><i data-lucide="home" width="16" class="text-blue-500"></i> 房屋信息</h4>
<div class="grid grid-cols-2 gap-y-3 text-sm">
<div><p class="text-gray-400 text-xs">地址</p><p id="res-detail-address" class="font-medium text-slate-800">--</p></div>
<div><p class="text-gray-400 text-xs">面积</p><p id="res-detail-area" class="font-medium text-slate-800">--</p></div>
<div><p class="text-gray-400 text-xs">入住时间</p><p id="res-detail-date" class="font-medium text-slate-800">--</p></div>
<div><p class="text-gray-400 text-xs">类型</p><p id="res-detail-type" class="font-medium text-slate-800">--</p></div>
</div>
</div>
<div class="bg-gray-50 rounded-2xl p-4">
<h4 class="text-sm font-bold text-slate-900 mb-3 flex items-center gap-2"><i data-lucide="phone" width="16" class="text-green-500"></i> 联系方式</h4>
<div class="flex items-center justify-between">
<div><p class="text-gray-400 text-xs">手机号码</p><p id="res-detail-phone" class="font-medium text-slate-800 text-lg">--</p></div>
<a id="res-detail-call" href="#" class="w-10 h-10 rounded-full bg-green-500 text-white flex items-center justify-center shadow-md active:scale-95 transition-transform"><i data-lucide="phone" width="20"></i></a>
</div>
</div>
</div>
</div>
</div>
<div id="delete-confirm-modal" class="fixed inset-0 bg-black/40 z-[80] hidden flex items-center justify-center fade-in">
<div class="bg-white rounded-[2rem] p-6 w-[85%] max-w-sm shadow-2xl text-center">
<div class="w-12 h-12 bg-red-50 text-red-500 rounded-full flex items-center justify-center mx-auto mb-4">
<i data-lucide="alert-triangle" width="24"></i>
</div>
<h3 class="text-xl font-bold text-slate-900 mb-2">确认删除住户?</h3>
<p class="text-slate-500 text-sm mb-6 leading-relaxed">删除后该账号将无法登录,<br>但历史数据会被保留。此操作不可撤销。</p>
<div class="flex gap-3">
<button onclick="$('#delete-confirm-modal').addClass('hidden')" class="flex-1 py-3 rounded-xl bg-slate-100 text-slate-600 font-bold text-sm">取消</button>
<button onclick="executeDeleteResident()" class="flex-1 py-3 rounded-xl bg-red-500 text-white font-bold text-sm shadow-md shadow-red-200">确认删除</button>
</div>
</div>
</div>
<div id="delete-announcement-modal" class="fixed inset-0 bg-black/40 z-[80] hidden flex items-center justify-center fade-in">
<div class="bg-white rounded-[2rem] p-6 w-[85%] max-w-sm shadow-2xl text-center">
<div class="w-12 h-12 bg-red-50 text-red-500 rounded-full flex items-center justify-center mx-auto mb-4">
<i data-lucide="alert-triangle" width="24"></i>
</div>
<h3 class="text-xl font-bold text-slate-900 mb-2">确认删除公告?</h3>
<p class="text-slate-500 text-sm mb-6 leading-relaxed">删除后公告将从系统中移除。<br>此操作不可撤销。</p>
<div class="flex gap-3">
<button onclick="$('#delete-announcement-modal').addClass('hidden')" class="flex-1 py-3 rounded-xl bg-slate-100 text-slate-600 font-bold text-sm">取消</button>
<button onclick="executeDeleteAnnouncement()" class="flex-1 py-3 rounded-xl bg-red-500 text-white font-bold text-sm shadow-md shadow-red-200">确认删除</button>
</div>
</div>
</div>
<div id="announcement-modal" class="fixed inset-0 bg-black/40 z-[60] hidden flex items-center justify-center fade-in">
<div class="bg-white rounded-[2rem] p-6 w-[90%] max-w-md shadow-2xl">
<h3 class="text-xl font-bold text-slate-900 mb-6">发布新公告</h3>
<div class="space-y-4">
<input id="anno-title" class="w-full bg-slate-50 rounded-xl px-4 py-3 text-sm outline-none border border-slate-100" placeholder="公告标题">
<div class="flex gap-2">
<select id="anno-type" class="flex-1 bg-slate-50 rounded-xl px-4 py-3 text-sm outline-none border border-slate-100">
<option value="notice">普通通知</option>
<option value="emergency">紧急通知</option>
<option value="maintenance">维修通知</option>
<option value="activity">社区活动</option>
</select>
<select id="anno-priority" class="flex-1 bg-slate-50 rounded-xl px-4 py-3 text-sm outline-none border border-slate-100"><option value="1">普通</option><option value="2">高</option><option value="3">紧急</option></select>
</div>
<div>
<label class="text-xs text-slate-400 ml-1 mb-1 block">有效期至 (可选)</label>
<input id="anno-expire" type="date" class="w-full bg-slate-50 rounded-xl px-4 py-3 text-sm outline-none border border-slate-100">
</div>
<textarea id="anno-content" class="w-full bg-slate-50 rounded-xl p-3 text-sm outline-none border border-slate-100" rows="4" placeholder="公告内容..."></textarea>
</div>
<div class="flex gap-3 mt-6">
<button onclick="$('#announcement-modal').addClass('hidden')" class="flex-1 py-3 rounded-xl bg-slate-100 text-slate-600 font-bold text-sm">取消</button>
<button onclick="submitAnnouncement()" class="flex-1 py-3 rounded-xl bg-[#3B82F6] text-white font-bold text-sm shadow-md">发布</button>
</div>
</div>
</div>
<div id="announcement-view-modal" class="fixed inset-0 z-[70] hidden">
<div class="absolute inset-0 bg-black/40 backdrop-blur-sm transition-opacity" onclick="closeAnnouncementViewModal()"></div>
<div class="absolute bottom-0 left-0 right-0 bg-white rounded-t-[2rem] p-6 max-h-[80vh] overflow-y-auto modal-enter flex flex-col">
<div class="w-12 h-1.5 bg-gray-200 rounded-full mx-auto mb-6 shrink-0"></div>
<div class="flex justify-between items-start mb-6 shrink-0">
<div>
<div class="flex items-center gap-2 mb-2">
<span id="view-anno-type" class="px-2.5 py-0.5 bg-blue-100 text-blue-600 rounded text-[10px] font-bold">通知</span>
<span id="view-anno-priority" class="px-2.5 py-0.5 bg-red-100 text-red-600 rounded text-[10px] font-bold hidden">紧急</span>
</div>
<h3 id="view-anno-title" class="text-xl font-bold text-slate-900 leading-tight">加载中...</h3>
<p id="view-anno-meta" class="text-xs text-gray-400 mt-2">--</p>
</div>
<button onclick="closeAnnouncementViewModal()" class="text-gray-400 p-1 -mr-2"><i data-lucide="x" width="24"></i></button>
</div>
<div class="flex-1 overflow-y-auto pb-6">
<p id="view-anno-content" class="text-slate-600 text-sm leading-relaxed whitespace-pre-wrap">--</p>
</div>
<div class="pt-4 border-t border-slate-100">
<button onclick="deleteAnnouncement()" class="w-full py-3 rounded-xl bg-red-50 text-red-500 font-bold text-sm hover:bg-red-100 transition-colors flex items-center justify-center gap-2">
<i data-lucide="trash-2" width="18"></i> 删除此公告
</button>
</div>
</div>
</div>
<div id="add-resident-modal" class="fixed inset-0 bg-black/40 z-[60] hidden flex items-center justify-center fade-in">
<div class="bg-white rounded-[2rem] p-6 w-[90%] max-w-md shadow-2xl">
<h3 class="text-xl font-bold text-slate-900 mb-6">录入新业主</h3>
<div class="space-y-4">
<div class="grid grid-cols-2 gap-3">
<input id="res-name" class="bg-slate-50 rounded-xl px-4 py-3 text-sm outline-none border border-slate-100 focus:ring-2 focus:ring-emerald-500" placeholder="真实姓名 (必填)">
<input id="res-phone" type="tel" class="bg-slate-50 rounded-xl px-4 py-3 text-sm outline-none border border-slate-100 focus:ring-2 focus:ring-emerald-500" placeholder="手机号码 (必填)">
</div>
<input id="res-idcard" class="w-full bg-slate-50 rounded-xl px-4 py-3 text-sm outline-none border border-slate-100 focus:ring-2 focus:ring-emerald-500" placeholder="身份证号 (选填)">
<input id="res-password" type="text" class="w-full bg-slate-50 rounded-xl px-4 py-3 text-sm outline-none border border-slate-100 focus:ring-2 focus:ring-emerald-500" placeholder="初始密码 (默认: 123456)">
<div class="grid grid-cols-3 gap-2">
<input id="res-building" class="bg-slate-50 rounded-xl px-2 py-3 text-sm text-center outline-none border border-slate-100 focus:ring-2 focus:ring-emerald-500" placeholder="楼栋号">
<input id="res-unit" class="bg-slate-50 rounded-xl px-2 py-3 text-sm text-center outline-none border border-slate-100 focus:ring-2 focus:ring-emerald-500" placeholder="单元号">
<input id="res-room" class="bg-slate-50 rounded-xl px-2 py-3 text-sm text-center outline-none border border-slate-100 focus:ring-2 focus:ring-emerald-500" placeholder="房号">
</div>
</div>
<div class="flex gap-3 mt-6">
<button onclick="$('#add-resident-modal').addClass('hidden')" class="flex-1 py-3 rounded-xl bg-slate-100 text-slate-600 font-bold text-sm">取消</button>
<button onclick="submitAddResident()" class="flex-1 py-3 rounded-xl bg-[#10B981] text-white font-bold text-sm shadow-md">确认录入</button>
</div>
</div>
</div>
<div id="create-bill-modal" class="fixed inset-0 bg-black/40 z-[60] hidden flex items-center justify-center fade-in">
<div class="bg-white rounded-[2rem] p-6 w-[90%] max-w-md shadow-2xl">
<h3 class="text-xl font-bold text-slate-900 mb-6">创建新账单</h3>
<div class="space-y-4">
<div>
<label class="text-xs text-slate-400 ml-1 mb-1 block">选择业主</label>
<select id="bill-owner" class="w-full bg-slate-50 rounded-xl px-4 py-3 text-sm outline-none border border-slate-100 appearance-none">
<option value="">加载中...</option>
</select>
</div>
<div>
<label class="text-xs text-slate-400 ml-1 mb-1 block">账单类型 & 标题</label>
<div class="flex gap-2">
<select id="bill-type" class="w-1/3 bg-slate-50 rounded-xl px-2 py-3 text-sm outline-none border border-slate-100">
<option value="property">物业费</option>
<option value="water">水费</option>
<option value="electricity">电费</option>
<option value="parking">停车费</option>
</select>
<input id="bill-title" class="flex-1 bg-slate-50 rounded-xl px-4 py-3 text-sm outline-none border border-slate-100" placeholder="例如:2023年12月物业费">
</div>
</div>
<div>
<label class="text-xs text-slate-400 ml-1 mb-1 block">金额 (元)</label>
<input id="bill-amount" type="number" class="w-full bg-slate-50 rounded-xl px-4 py-3 text-sm outline-none border border-slate-100 font-mono" placeholder="0.00">
</div>
<div class="flex gap-2">
<div class="flex-1">
<label class="text-xs text-slate-400 ml-1 mb-1 block">账期 (YYYY-MM)</label>
<input id="bill-cycle" type="month" class="w-full bg-slate-50 rounded-xl px-2 py-3 text-sm outline-none border border-slate-100">
</div>
<div class="flex-1">
<label class="text-xs text-slate-400 ml-1 mb-1 block">截止日期</label>
<input id="bill-due" type="date" class="w-full bg-slate-50 rounded-xl px-2 py-3 text-sm outline-none border border-slate-100">
</div>
</div>
</div>
<div class="flex gap-3 mt-6">
<button onclick="$('#create-bill-modal').addClass('hidden')" class="flex-1 py-3 rounded-xl bg-slate-100 text-slate-600 font-bold text-sm">取消</button>
<button onclick="submitCreateBill()" class="flex-1 py-3 rounded-xl bg-amber-500 text-white font-bold text-sm shadow-md">创建</button>
</div>
</div>
</div>
<div id="change-password-modal" class="fixed inset-0 bg-black/40 z-[60] hidden flex items-center justify-center fade-in">
<div class="bg-white rounded-[2rem] p-6 w-[85%] max-w-sm shadow-2xl">
<h3 class="text-xl font-bold text-slate-900 mb-6">修改登录密码</h3>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">当前密码</label>
<input type="password" id="old-pass" class="w-full bg-slate-50 border border-slate-200 rounded-xl px-4 py-3 outline-none focus:border-blue-500 transition-all">
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-1">新密码</label>
<input type="password" id="new-pass" class="w-full bg-slate-50 border border-slate-200 rounded-xl px-4 py-3 outline-none focus:border-blue-500 transition-all">
</div>
</div>
<div class="flex gap-3 mt-6">
<button onclick="$('#change-password-modal').addClass('hidden')" class="flex-1 py-3 rounded-xl bg-slate-100 text-slate-600 font-bold text-sm">取消</button>
<button onclick="submitChangePassword()" class="flex-1 py-3 rounded-xl bg-[#3B82F6] text-white font-bold text-sm shadow-md">确认修改</button>
</div>
</div>
</div>
<div id="view-system-logs" class="page-view hidden-view fade-in fixed inset-0 bg-[#F5F7FA] z-[70] overflow-y-auto">
<header class="px-6 pt-12 pb-4 bg-white sticky top-0 border-b border-slate-100">
<div class="flex items-center gap-2">
<button onclick="$('#view-system-logs').addClass('hidden-view')" class="p-1 -ml-1 text-slate-400 active:text-slate-600"><i data-lucide="chevron-left" width="28" height="28"></i></button>
<h2 class="text-2xl font-bold text-slate-900">操作日志</h2>
</div>
</header>
<main class="px-6 mt-4 pb-20 space-y-4" id="logs-list-container"></main>
</div>
<script>
const API_BASE = 'https://happy.kudosd.icu/api/v1';
const DEBUG_MODE = true;
const STATUS_MAP = {
'submitted': { text: '已提交', class: 'text-blue-600' },
'assigned': { text: '已指派', class: 'text-indigo-600' },
'processing': { text: '维修中', class: 'text-yellow-600' },
'completed': { text: '已完成', class: 'text-green-600' },
'cancelled': { text: '已取消', class: 'text-gray-500' },
'rejected': { text: '已驳回', class: 'text-red-600' }
};
const TYPE_MAP = { 'electrical': '电力', 'plumbing': '水路', 'elevator': '电梯', 'door_window': '门窗', 'other': '其他' };
const URGENCY_MAP = { 'low': '普通', 'medium': '中等', 'high': '重要', 'emergency': '紧急' };
const AppStorage = {
setItem: (k, v) => window.plus ? plus.storage.setItem(k, String(v)) : localStorage.setItem(k, v),
getItem: (k) => window.plus ? plus.storage.getItem(k) : localStorage.getItem(k),
removeItem: (k) => window.plus ? plus.storage.removeItem(k) : localStorage.removeItem(k)
};
const request = async (endpoint, method = 'GET', data = null) => {
const token = AppStorage.getItem('token');
if (DEBUG_MODE) {
console.log(`>>> [Request] ${method} ${API_BASE}${endpoint}`);
if (data) console.log('>>> [Request Body]:', JSON.stringify(data, null, 2));
}
return $.ajax({
url: `${API_BASE}${endpoint}`,
method: method,
contentType: 'application/json',
headers: { 'Authorization': `Bearer ${token}` },
data: data ? JSON.stringify(data) : undefined
}).then(res => {
if (DEBUG_MODE) {
console.log(`<<< [Response Success] ${method} ${endpoint}`);
try { console.log(JSON.stringify(res, null, 2)); } catch(e) { console.log(res); }
}
return res;
}).catch(err => {
if (DEBUG_MODE) {
console.error(`<<< [Response Error] ${method} ${endpoint}`);
try { console.error(JSON.stringify(err, null, 2)); if(err.responseText) console.error(err.responseText); } catch(e) { console.error(err); }
}
if (err.status === 401) { alert("登录过期"); window.location.href = 'index.html'; }
throw err;
});
};
let currentTaskId = null, currentTaskKind = null, currentOrderFilter = 'submitted';
let residentsCache = [];
let currentResidentId = null;
let currentAnnouncementId = null;
$(document).ready(function() {
if (window.lucide) lucide.createIcons();
if (window.plus) initDashboard();
else {
document.addEventListener('plusready', initDashboard, false);
if (navigator.userAgent.indexOf("Html5Plus") === -1) initDashboard();
}
});
function initDashboard() {
if (!AppStorage.getItem('token')) return window.location.href = 'index.html';
const user = JSON.parse(AppStorage.getItem('user_info') || '{}');
$('#setting-username').text(user.real_name || "Admin");
loadOverview();
loadDashboardTasks();
loadDashboardAnnouncements();
}
window.switchTab = function(tabName) {
$('.page-view').addClass('hidden-view');
$(`#view-${tabName}`).removeClass('hidden-view');
$('.nav-item').each(function() {
const isTarget = $(this).hasClass(`${tabName}-btn`);
const $indicator = $(this).find('.indicator');
if (isTarget) { $(this).removeClass('text-slate-400').addClass('text-[#3B82F6] -translate-y-1'); $indicator.removeClass('hidden'); }
else { $(this).addClass('text-slate-400').removeClass('text-[#3B82F6] -translate-y-1'); $indicator.addClass('hidden'); }
});
if (tabName === 'orders') loadOrdersList();
if (tabName === 'residents') loadResidentsList();
if (window.lucide) lucide.createIcons();
}
async function loadOverview() {
try {
const res = await request('/statistics/overview');
const data = res.data;
$('#stat-payment').text((data.payment_rate || 0) + '%');
$('#stat-satisfaction').text(data.owner_satisfaction || 0);
$('#stat-repair-count').text(data.new_repairs_count || 0);
$('#prog-payment').css('width', (data.payment_rate || 0) + '%');
} catch(e) {}
}
async function loadDashboardTasks() {
const repairRes = await request('/repairs?status=submitted&page_size=5');
const alertRes = await request('/alerts?status=pending&page_size=5');
const repairs = (repairRes.data.items || []).map(i => ({...i, _kind: 'repair'}));
const alerts = (alertRes.data.items || []).map(i => ({...i, _kind: 'alert'}));
renderTaskCards([...repairs, ...alerts].slice(0,5), '#dashboard-task-list');
}
// 新增:加载公告列表
async function loadDashboardAnnouncements() {
try {
const res = await request('/announcements?page=1&page_size=5');
const list = res.data.items || res.data.list || [];
const $container = $('#dashboard-announcement-list');
$container.empty();
if (list.length === 0) {
$container.html('<p class="text-center text-slate-400 text-sm">暂无公告</p>');
return;
}
list.forEach(item => {
const isUrgent = item.priority > 1;
const tagColor = isUrgent ? 'bg-red-100 text-red-600' : 'bg-blue-100 text-blue-600';
const tagText = isUrgent ? '紧急' : '通知';
const date = item.created_at ? item.created_at.split('T')[0] : '--';
const html = `
<div onclick="viewAnnouncement(${item.id})" class="bg-white rounded-[1.5rem] p-4 shadow-sm flex items-center justify-between active:scale-[0.99] transition-transform cursor-pointer">
<div class="flex-1 mr-4">
<div class="flex items-center gap-2 mb-1">
<span class="px-2 py-0.5 rounded text-[10px] font-bold ${tagColor}">${tagText}</span>
<span class="text-xs text-gray-400">${date}</span>
</div>
<h4 class="font-bold text-slate-800 text-sm truncate">${item.title}</h4>
</div>
<i data-lucide="chevron-right" class="text-gray-300" width="18"></i>
</div>
`;
$container.append(html);
});
if(window.lucide) lucide.createIcons();
} catch(e) { console.error("加载公告失败", e); }
}
// 新增:查看公告详情
window.viewAnnouncement = async function(id) {
currentAnnouncementId = id;
$('#announcement-view-modal').removeClass('hidden');
$('#view-anno-title').text('加载中...');
try {
const res = await request(`/announcements/${id}`);
const data = res.data;
$('#view-anno-title').text(data.title);
$('#view-anno-content').text(data.content);
const date = data.created_at ? data.created_at.split('T')[0] : '--';
const expire = data.expire_at ? data.expire_at.split('T')[0] : '永久';
$('#view-anno-meta').text(`发布于 ${date} • 有效期至 ${expire}`);
const isUrgent = data.priority > 1;
const typeMap = { 'notice': '普通通知', 'emergency': '紧急通知', 'maintenance': '维修通知', 'activity': '社区活动' };
$('#view-anno-type').text(typeMap[data.type] || '通知');
if (isUrgent) $('#view-anno-priority').removeClass('hidden');
else $('#view-anno-priority').addClass('hidden');
} catch(e) { alert('获取公告失败'); closeAnnouncementViewModal(); }
};
window.closeAnnouncementViewModal = () => $('#announcement-view-modal').addClass('hidden');
// 新增:删除公告
window.deleteAnnouncement = function() {
if(!currentAnnouncementId) return;
$('#delete-announcement-modal').removeClass('hidden');
};
window.executeDeleteAnnouncement = async function() {
try {
await request(`/announcements/${currentAnnouncementId}`, 'DELETE');
alert('删除成功');
$('#delete-announcement-modal').addClass('hidden');
closeAnnouncementViewModal();
loadDashboardAnnouncements();
} catch(e) {
alert('删除失败: ' + (e.responseJSON?.message || '未知错误'));
}
};
window.filterOrders = function(status) {
currentOrderFilter = status;
$('.order-filter-btn').removeClass('bg-white shadow-sm text-slate-600').addClass('text-slate-400');
$(`.order-filter-btn[data-status="${status}"]`).addClass('bg-white shadow-sm text-slate-600').removeClass('text-slate-400');
loadOrdersList();
}
async function loadOrdersList() {
const $container = $('#orders-list-container');
$container.html('<div class="flex justify-center py-8"><i data-lucide="loader-2" class="animate-spin text-slate-300"></i></div>');
if(window.lucide) lucide.createIcons();
let tasks = [];
try {
if (currentOrderFilter === 'active') {
const [res1, res2] = await Promise.all([request('/repairs?status=assigned'), request('/repairs?status=processing')]);
tasks = [...(res1.data.items||[]), ...(res2.data.items||[])].map(i => ({...i, _kind: 'repair'}));
} else {
const res = await request(`/repairs?status=${currentOrderFilter}`);
tasks = (res.data.items || []).map(i => ({...i, _kind: 'repair'}));
}
if(tasks.length === 0) $container.html('<p class="text-center text-slate-400 mt-10">暂无相关工单</p>');
else renderTaskCards(tasks, '#orders-list-container');
} catch(e) { $container.html('<p class="text-center text-slate-400 mt-10">加载失败</p>'); }
}
function renderTaskCards(tasks, containerSelector) {
const $container = $(containerSelector);
$container.empty();
tasks.forEach(item => {
let icon = 'wrench', title = item.title, desc = item.location,
tagColor, tagText, btnText, btnAction;
if (item._kind === 'alert' || item.alert_level) {
icon = 'siren'; title = (item.device_name || '设备') + " 异常"; desc = item.message;
tagColor = 'bg-red-500 text-white animate-pulse'; tagText = '报警';
btnText = '去处理';
btnAction = `openHandleModal('alert', ${item.id}, '${title}', 'handle')`;
} else {
const status = item.status;
if (status === 'submitted') {
tagColor = 'bg-orange-100 text-orange-600'; tagText = '待处理';
btnText = '派单'; btnAction = `openHandleModal('repair', ${item.id}, '${item.title}', 'assign')`;
} else if (status === 'assigned') {
tagColor = 'bg-indigo-100 text-indigo-600'; tagText = '已指派';
btnText = '开始'; btnAction = `openHandleModal('repair', ${item.id}, '${item.title}', 'start_process')`;
} else if (status === 'processing') {
tagColor = 'bg-blue-100 text-blue-600'; tagText = '维修中';
btnText = '完成'; btnAction = `openHandleModal('repair', ${item.id}, '${item.title}', 'complete')`;
} else if (status === 'completed') {
tagColor = 'bg-green-100 text-green-600'; tagText = '已完成';
btnText = '详情'; btnAction = `openDetailModal('repair', ${item.id})`;
}
}
const clickAction = (item._kind === 'repair') ? `onclick="openDetailModal('repair', ${item.id})"` : '';
const html = `
<div ${clickAction} class="bg-white rounded-[1.5rem] p-5 shadow-[0_2px_10px_rgb(0,0,0,0.03)] flex items-center justify-between active:scale-[0.99] transition-transform cursor-pointer">
<div class="flex items-center gap-4 overflow-hidden">
<div class="w-12 h-12 rounded-2xl bg-slate-50 flex items-center justify-center shrink-0 text-slate-600"><i data-lucide="${icon}" width="24" height="24"></i></div>
<div class="min-w-0">
<div class="flex items-center gap-2 mb-1"><h4 class="font-bold text-slate-800 truncate">${title}</h4><span class="text-[10px] px-2 py-0.5 rounded-full font-bold ${tagColor}">${tagText}</span></div>
<p class="text-xs text-slate-400 truncate">${desc} • ${item.created_at.split('T')[0]}</p>
</div>
</div>
<button onclick="event.stopPropagation(); ${btnAction}" class="ml-2 px-5 py-2 bg-slate-900 text-white text-xs font-bold rounded-xl shadow-md active:scale-95 transition-transform shrink-0">${btnText}</button>
</div>`;
$container.append(html);
});
if (window.lucide) lucide.createIcons();
}
window.openHandleModal = function(kind, id, title, actionType) {
currentTaskId = id; currentTaskKind = kind; $('#handle-action-type').val(actionType);
$('#modal-task-title').text(title); $('#handle-note').val('');
let btnText = '确认';
if(actionType === 'assign') { $('#modal-title').text('指派维修人员'); btnText='确认指派'; }
else if(actionType === 'start_process') { $('#modal-title').text('开始维修'); btnText='确认开始'; }
else if(actionType === 'complete') { $('#modal-title').text('完成维修'); btnText='确认完成'; }
$('#modal-submit-btn').text(btnText);
$('#handle-modal').removeClass('hidden');
}
window.openDetailModal = async function(kind, id) {
if (kind !== 'repair') return;
$('#detail-modal').removeClass('hidden');
$('#detail-title').text('加载中...');
$('#process-section, #evaluation-section').addClass('hidden');
try {
const res = await request(`/repairs/${id}`);
const data = res.data;
$('#detail-title').text(data.title);
$('#detail-no').text(data.repair_no);
$('#detail-type').text(TYPE_MAP[data.repair_type] || '其他');
$('#detail-urgency').text(URGENCY_MAP[data.urgency] || '普通');
$('#detail-location').text(data.location);
$('#detail-desc').text(data.description);
$('#detail-date').text(data.created_at.split('T')[0]);
$('#detail-phone').text(data.contact_phone);
const reporter = data.owner_info ? (data.owner_info.real_name || '业主') : '未知业主';
$('#detail-reporter').text(reporter);
if (['assigned', 'processing', 'completed'].includes(data.status)) {
$('#process-section').removeClass('hidden');
$('#assigned-info, #completed-info').removeClass('hidden');
$('#detail-assigned-at').text(data.assigned_at ? data.assigned_at.replace('T',' ') : '-');
$('#detail-completed-at').text(data.actual_completion ? data.actual_completion.replace('T',' ') : '-');
$('#detail-notes').text(data.completion_notes || '暂无备注');
}
if (data.status === 'completed' && data.rating) {
$('#evaluation-section').removeClass('hidden');
let stars = '';
for(let i=0; i<data.rating; i++) stars += '<i data-lucide="star" width="16" fill="currentColor"></i>';
$('#display-stars').html(stars);
$('#display-comment').text(data.evaluation || "默认好评");
}
if (window.lucide) lucide.createIcons();
} catch (e) { alert('加载详情失败'); closeDetailModal(); }
}
window.closeDetailModal = function() { $('#detail-modal').addClass('hidden'); }
window.submitHandle = async function() {
const note = $('#handle-note').val();
const actionType = $('#handle-action-type').val();
const id = currentTaskId;
try {
if (currentTaskKind === 'alert') {
await request(`/alerts/${id}/handle`, 'PUT', { handled_notes: note, status: 'handled' });
} else {
if (actionType === 'assign') await request(`/repairs/${id}/assign`, 'PUT', { assigned_to: 1, estimated_completion: new Date().toISOString() });
else if (actionType === 'start_process') await request(`/repairs/${id}/status`, 'PUT', { status: 'processing', completion_notes: note });
else if (actionType === 'complete') await request(`/repairs/${id}/status`, 'PUT', { status: 'completed', completion_notes: note });
}
alert('操作成功'); $('#handle-modal').addClass('hidden');
loadDashboardTasks(); if ($('#view-orders').is(':visible')) loadOrdersList();
} catch(e) { alert("操作失败:" + (e.responseJSON ? e.responseJSON.message : "未知错误")); }
}
// --- 住户列表与详情 ---
async function loadResidentsList() {
const keyword = $('#resident-search').val().toLowerCase();
const res = await request('/owners');
let list = (res.data.items || res.data.list || []).filter(r => {
const name = r.real_name || (r.user && r.user.real_name) || '';
const roomInfo = `${r.building}-${r.unit}-${r.room}`;
return !keyword || name.includes(keyword) || roomInfo.includes(keyword);
});
residentsCache = list;
const $container = $('#residents-list-container');
$container.empty();
if(list.length===0) return $container.html('<p class="text-center text-slate-400 mt-10">无数据</p>');
list.forEach((r, idx) => {
const name = r.real_name || (r.user && r.user.real_name) || '未知姓名';
const avatar = name[0] || 'U';
const html = `
<div onclick="openResidentDetail(${idx})" class="bg-white rounded-[1.5rem] p-4 flex items-center justify-between shadow-sm active:scale-[0.99] transition-transform cursor-pointer">
<div class="flex items-center gap-4">
<div class="w-12 h-12 rounded-full bg-blue-50 text-blue-500 flex items-center justify-center font-bold text-lg">${avatar}</div>
<div>
<h4 class="font-bold text-slate-900">${name}</h4>
<p class="text-xs text-slate-400">${r.building}栋-${r.unit}单元-${r.room}</p>
</div>
</div>
<div class="flex gap-2">
<a href="tel:${r.phone}" onclick="event.stopPropagation()" class="w-9 h-9 rounded-full bg-slate-100 flex items-center justify-center text-slate-600"><i data-lucide="phone" width="16"></i></a>
</div>
</div>`;
$container.append(html);
});
if(window.lucide) lucide.createIcons();
}
$('#resident-search').on('input', loadResidentsList);
window.openResidentDetail = function(idx) {
const data = residentsCache[idx];
if (!data) return;
currentResidentId = data.id;
const name = data.real_name || (data.user && data.user.real_name) || '未知';
$('#res-detail-avatar').text(name[0] || 'U');
$('#res-detail-name').text(name);
$('#res-detail-address').text(`${data.building}栋 ${data.unit}单元 ${data.room}室`);
$('#res-detail-area').text(data.area ? `${data.area} ㎡` : '未录入');
$('#res-detail-date').text(data.move_in_date || '未录入');
$('#res-detail-type').text(data.owner_type === 'owner' ? '业主' : '租户');
$('#res-detail-phone').text(data.phone);
$('#res-detail-call').attr('href', `tel:${data.phone}`);
$('#resident-detail-modal').removeClass('hidden');
};
window.closeResidentDetailModal = () => $('#resident-detail-modal').addClass('hidden');
// === 删除住户 ===
window.confirmDeleteResident = function() { $('#delete-confirm-modal').removeClass('hidden'); };
window.executeDeleteResident = async function() {
if (!currentResidentId) return;
try {
await request(`/owners/${currentResidentId}`, 'DELETE');
alert('删除成功'); $('#delete-confirm-modal').addClass('hidden'); $('#resident-detail-modal').addClass('hidden'); loadResidentsList();
} catch (e) { alert('删除失败: ' + (e.responseJSON?.message || '未知错误')); }
};
// --- 弹窗功能集合 ---
window.openAddResidentModal = () => {
$('#res-name').val(''); $('#res-phone').val(''); $('#res-idcard').val(''); $('#res-password').val('');
$('#res-building').val(''); $('#res-unit').val(''); $('#res-room').val('');
$('#add-resident-modal').removeClass('hidden');
};
window.submitAddResident = async () => {
const payload = { real_name: $('#res-name').val(), phone: $('#res-phone').val(), id_card: $('#res-idcard').val(), password: $('#res-password').val() || '123456', building: $('#res-building').val(), unit: $('#res-unit').val(), room: $('#res-room').val() };
if(!payload.phone || !payload.real_name || !payload.building || !payload.room) return alert('请补全必填信息');
try { await request('/owners', 'POST', payload); alert('录入成功'); $('#add-resident-modal').addClass('hidden'); if ($('#view-residents').is(':visible')) loadResidentsList(); } catch(e) { alert('录入失败: ' + (e.responseJSON?.message || '未知错误')); }
};
// 新增:建账单逻辑
window.openCreateBillModal = async () => {
$('#create-bill-modal').removeClass('hidden');
// 加载业主下拉框
try {
const res = await request('/owners?page=1&page_size=100');
const list = res.data.items || res.data.list || [];
const $select = $('#bill-owner');
$select.empty();
list.forEach(o => {
const name = o.real_name || (o.user && o.user.real_name) || '未知';
$select.append(`<option value="${o.id}">${name} - ${o.building}-${o.unit}-${o.room}</option>`);
});
} catch(e) { alert('加载业主列表失败'); }
};
window.submitCreateBill = async () => {
const ownerId = $('#bill-owner').val();
const type = $('#bill-type').val();
const title = $('#bill-title').val();
const amount = $('#bill-amount').val();
const cycle = $('#bill-cycle').val();
const due = $('#bill-due').val();
if(!ownerId || !title || !amount || !cycle || !due) return alert('请填写完整信息');
const payload = {
owner_id: parseInt(ownerId),
type: type,
title: title,
amount: parseFloat(amount),
billing_cycle: cycle, // YYYY-MM
due_date: due // YYYY-MM-DD
};
try {
await request('/bills', 'POST', payload);
alert('账单创建成功');
$('#create-bill-modal').addClass('hidden');
} catch(e) {
alert('创建失败: ' + (e.responseJSON?.message || '未知错误'));
}
};
window.openAnnouncementModal = () => $('#announcement-modal').removeClass('hidden');
window.submitAnnouncement = async () => {
const p = {title:$('#anno-title').val(), content:$('#anno-content').val(), type:$('#anno-type').val(), priority:parseInt($('#anno-priority').val())};
// 增加过期时间字段
const expire = $('#anno-expire').val();
if(expire) p.expire_at = new Date(expire).toISOString();
if(!p.title) return alert('请填写');
try {
const res = await request('/announcements', 'POST', p);
// 自动发布
await request(`/announcements/${res.data.id}/publish`, 'PUT', { is_published: true });
alert('发布成功');
$('#announcement-modal').addClass('hidden');
loadDashboardAnnouncements();
} catch(e) { alert('发布失败'); }
};
window.openLogsModal = async () => {
$('#view-system-logs').removeClass('hidden-view');
const res = await request('/system/logs');
$('#logs-list-container').html((res.data.items||[]).map(l=>
`<div class="pl-4 border-l-2 border-slate-200 relative"><div class="absolute -left-[5px] top-0 w-2.5 h-2.5 bg-slate-300 rounded-full"></div><p class="text-xs text-slate-400 mb-1">${l.created_at||''}</p><h4 class="text-sm font-bold text-slate-800">${l.operation}</h4><p class="text-xs text-slate-500">ID: ${l.user_id}</p></div>`
).join(''));
};
window.openChangePasswordModal = () => { $('#old-pass').val(''); $('#new-pass').val(''); $('#change-password-modal').removeClass('hidden'); };
window.submitChangePassword = async () => {
const oldP = $('#old-pass').val(); const newP = $('#new-pass').val();
if(!oldP || !newP) return alert('请填写完整');
const userStr = AppStorage.getItem('user_info');
if (!userStr) return alert('无法获取用户信息');
const userId = JSON.parse(userStr).id;
try { await request(`/system/users/${userId}/password`, 'PUT', { old_password: oldP, new_password: newP }); alert('修改成功,请重新登录'); logout(); } catch(e) { alert('修改失败: ' + (e.responseJSON?.message || '原密码错误')); }
};
window.logout = () => { if(confirm('退出?')) { AppStorage.removeItem('token'); window.location.href='index.html'; } };
</script>
</body>
</html>