kuni 3 주 전
부모
커밋
6ec4e0c177

+ 6
- 2
src/app/app.routes.ts 파일 보기

@@ -27,7 +27,11 @@ export const routes: Routes = [
27 27
     component: DankaEdit,
28 28
   },
29 29
   {
30
-    path: 'kakocho-edit/:id',
30
+    path: 'kakocho-edit/:dankaId',
31 31
     component: KakochoEdit,
32
-  }  
32
+  },
33
+  {
34
+    path: 'kakocho-edit/:dankaId/:kakochoId',
35
+    component: KakochoEdit,
36
+  }
33 37
 ];

+ 12
- 2
src/app/pages/danka-detail/danka-detail.html 파일 보기

@@ -66,6 +66,15 @@
66 66
               </button>
67 67
             </nav>
68 68
           </div>
69
+          @if (selectedTab === 'basic') {
70
+          <button
71
+            type="button"
72
+            class="edit-button"
73
+            [routerLink]="['/danka-edit', danka.id]"
74
+          >
75
+            編集
76
+          </button>
77
+          }
69 78
 
70 79
           @if (selectedTab === 'kakocho') {
71 80
           <button
@@ -75,15 +84,16 @@
75 84
           >
76 85
             故人を登録
77 86
           </button>
78
-          }
79 87
 
80 88
           <button
81 89
             type="button"
82 90
             class="edit-button"
83
-            [routerLink]="['/danka-edit', danka.id]"
91
+            [routerLink]="['/kakocho-edit', danka.id, kakocholist[0].id]"
84 92
           >
85 93
             編集
86 94
           </button>
95
+          }
96
+
87 97
         </div>
88 98
 
89 99
         <section class="family-summary">

+ 97
- 84
src/app/pages/kakocho-edit/kakocho-edit.html 파일 보기

@@ -1,7 +1,11 @@
1 1
 <app-header></app-header>
2 2
 
3 3
 <div class="breadcrumb">
4
-  ホーム &gt; 檀家(世帯) &gt; 編集
4
+  @if (kakocho) {
5
+    ホーム &gt; 檀家(世帯) &gt; 過去帳 &gt; 故人を編集
6
+  } @else {
7
+    ホーム &gt; 檀家(世帯) &gt; 過去帳 &gt; 故人を追加
8
+  }
5 9
 </div>
6 10
 
7 11
 <div class="danka-edit-page">
@@ -9,139 +13,148 @@
9 13
 
10 14
   <main class="danka-edit-main">
11 15
     <section class="edit-panel">
16
+
12 17
       <div class="page-title-area">
13
-        <h1>檀家(世帯)編集</h1>
18
+        <h1>
19
+          @if (kakocho) {
20
+            故人を編集
21
+          } @else {
22
+            故人を追加
23
+          }
24
+        </h1>
14 25
       </div>
15 26
 
16
-      <form [formGroup]="dankaForm" class="edit-form">
27
+      <form [formGroup]="kakochoForm" class="edit-form">
28
+
17 29
         <div class="edit-content">
30
+
18 31
           <section class="basic-edit-section">
19 32
             <h2>基本情報</h2>
20 33
 
21 34
             <div class="form-list">
35
+
36
+              <!-- 名前 -->
22 37
               <div class="form-row">
23
-                <label for="householdName">世帯名</label>
38
+                <label for="name">名前</label>
39
+
24 40
                 <div class="form-field">
25 41
                   <input
26
-                    id="householdName"
42
+                    id="name"
27 43
                     type="text"
28
-                    formControlName="householdName"
44
+                    formControlName="name"
29 45
                   />
