|
|
@@ -1,9 +1,107 @@
|
|
1
|
1
|
import { Component } from '@angular/core';
|
|
|
2
|
+import { FormBuilder, FormsModule } from '@angular/forms';
|
|
|
3
|
+import { Router, RouterLink } from '@angular/router';
|
|
|
4
|
+import { Danka } from '../../models/danka';
|
|
|
5
|
+import { Family } from '../../models/family';
|
|
|
6
|
+import { Kakocho } from '../../models/kakocho';
|
|
|
7
|
+import { DankaService } from '../../services/dankaService';
|
|
|
8
|
+import { FamilyService } from '../../services/family-service';
|
|
|
9
|
+import { KakochoService } from '../../services/kakocho-service';
|
|
|
10
|
+import { AppHeader } from '../../share/header/app-header';
|
|
|
11
|
+import { AppSideMenu } from '../../share/side-menu/app-side-menu';
|
|
2
|
12
|
|
|
3
|
13
|
@Component({
|
|
4
|
14
|
selector: 'app-search',
|
|
5
|
|
- imports: [],
|
|
|
15
|
+ imports: [AppHeader, AppSideMenu, FormsModule, RouterLink],
|
|
6
|
16
|
templateUrl: './search.html',
|
|
7
|
17
|
styleUrl: './search.scss',
|
|
8
|
18
|
})
|
|
9
|
|
-export class Search {}
|
|
|
19
|
+export class Search {
|
|
|
20
|
+ searchKeyword = '';
|
|
|
21
|
+ selectedSearchType = 'all';
|
|
|
22
|
+ searchTypeFilters = [
|
|
|
23
|
+ { label: 'すべて', value: 'all' },
|
|
|
24
|
+ { label: '檀家(世帯)', value: 'danka' },
|
|
|
25
|
+ { label: '家族', value: 'family' },
|
|
|
26
|
+ { label: '過去帳', value: 'kakocho' },
|
|
|
27
|
+ ];
|
|
|
28
|
+ dankaResults: Danka[] = [];
|
|
|
29
|
+ familyResults: Family[] = [];
|
|
|
30
|
+ kakochoResults: Kakocho[] = [];
|
|
|
31
|
+ totalResultCount = 0;
|
|
|
32
|
+
|
|
|
33
|
+ constructor(
|
|
|
34
|
+ private dankaService: DankaService,
|
|
|
35
|
+ private familyService: FamilyService,
|
|
|
36
|
+ private kakochoService: KakochoService,
|
|
|
37
|
+ ) {}
|
|
|
38
|
+
|
|
|
39
|
+ // フィルタータブの選択処理
|
|
|
40
|
+ changeSearchType(searchType: string): void {
|
|
|
41
|
+ this.selectedSearchType = searchType;
|
|
|
42
|
+ this.searchAll();
|
|
|
43
|
+ }
|
|
|
44
|
+
|
|
|
45
|
+ // 全検索の処理
|
|
|
46
|
+ searchAll() {
|
|
|
47
|
+ const keyword = this.searchKeyword.trim();
|
|
|
48
|
+ this.dankaResults = [];
|
|
|
49
|
+ this.familyResults = [];
|
|
|
50
|
+ this.kakochoResults = [];
|
|
|
51
|
+ this.totalResultCount = 0;
|
|
|
52
|
+ if (keyword === '') {
|
|
|
53
|
+ return;
|
|
|
54
|
+ }
|
|
|
55
|
+ // 檀家・家族・過去帳の情報を取得
|
|
|
56
|
+ const dankaList = this.dankaService.getDankaList();
|
|
|
57
|
+ const familyList = this.familyService.getFamilyList();
|
|
|
58
|
+ const kakochoList = this.kakochoService.getKakochoList();
|
|
|
59
|
+ //檀家のキーワード検索
|
|
|
60
|
+ if (this.selectedSearchType === 'all' || this.selectedSearchType === 'danka') {
|
|
|
61
|
+ this.dankaResults = dankaList.filter(
|
|
|
62
|
+ (danka) =>
|
|
|
63
|
+ danka.householdName.includes(keyword) ||
|
|
|
64
|
+ danka.householder.includes(keyword) ||
|
|
|
65
|
+ danka.postalCode.includes(keyword) ||
|
|
|
66
|
+ danka.address.includes(keyword) ||
|
|
|
67
|
+ danka.phones.some((phone) => phone.tel.includes(keyword) || phone.note.includes(keyword)),
|
|
|
68
|
+ );
|
|
|
69
|
+ }
|
|
|
70
|
+ //家族のキーワード検索
|
|
|
71
|
+ if (this.selectedSearchType === 'all' || this.selectedSearchType === 'family') {
|
|
|
72
|
+ this.familyResults = familyList.filter(
|
|
|
73
|
+ (family) =>
|
|
|
74
|
+ family.name.includes(keyword) ||
|
|
|
75
|
+ family.furigana.includes(keyword) ||
|
|
|
76
|
+ family.relationship.includes(keyword) ||
|
|
|
77
|
+ family.birthDate.includes(keyword) ||
|
|
|
78
|
+ family.note.includes(keyword),
|
|
|
79
|
+ );
|
|
|
80
|
+ }
|
|
|
81
|
+ //過去帳のキーワード検索
|
|
|
82
|
+ if (this.selectedSearchType === 'all' || this.selectedSearchType === 'kakocho') {
|
|
|
83
|
+ this.kakochoResults = kakochoList.filter(
|
|
|
84
|
+ (kakocho) =>
|
|
|
85
|
+ kakocho.name.includes(keyword) ||
|
|
|
86
|
+ kakocho.furigana.includes(keyword) ||
|
|
|
87
|
+ kakocho.relationship.includes(keyword) ||
|
|
|
88
|
+ kakocho.kaimyo.includes(keyword) ||
|
|
|
89
|
+ kakocho.deathDate.includes(keyword) ||
|
|
|
90
|
+ kakocho.ageAtDeath.includes(keyword) ||
|
|
|
91
|
+ kakocho.note.includes(keyword),
|
|
|
92
|
+ );
|
|
|
93
|
+ }
|
|
|
94
|
+ //検索結果の件数カウント
|
|
|
95
|
+ this.totalResultCount =
|
|
|
96
|
+ this.dankaResults.length + this.familyResults.length + this.kakochoResults.length;
|
|
|
97
|
+ }
|
|
|
98
|
+
|
|
|
99
|
+ clearSearch(): void {
|
|
|
100
|
+ this.searchKeyword = '';
|
|
|
101
|
+ this.selectedSearchType = 'all';
|
|
|
102
|
+ this.dankaResults = [];
|
|
|
103
|
+ this.familyResults = [];
|
|
|
104
|
+ this.kakochoResults = [];
|
|
|
105
|
+ this.totalResultCount = 0;
|
|
|
106
|
+ }
|
|
|
107
|
+}
|