Ver código fonte

[add]

檀家一覧の全件タブと電話番号ありのタブ切り替えの処理
poohr 4 semanas atrás
pai
commit
31b42bced0

+ 16
- 15
src/app/pages/danka-list/danka-list.html Ver arquivo

@@ -15,14 +15,15 @@
15 15
           <input
16 16
             type="text"
17 17
             placeholder="氏名・ふりがな・住所・電話番号で探す"
18
+            [(ngModel)]="searchKeyword"
18 19
           />
19 20
         </div>
20 21
 
21
-        <button type="button" class="search-button">
22
+        <button type="button" class="search-button" (click)="searchDanka()">
22 23
           検索
23 24
         </button>
24 25
 
25
-        <button type="button" class="new-button">
26
+        <button type="button" class="new-button" routerLink="/danka-new">
26 27
           新規登録
27 28
         </button>
28 29
 
@@ -33,7 +34,7 @@
33 34
 
34 35
       <div class="filter-row">
35 36
         <div class="filter-button-list">
36
-          <button type="button" class="filter-button active">
37
+          <button type="button" class="filter-button" [class.active]="selectedFilter === 'all'" (click)="showAllDanka()">
37 38
             全件
38 39
           </button>
39 40
 
@@ -45,13 +46,13 @@
45 46
             法要あり
46 47
           </button>
47 48
 
48
-          <button type="button" class="filter-button">
49
+          <button type="button" class="filter-button" [class.active]="selectedFilter === 'phone'" (click)="filterPhoneAvailable()">
49 50
             電話番号あり
50 51
           </button>
51 52
         </div>
52 53
 
53 54
         <p class="result-count">
54
-          表示 124 件 / 1-20 件目
55
+          表示 {{ filterDankaList.length }} 件 / 全 {{ dankaList.length }} 件
55 56
         </p>
56 57
       </div>
57 58
 
@@ -65,16 +66,16 @@
65 66
             <div>家族</div>
66 67
           </div>
67 68
 
68
-          @for (danka of dankaList; track danka.id) {
69
-            <a class="danka-table-row" [routerLink]="['/danka-detail', danka.id]">
70
-              <div class="strong">{{ danka.householder }}</div>
71
-              <div>{{ danka.householdName }}</div>
72
-              <div>{{ danka.address }}</div>
73
-              <div>{{ danka.phones[0]?.tel }}</div>
74
-              <div>{{ danka.phones.length }}件</div>
75
-            </a>
76
-          }
77
-        </div>
69
+            @for (danka of filterDankaList; track danka.id) {
70
+              <a class="danka-table-row" [routerLink]="['/danka-detail', danka.id]">
71
+                <div class="strong">{{ danka.householder }}</div>
72
+                <div>{{ danka.householdName }}</div>
73
+                <div>{{ danka.address }}</div>
74
+                <div>{{ danka.phones[0]?.tel }}</div>
75
+                <div>{{ danka.phones.length }}件</div>
76
+              </a>
77
+            }
78
+          </div>
78 79
 
79 80
       </div>
80 81
     </section>

+ 49
- 1
src/app/pages/danka-list/danka-list.ts Ver arquivo

@@ -4,17 +4,65 @@ import { DankaService } from '../../services/dankaService';
4 4
 import { AppHeader } from '../../share/header/app-header';
5 5
 import { AppSideMenu } from '../../share/side-menu/app-side-menu';
6 6
 import { Danka } from '../../models/danka';
7
+import { FormsModule } from '@angular/forms';
8
+import { findIndex } from 'rxjs';
7 9
 
8 10
 @Component({
9 11
   selector: 'app-danka-list',
10
-  imports: [AppHeader, AppSideMenu, RouterLink],
12
+  imports: [AppHeader, AppSideMenu, RouterLink, FormsModule],
11 13
   templateUrl: './danka-list.html',
12 14
   styleUrl: './danka-list.scss',
13 15
 })
14 16
 export class DankaList {
15 17
   dankaList: Danka[] = [];
18
+  filterDankaList: Danka[] = [];
19
+  searchKeyword: string = '';
20
+  dankaDisplay: number = 0;
21
+  selectedFilter = 'all';
16 22
 
17 23
   constructor(private dankaService: DankaService) {
18 24
     this.dankaList = this.dankaService.getDankaList();
19 25
   }
26
+
27
+  //全件タグで絞り込み
28
+  showAllDanka() {
29
+    this.selectedFilter = 'all';
30
+    this.searchKeyword = '';
31
+    this.filterDankaList = this.dankaList;
32
+    this.dankaDisplay = this.filterDankaList.length;
33
+  }
34
+
35
+  //電話番号タグで絞り込み
36
+  filterPhoneAvailable() {
37
+    this.selectedFilter = 'phone';
38
+    //電話番号タブに該当する檀家を表示
39
+    this.filterDankaList = this.dankaList.filter((danka) => {
40
+      return danka.phones.some((phone) => phone.tel.trim() !== '');
41
+    });
42
+    this.dankaDisplay = this.filterDankaList.length;
43
+  }
44
+
45
+  //検索処理
46
+  searchDanka() {
47
+    this.selectedFilter = 'search';
48
+    //検索欄に入力された値から余白を削除
49
+    const keyword = this.searchKeyword.trim();
50
+    //検索欄が空の場合は檀家の一覧を表示
51
+    if (keyword === '') {
52
+      this.filterDankaList = this.dankaList;
53
+      return;
54
+    }
55
+    //検索欄に値がある場合は値に該当する内容を表示
56
+    this.filterDankaList = this.dankaList.filter((danka) => {
57
+      return (
58
+        danka.householdName.includes(keyword) ||
59
+        danka.householder.includes(keyword) ||
60
+        danka.postalCode.includes(keyword) ||
61
+        danka.address.includes(keyword) ||
62
+        danka.phones.some((phone) => phone.tel.includes(keyword) || phone.note.includes(keyword))
63
+      );
64
+    });
65
+    this.dankaDisplay = this.filterDankaList.length;
66
+    console.log(this.dankaDisplay);
67
+  }
20 68
 }

+ 17
- 2
src/app/services/dankaService.ts Ver arquivo

@@ -23,6 +23,23 @@ export class DankaService {
23 23
         },
24 24
       ],
25 25
     },
26
+    {
27
+      id: '2',
28
+      householdName: '古田家',
29
+      householder: '古田 太郎',
30
+      postalCode: '234-4567',
31
+      address: '市内 1-2-3',
32
+      phones: [
33
+        {
34
+          tel: '03-xxxx-xxxx',
35
+          note: '寺報連絡',
36
+        },
37
+        {
38
+          tel: '090-xxxx-xxxx',
39
+          note: '世帯主',
40
+        },
41
+      ],
42
+    }
26 43
   ];
27 44
 
28 45
   //サービスの檀家一覧の取得
@@ -53,6 +70,4 @@ export class DankaService {
53 70
     }
54 71
     this.dankaList.splice(index, 1);
55 72
   }
56
-
57
-
58 73
 }

Carregando…
Cancelar
Salvar