30
-                  @if (dankaForm.get('householdName')?.invalid && dankaForm.get('householdName')?.touched) {
31
-                    <p class="error-message">世帯名を入力してください。</p>
46
+
47
+                  @if (kakochoForm.get('name')?.invalid && kakochoForm.get('name')?.touched) {
48
+                    <p class="error-message">
49
+                      名前を入力してください。
50
+                    </p>
32 51
                   }
33 52
                 </div>
34 53
               </div>
35 54
 
55
+              <!-- ふりがな -->
36 56
               <div class="form-row">
37
-                <label for="householder">世帯主</label>
38
-                <div class="form-field">
39
-                  <input
40
-                    id="householder"
41
-                    type="text"
42
-                    formControlName="householder"
43
-                  />
44
-                  @if (dankaForm.get('householder')?.invalid && dankaForm.get('householder')?.touched) {
45
-                    <p class="error-message">世帯主を入力してください。</p>
46
-                  }
47
-                </div>
57
+                <label for="furigana">ふりがな</label>
58
+
59
+                <input
60
+                  id="furigana"
61
+                  type="text"
62
+                  formControlName="furigana"
63
+                />
48 64
               </div>
49 65
 
66
+              <!-- 続柄 -->
50 67
               <div class="form-row">
51
-                <label for="postalCode">郵便番号</label>
52
-                <div class="form-field">
53
-                  <input
54
-                    id="postalCode"
55
-                    type="text"
56
-                    formControlName="postalCode"
57
-                  />
58
-                  @if (dankaForm.get('postalCode')?.invalid && dankaForm.get('postalCode')?.touched) {
59
-                    <p class="error-message">郵便番号を入力してください。</p>
60
-                  }
61
-                </div>
68
+                <label for="relationship">続柄</label>
69
+
70
+                <input
71
+                  id="relationship"
72
+                  type="text"
73
+                  formControlName="relationship"
74
+                />
62 75
               </div>
63 76
 
77
+              <!-- 戒名 -->
64 78
               <div class="form-row">
65
-                <label for="address">住所</label>
79
+                <label for="kaimyo">戒名</label>
80
+
66 81
                 <input
67
-                  id="address"
82
+                  id="kaimyo"
68 83
                   type="text"
69
-                  formControlName="address"
84
+                  formControlName="kaimyo"
70 85
                 />
71 86
               </div>
72
-            </div>
73
-          </section>
74 87
 
75
-          <section class="phone-edit-section">
76
-            <div class="section-heading">
77
-              <h2>電話番号(複数登録)</h2>
78
-              <p>番号と備考を複数登録できます。</p>
79
-            </div>
88
+              <!-- 没年月日 -->
89
+              <div class="form-row">
90
+                <label for="deathDate">没年月日</label>
80 91
 
81
-            <div formArrayName="phones" class="phone-table">
82
-              <div class="phone-table-header">
83
-                <div>番号</div>
84
-                <div>備考</div>
85
-                <div>操作</div>
92
+                <input
93
+                  id="deathDate"
94
+                  type="date"
95
+                  formControlName="deathDate"
96
+                />
86 97
               </div>
87 98
 
88
-              @for (phone of phones.controls; track $index; let i = $index) {
89
-                <div class="phone-table-row" [formGroupName]="i">
90
-                  <div>
91
-                    <input type="text" formControlName="tel" placeholder="電話番号"/>
92
-                    @if (phone.get('tel')?.invalid && phone.get('tel')?.touched) {
93
-                      <p class="phone-error-message">
94
-                        電話番号は数字とハイフンで入力してください。
95
-                      </p>
96
-                    }
97
-                  </div>
98
-
99
-                  <div>
100
-                    <input type="text" formControlName="note" placeholder="備考"/>
101
-                  </div>
102
-
103
-                  <div class="phone-row-action">
104
-                    <button type="button" class="remove-phone-button" [disabled]="phones.length === 1" (click)="removePhone(i)">
105
-                      削除
106
-                    </button>
107
-                  </div>
108
-                </div>
109
-              }
99
+              <!-- 行年 -->
100
+              <div class="form-row">
101
+                <label for="ageAtDeath">行年</label>
110 102
 
111
-            </div>
103
+                <input
104
+                  id="ageAtDeath"
105
+                  type="text"
106
+                  formControlName="ageAtDeath"
107
+                />
108
+              </div>
109
+
110
+              <!-- 備考 -->
111
+              <div class="form-row">
112
+                <label for="note">備考</label>
113
+
114
+                <textarea
115
+                  id="note"
116
+                  formControlName="note"
117
+                ></textarea>
118
+              </div>
112 119
 
113
-            <div class="phone-action">
114
-              <button
115
-                type="button"
116
-                class="add-phone-button"
117
-                (click)="addPhone()"
118
-              >
119
-                電話を追加
120
-              </button>
121 120
             </div>
122 121
           </section>
122
+
123 123
         </div>
124 124
 
125 125
         <div class="bottom-actions">
126
-          <button type="button" class="delete-button" (click)="deleteDanka()">
127
-            削除
128
-          </button>
129 126
 
130
-          <button type="button" class="cancel-button" [routerLink]="['/danka-detail', danka?.id]">
127
+          @if (kakocho) {
128
+            <button
129
+              type="button"
130
+              class="delete-button"
131
+              (click)="deleteKakocho()"
132
+            >
133
+              削除
134
+            </button>
135
+          }
136
+
137
+          <button
138
+            type="button"
139
+            class="cancel-button"
140
+            [routerLink]="['/kakocho-list']"
141
+          >
131 142
             キャンセル
132 143
           </button>
133 144
 
134 145
           <button
135 146
             type="button"
136 147
             class="save-button"
137
-            [disabled]="dankaForm.invalid"
138
-            (click)="saveDanka()"
148
+            [disabled]="kakochoForm.invalid"
149
+            (click)="saveKakocho()"
139 150
           >
140 151
             保存
141 152
           </button>
153
+
142 154
         </div>
155
+
143 156
       </form>
157
+
144 158
     </section>
145 159
   </main>
146
-</div>
147
-
160
+</div>

+ 116
- 82
src/app/pages/kakocho-edit/kakocho-edit.ts 파일 보기

@@ -1,124 +1,158 @@
1
-import { Component, inject } from '@angular/core';
1
+import { Component } from '@angular/core';
2 2
 import {
3 3
   FormBuilder,
4 4
   FormGroup,
5
-  FormControl,
6
-  FormArray,
7 5
   ReactiveFormsModule,
8 6
   Validators,
9 7
 } from '@angular/forms';
10
-import { ActivatedRoute, Router, RouterLink } from '@angular/router';
8
+
9
+import {
10
+  ActivatedRoute,
11
+  Router,
12
+  RouterLink,
13
+} from '@angular/router';
14
+
11 15
 import { AppHeader } from '../../share/header/app-header';
12 16
 import { AppSideMenu } from '../../share/side-menu/app-side-menu';
17
+
13 18
 import { DankaService } from '../../services/dankaService';
19
+import { KakochoService } from '../../services/kakocho-service';
20
+
14 21
 import { Danka } from '../../models/danka';
22
+import { Kakocho } from '../../models/kakocho';
15 23
 
16 24
 @Component({
17 25
   selector: 'app-kakocho-edit',
18
-  imports: [AppHeader, AppSideMenu, ReactiveFormsModule, RouterLink],
26
+  imports: [
27
+    AppHeader,
28
+    AppSideMenu,
29
+    ReactiveFormsModule,
30
+    RouterLink,
31
+  ],
19 32
   templateUrl: './kakocho-edit.html',
20 33
   styleUrl: './kakocho-edit.scss',
21 34
 })
22 35
 export class KakochoEdit {
23
-  danka: Danka | undefined;
24 36
 
25
-  dankaForm = new FormGroup({
26
-    householdName: new FormControl('', [Validators.required]),
27
-    householder: new FormControl('', [Validators.required]),
28
-    postalCode: new FormControl('', Validators.pattern(/^\d{3}-\d{4}$/)),
29
-    address: new FormControl(''),
30
-    phones: new FormArray([this.createPhoneForm('', '')]),
31
-  });
37
+  danka?: Danka;
38
+  kakocho?: Kakocho;
39
+
40
+  kakochoForm: FormGroup;
32 41
 
33 42
   constructor(
43
+    private fb: FormBuilder,
34 44
     private dankaService: DankaService,
45
+    private kakochoService: KakochoService,
35 46
     private route: ActivatedRoute,
36 47
     private router: Router,
37 48
   ) {
38
-    const id = this.route.snapshot.params['id'];
39
-    if (id) {
40
-      this.danka = this.dankaService.getDankaById(id);
41
-
42
-      if (this.danka) {
43
-        this.dankaForm.patchValue({
44
-          householdName: this.danka.householdName,
45
-          householder: this.danka.householder,
46
-          postalCode: this.danka.postalCode,
47
-          address: this.danka.address,
48
-        });
49 49
 
50
-        this.phones.clear();
50
+    // フォーム初期化
51
+    this.kakochoForm = this.fb.group({
52
+      name: ['', Validators.required],
53
+      furigana: [''],
54
+      relationship: [''],
55
+      kaimyo: [''],
56
+      deathDate: [''],
57
+      ageAtDeath: [''],
58
+      note: [''],
59
+    });
51 60
 
52
-        for (const phone of this.danka.phones) {
53
-          this.phones.push(this.createPhoneForm(phone.tel, phone.note));
54
-        }
55
-      }
61
+    // 檀家ID
62
+    const dankaId = this.route.snapshot.params['dankaId'];
63
+
64
+    if (dankaId) {
65
+      this.danka =
66
+        this.dankaService.getDankaById(dankaId);
56 67
     }
57
-    console.log(this.danka);
58
-  }
59 68
 
60
-  get phones() {
61
-    return this.dankaForm.get('phones') as FormArray;
62
-  }
69
+    // 編集対象ID
70
+    const kakochoId =
71
+      this.route.snapshot.params['kakochoId'];
63 72
 
64
-  createPhoneForm(tel = '', note = '') {
65
-    return new FormGroup({
66
-      tel: new FormControl(tel, [Validators.pattern(/^[0-9-]+$/)]),
67
-      note: new FormControl(note),
68
-    });
69
-  }
73
+    // 編集モード
74
+    if (kakochoId) {
70 75
 
71
-  addPhone() {
72
-    this.phones.push(this.createPhoneForm());
73
-  }
76
+      this.kakocho =
77
+        this.kakochoService.getKakochoById(kakochoId);
78
+
79
+      if (this.kakocho) {
80
+
81
+        this.kakochoForm.patchValue({
82
+          name: this.kakocho.name,
83
+          furigana: this.kakocho.furigana,
84
+          relationship: this.kakocho.relationship,
85
+          kaimyo: this.kakocho.kaimyo,
86
+          deathDate: this.kakocho.deathDate,
87
+          ageAtDeath: this.kakocho.ageAtDeath,
88
+          note: this.kakocho.note,
89
+        });
74 90
 
75
-  removePhone(index: number) {
76
-    if(this.phones.length > 1) {
77
-      this.phones.removeAt(index);
91
+      }
78 92
     }
79 93
   }
80 94
 
81
-  //保存の処理
82
-  saveDanka() {
83
-    if (this.dankaForm.invalid) {
84
-      this.dankaForm.markAllAsTouched();
85
-      return;
86
-    }
87
-    const formValue = this.dankaForm.value;
88
-    const isEdit = !!this.danka;
89
-    const dankaId = isEdit ? this.danka!.id : Date.now().toString();
90
-    const updatedDanka = {
91
-      id: dankaId,
92
-      householdName: formValue.householdName?.trim() ?? '',
93
-      householder: formValue.householder?.trim() ?? '',
94
-      postalCode: formValue.postalCode?.trim() ?? '',
95
-      address: formValue.address?.trim() ?? '',
96
-      phones: (formValue.phones ?? [])
97
-        .map((phone) => ({
98
-          tel: phone.tel?.trim() ?? '',
99
-          note: phone.note?.trim() ?? '',
100
-        }))
101
-        .filter((phone) => phone.tel !== '' || phone.note !== ''),
102
-    };
103
-
104
-    this.dankaService.saveDanka(updatedDanka);
105
-
106
-    if (isEdit) {
107
-      this.router.navigate(['/danka-detail', dankaId]);
95
+  saveKakocho(): void {
96
+
97
+    // form値取得
98
+    const formValue = this.kakochoForm.value;
99
+
100
+    // 編集
101
+    if (this.kakocho) {
102
+
103
+      const updatedKakocho: Kakocho = {
104
+        ...this.kakocho,
105
+        ...formValue,
106
+      };
107
+
108
+      this.kakochoService.updateKakocho(
109
+        updatedKakocho
110
+      );
111
+
108 112
     } else {
109
-      this.router.navigateByUrl('/danka-list');
113
+
114
+      // 新規追加
115
+      const newKakocho: Kakocho = {
116
+        id: crypto.randomUUID(),
117
+
118
+        dankaId: this.danka?.id ?? '',
119
+
120
+        familyId: '',
121
+
122
+        name: formValue.name,
123
+        furigana: formValue.furigana,
124
+        relationship: formValue.relationship,
125
+        kaimyo: formValue.kaimyo,
126
+        deathDate: formValue.deathDate,
127
+        ageAtDeath: formValue.ageAtDeath,
128
+        note: formValue.note,
129
+      };
130
+
131
+      this.kakochoService.addKakocho(
132
+        newKakocho
133
+      );
110 134
     }
135
+
136
+    // 一覧へ戻る
137
+    this.router.navigate([
138
+      '/danka-detail',
139
+      this.danka?.id,
140
+    ]);
111 141
   }
112 142
 
113
-  //削除の処理
114
-  deleteDanka() {
115
-    if (!this.danka) {
143
+  deleteKakocho(): void {
144
+
145
+    if (!this.kakocho) {
116 146
       return;
117 147
     }
118 148
 
119
-    const deleteDankaId = this.danka.id;
120
-    this.dankaService.deleteDanka(deleteDankaId);
121
-    console.log(this.dankaService.getDankaById(this.danka.id));
122
-    this.router.navigateByUrl('/danka-list');
149
+    this.kakochoService.deleteKakocho(
150
+      this.kakocho.id
151
+    );
152
+
153
+    this.router.navigate([
154
+      '/danka-detail',
155
+      this.danka?.id,
156
+    ]);
123 157
   }
124
-}
158
+}

+ 34
- 0
src/app/services/kakocho-service.ts 파일 보기

@@ -35,4 +35,38 @@ export class KakochoService {
35 35
   getKakochoByDankaId(dankaId: string): Kakocho[] {
36 36
     return this.kakochoList.filter((kakocho) => kakocho.dankaId === dankaId);
37 37
   }
38
+
39
+  // 一覧取得
40
+  getKakochoList(): Kakocho[] {
41
+    return this.kakochoList;
42
+  }
43
+
44
+  // 1件取得
45
+  getKakochoById(id: string): Kakocho | undefined {
46
+    return this.kakochoList.find(item => item.id === id);
47
+  }
48
+
49
+  // 新規登録
50
+  addKakocho(data: Kakocho): void {
51
+    this.kakochoList.push(data);
52
+  }
53
+
54
+  // 更新
55
+  updateKakocho(updatedData: Kakocho): void {
56
+
57
+    const index = this.kakochoList.findIndex(
58
+      item => item.id === updatedData.id
59
+    );
60
+
61
+    if (index !== -1) {
62
+      this.kakochoList[index] = updatedData;
63
+    }
64
+  }
65
+
66
+  // 削除
67
+  deleteKakocho(id: string): void {
68
+    this.kakochoList = this.kakochoList.filter(
69
+      item => item.id !== id
70
+    );
71
+  }  
38 72
 }

Loading…
취소
저장