kuni 3 weken geleden
bovenliggende
commit
08fca4c4dc

+ 6
- 1
src/app/app.routes.ts Bestand weergeven

@@ -3,6 +3,7 @@ import { Dashboard } from './pages/dashboard/dashboard';
3 3
 import { DankaList } from './pages/danka-list/danka-list';
4 4
 import { DankaDetail } from './pages/danka-detail/danka-detail';
5 5
 import { DankaEdit } from './pages/danka-edit/danka-edit';
6
+import { KakochoEdit } from './pages/kakocho-edit/kakocho-edit';
6 7
 
7 8
 export const routes: Routes = [
8 9
   {
@@ -24,5 +25,9 @@ export const routes: Routes = [
24 25
   {
25 26
     path: 'danka-edit/:id',
26 27
     component: DankaEdit,
27
-  }
28
+  },
29
+  {
30
+    path: 'kakocho-edit/:id',
31
+    component: KakochoEdit,
32
+  }  
28 33
 ];

+ 67
- 2
src/app/pages/danka-detail/danka-detail.html Bestand weergeven

@@ -67,6 +67,16 @@
67 67
             </nav>
68 68
           </div>
69 69
 
70
+          @if (selectedTab === 'kakocho') {
71
+          <button
72
+            type="button"
73
+            class="add-button"
74
+            [routerLink]="['/kakocho-edit', danka.id]"
75
+          >
76
+            故人を登録
77
+          </button>
78
+          }
79
+
70 80
           <button
71 81
             type="button"
72 82
             class="edit-button"
@@ -77,6 +87,7 @@
77 87
         </div>
78 88
 
79 89
         <section class="family-summary">
90
+          @if (selectedTab === 'basic') {
80 91
           <div class="family-name-area">
81 92
             <p class="family-name">{{ danka.householdName }}</p>
82 93
             <p class="family-head">世帯主: {{ danka.householder }}</p>
@@ -90,6 +101,17 @@
90 101
           <button type="button" class="memo-button">
91 102
             回忌を見る
92 103
           </button>
104
+          }
105
+
106
+          @if (selectedTab === 'kakocho') {
107
+          <div class="family-name-area">
108
+            <p class="family-name">{{ danka.householdName }}の過去帳{{ kakocholist.length }} 名</p>
109
+          </div>
110
+
111
+          <button type="button" class="memo-button">
112
+            年次法要を見る
113
+          </button>
114
+          }
93 115
         </section>
94 116
 
95 117
         @if (selectedTab === 'basic') {
@@ -160,7 +182,7 @@
160 182
                   (click)="selectedTab = 'kakocho'"
161 183
                 >
162 184
                   <p class="status-label">過去帳</p>
163
-                  <p class="status-count">2 名</p>
185
+                  <p class="status-count">{{ kakocholist.length }}  名</p>
164 186
                   <p class="status-link">詳細へ</p>
165 187
                 </button>
166 188
               </div>
@@ -271,7 +293,50 @@
271 293
             </div>
272 294
 
273 295
             <p class="empty-family-message">
274
-              過去帳情報はこれから実装します。
296
+              @if (kakocholist.length > 0) {
297
+                <div class="family-table">
298
+                  <div class="family-table-header">
299
+                    <div>戒名</div>
300
+                    <div>俗名</div>
301
+                    <div>没年月日</div>
302
+                    <div>関係</div>
303
+                    <div>回忌</div>
304
+                    <div>備考</div>
305
+                  </div>
306
+
307
+                  @for (kakocho of kakocholist; track kakocho.id) {
308
+                    <div class="family-table-row">
309
+                      <div class="family-person-name">
310
+                        {{ kakocho.kaimyo }}
311
+                      </div>
312
+
313
+                      <div>
314
+                        {{ kakocho.name }}
315
+                      </div>
316
+
317
+                      <div>
318
+                        {{ kakocho.deathDate }}
319
+                      </div>
320
+
321
+                      <div>
322
+                        {{ kakocho.relationship }}
323
+                      </div>
324
+
325
+                      <div>
326
+                        {{ getKaiki(kakocho.deathDate) }}回忌
327
+                      </div>
328
+
329
+                      <div>
330
+                        {{ kakocho.note || '' }}
331
+                      </div>
332
+                    </div>
333
+                  }
334
+                </div>
335
+              } @else {
336
+                <div class="empty-family-message">
337
+                  登録されている家族情報はありません。
338
+                </div>
339
+              }              
275 340
             </p>
276 341
           </section>
277 342
         }

+ 20
- 1
src/app/pages/danka-detail/danka-detail.scss Bestand weergeven

@@ -159,6 +159,25 @@
159 159
   background: #f6efe6;
160 160
 }
161 161
 
162
+.add-button {
163
+  width: 140px;
164
+  height: 46px;
165
+  margin-top: 36px;
166
+  border: 2px solid #d8caba;
167
+  border-radius: 6px;
168
+  background: #ffffff;
169
+  color: #2f2720;
170
+  font-size: 16px;
171
+  font-weight: 800;
172
+  cursor: pointer;
173
+  box-sizing: border-box;
174
+}
175
+
176
+.add-button:hover {
177
+  background: #f6efe6;
178
+}
179
+
180
+
162 181
 .detail-content {
163 182
   display: grid;
164 183
   grid-template-columns: minmax(0, 1fr) 500px;
@@ -540,4 +559,4 @@
540 559
   .family-support-area {
541 560
     grid-template-columns: 1fr;
542 561
   }
543
-}
562
+}

+ 15
- 0
src/app/pages/danka-detail/danka-detail.ts Bestand weergeven

@@ -4,8 +4,10 @@ import { DankaService } from '../../services/dankaService';
4 4
 import { FamilyService } from '../../services/family-service';
5 5
 import { Danka } from '../../models/danka';
6 6
 import { Family } from '../../models/family';
7
+import { Kakocho } from '../../models/kakocho';
7 8
 import { AppHeader } from '../../share/header/app-header';
8 9
 import { AppSideMenu } from '../../share/side-menu/app-side-menu';
10
+import { KakochoService } from '../../services/kakocho-service';
9 11
 
10 12
 @Component({
11 13
   selector: 'app-danka-detail',
@@ -16,20 +18,33 @@ import { AppSideMenu } from '../../share/side-menu/app-side-menu';
16 18
 export class DankaDetail {
17 19
   danka: Danka | undefined;
18 20
   families: Family[] = [];
21
+  kakocholist: Kakocho[] = [];
22
+  currentYear = new Date().getFullYear();
19 23
 
20 24
   selectedTab: 'basic' | 'family' | 'kakocho' | 'familyTree' = 'basic';
21 25
 
22 26
   constructor(
23 27
     private dankaService: DankaService,
24 28
     private familyService: FamilyService,
29
+    private kakochoService: KakochoService,
25 30
     private route: ActivatedRoute,
26 31
   ) {
27 32
     const id = this.route.snapshot.params['id'];
28 33
     if (id) {
29 34
       this.danka = this.dankaService.getDankaById(id);
30 35
       this.families = this.familyService.getFamiliesByDankaId(id);
36
+      this.kakocholist = this.kakochoService.getKakochoByDankaId(id);
31 37
     }
32 38
     console.log(this.danka);
33 39
     console.log(this.families);
40
+    console.log(this.kakocholist);
41
+  }
42
+
43
+  getKaiki(deathDate: string): number {
44
+    return (
45
+      this.currentYear -
46
+      new Date(deathDate).getFullYear() +
47
+      1
48
+    );
34 49
   }
35 50
 }

+ 147
- 1
src/app/pages/kakocho-edit/kakocho-edit.html Bestand weergeven

@@ -1 +1,147 @@
1
-<p>kakocho-edit works!</p>
1
+<app-header></app-header>
2
+
3
+<div class="breadcrumb">
4
+  ホーム &gt; 檀家(世帯) &gt; 編集
5
+</div>
6
+
7
+<div class="danka-edit-page">
8
+  <app-side-menu></app-side-menu>
9
+
10
+  <main class="danka-edit-main">
11
+    <section class="edit-panel">
12
+      <div class="page-title-area">
13
+        <h1>檀家(世帯)編集</h1>
14
+      </div>
15
+
16
+      <form [formGroup]="dankaForm" class="edit-form">
17
+        <div class="edit-content">
18
+          <section class="basic-edit-section">
19
+            <h2>基本情報</h2>
20
+
21
+            <div class="form-list">
22
+              <div class="form-row">
23
+                <label for="householdName">世帯名</label>
24
+                <div class="form-field">
25
+                  <input
26
+                    id="householdName"
27
+                    type="text"
28
+                    formControlName="householdName"
29
+                  />
30
+                  @if (dankaForm.get('householdName')?.invalid && dankaForm.get('householdName')?.touched) {
31
+                    <p class="error-message">世帯名を入力してください。</p>
32
+                  }
33
+                </div>
34
+              </div>
35
+
36
+              <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>
48
+              </div>
49
+
50
+              <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>
62
+              </div>
63
+
64
+              <div class="form-row">
65
+                <label for="address">住所</label>
66
+                <input
67
+                  id="address"
68
+                  type="text"
69
+                  formControlName="address"
70
+                />
71
+              </div>
72
+            </div>
73
+          </section>
74
+
75
+          <section class="phone-edit-section">
76
+            <div class="section-heading">
77
+              <h2>電話番号(複数登録)</h2>
78
+              <p>番号と備考を複数登録できます。</p>
79
+            </div>
80
+
81
+            <div formArrayName="phones" class="phone-table">
82
+              <div class="phone-table-header">
83
+                <div>番号</div>
84
+                <div>備考</div>
85
+                <div>操作</div>
86
+              </div>
87
+
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
+              }
110
+
111
+            </div>
112
+
113
+            <div class="phone-action">
114
+              <button
115
+                type="button"
116
+                class="add-phone-button"
117
+                (click)="addPhone()"
118
+              >
119
+                電話を追加
120
+              </button>
121
+            </div>
122
+          </section>
123
+        </div>
124
+
125
+        <div class="bottom-actions">
126
+          <button type="button" class="delete-button" (click)="deleteDanka()">
127
+            削除
128
+          </button>
129
+
130
+          <button type="button" class="cancel-button" [routerLink]="['/danka-detail', danka?.id]">
131
+            キャンセル
132
+          </button>
133
+
134
+          <button
135
+            type="button"
136
+            class="save-button"
137
+            [disabled]="dankaForm.invalid"
138
+            (click)="saveDanka()"
139
+          >
140
+            保存
141
+          </button>
142
+        </div>
143
+      </form>
144
+    </section>
145
+  </main>
146
+</div>
147
+

+ 355
- 0
src/app/pages/kakocho-edit/kakocho-edit.scss Bestand weergeven

@@ -0,0 +1,355 @@
1
+:host {
2
+  position: relative;
3
+  display: block;
4
+  min-height: 100vh;
5
+  background: #f4eee4;
6
+  color: #2f2720;
7
+}
8
+
9
+.breadcrumb {
10
+  position: absolute;
11
+  top: 28px;
12
+  left: 50%;
13
+  transform: translateX(-50%);
14
+  color: #7b6b5c;
15
+  font-size: 14px;
16
+  z-index: 2;
17
+}
18
+
19
+.danka-edit-page {
20
+  display: flex;
21
+  align-items: flex-start;
22
+  gap: 8px;
23
+  background: #f4eee4;
24
+}
25
+
26
+.danka-edit-main {
27
+  flex: 1;
28
+  padding-right: 34px;
29
+  box-sizing: border-box;
30
+}
31
+
32
+.edit-panel {
33
+  min-height: 650px;
34
+  padding: 26px 34px 36px;
35
+  background: #ffffff;
36
+  border: 2px solid #d8caba;
37
+  border-radius: 76px;
38
+  box-sizing: border-box;
39
+}
40
+
41
+.page-title-area {
42
+  margin-bottom: 8px;
43
+}
44
+
45
+.page-title-area h1 {
46
+  margin: 0;
47
+  color: #2f2720;
48
+  font-size: 32px;
49
+  line-height: 1.2;
50
+  font-weight: 800;
51
+  letter-spacing: 0.02em;
52
+}
53
+
54
+.edit-form {
55
+  display: block;
56
+  width: 100%;
57
+  margin: 0;
58
+  color: #2f2720;
59
+}
60
+
61
+.edit-form input,
62
+.edit-form button {
63
+  font-family: inherit;
64
+}
65
+
66
+.edit-content {
67
+  display: grid;
68
+  grid-template-columns: minmax(0, 1fr) 520px;
69
+  gap: 48px;
70
+  align-items: start;
71
+}
72
+
73
+.basic-edit-section,
74
+.phone-edit-section {
75
+  padding-top: 4px;
76
+}
77
+
78
+.basic-edit-section h2,
79
+.phone-edit-section h2,
80
+.support-box h2 {
81
+  margin: 0;
82
+  color: #2f2720;
83
+  font-size: 22px;
84
+  font-weight: 800;
85
+}
86
+
87
+.section-heading p {
88
+  margin: 6px 0 14px;
89
+  color: #7b6b5c;
90
+  font-size: 15px;
91
+}
92
+
93
+/* 基本情報 */
94
+.form-list {
95
+  margin-top: 14px;
96
+}
97
+
98
+.form-field {
99
+  width: 100%;
100
+  display: flex;
101
+  flex-direction: column;
102
+}
103
+
104
+.form-row {
105
+  display: grid;
106
+  grid-template-columns: 120px 1fr;
107
+  align-items: center;
108
+  gap: 16px;
109
+  margin-bottom: 14px;
110
+}
111
+
112
+.form-row label {
113
+  color: #4b3c31;
114
+  font-size: 17px;
115
+  font-weight: 800;
116
+}
117
+
118
+.form-row input {
119
+  width: 100%;
120
+  height: 54px;
121
+  padding: 0 14px;
122
+  border: 2px solid #d8caba;
123
+  border-radius: 8px;
124
+  background: #fffdf9;
125
+  color: #2f2720;
126
+  font-size: 18px;
127
+  font-weight: 600;
128
+  box-sizing: border-box;
129
+  outline: none;
130
+}
131
+
132
+.form-row input:focus {
133
+  border-color: #8a6543;
134
+  box-shadow: 0 0 0 3px rgba(138, 101, 67, 0.15);
135
+}
136
+
137
+/* 電話番号 */
138
+.phone-table {
139
+  width: 100%;
140
+}
141
+
142
+.phone-table-header,
143
+.phone-table-row {
144
+  display: grid;
145
+  grid-template-columns: 1.35fr 1.45fr 84px;
146
+  align-items: center;
147
+  column-gap: 10px;
148
+}
149
+
150
+.phone-table-header {
151
+  min-height: 38px;
152
+  padding: 0 10px;
153
+  border: 2px solid #d8caba;
154
+  border-radius: 6px;
155
+  background: #eadfce;
156
+  color: #5a4a3c;
157
+  font-size: 15px;
158
+  font-weight: 800;
159
+  box-sizing: border-box;
160
+}
161
+
162
+.phone-table-row {
163
+  min-height: 56px;
164
+  margin-top: 4px;
165
+  padding: 6px 10px;
166
+  border: 2px solid #d8caba;
167
+  border-radius: 8px;
168
+  background: #fffdf9;
169
+  color: #2f2720;
170
+  font-size: 16px;
171
+  box-sizing: border-box;
172
+}
173
+
174
+.phone-table-row > div {
175
+  display: flex;
176
+  align-items: center;
177
+}
178
+
179
+.phone-table-row input {
180
+  width: 100%;
181
+  height: 38px;
182
+  padding: 0 10px;
183
+  border: none;
184
+  border-radius: 6px;
185
+  background: transparent;
186
+  color: #2f2720;
187
+  font-size: 16px;
188
+  font-weight: 600;
189
+  box-sizing: border-box;
190
+  outline: none;
191
+}
192
+
193
+.phone-table-row input:focus {
194
+  background: #ffffff;
195
+  box-shadow: inset 0 0 0 2px #8a6543;
196
+}
197
+
198
+.phone-table-row input::placeholder {
199
+  color: #9b8b7a;
200
+  font-weight: 500;
201
+}
202
+
203
+.phone-row-action {
204
+  justify-content: flex-end;
205
+}
206
+
207
+.remove-phone-button {
208
+  width: 68px;
209
+  height: 34px;
210
+  border: 2px solid #d8caba;
211
+  border-radius: 6px;
212
+  background: #ffffff;
213
+  color: #6a4a35;
214
+  font-size: 14px;
215
+  font-weight: 800;
216
+  cursor: pointer;
217
+  box-sizing: border-box;
218
+}
219
+
220
+.remove-phone-button:hover {
221
+  background: #f6efe6;
222
+}
223
+
224
+.phone-action {
225
+  display: flex;
226
+  justify-content: flex-end;
227
+  margin-top: 8px;
228
+}
229
+
230
+.add-phone-button {
231
+  width: 170px;
232
+  height: 46px;
233
+  border: 2px solid #d8caba;
234
+  border-radius: 8px;
235
+  background: #ffffff;
236
+  color: #2f2720;
237
+  font-size: 16px;
238
+  font-weight: 800;
239
+  cursor: pointer;
240
+  box-sizing: border-box;
241
+}
242
+
243
+.add-phone-button:hover {
244
+  background: #f6efe6;
245
+}
246
+
247
+/* 入力補助 */
248
+.support-box {
249
+  min-height: 142px;
250
+  margin-top: 56px;
251
+  padding: 28px 30px;
252
+  border: 2px solid #d8caba;
253
+  border-radius: 24px;
254
+  background: #fffdf9;
255
+  box-sizing: border-box;
256
+}
257
+
258
+.support-box ul {
259
+  margin: 12px 0 0;
260
+  padding-left: 22px;
261
+  color: #6f6257;
262
+  font-size: 15px;
263
+  line-height: 1.65;
264
+}
265
+
266
+/* 下部ボタン */
267
+.bottom-actions {
268
+  display: flex;
269
+  justify-content: flex-end;
270
+  align-items: center;
271
+  gap: 12px;
272
+  margin-top: 22px;
273
+}
274
+
275
+.delete-button,
276
+.cancel-button,
277
+.save-button {
278
+  min-width: 116px;
279
+  height: 52px;
280
+  border: 2px solid #d8caba;
281
+  border-radius: 8px;
282
+  font-size: 17px;
283
+  font-weight: 800;
284
+  cursor: pointer;
285
+  box-sizing: border-box;
286
+}
287
+
288
+.delete-button,
289
+.cancel-button {
290
+  background: #ffffff;
291
+  color: #2f2720;
292
+}
293
+
294
+.save-button {
295
+  background: #8a6543;
296
+  border-color: #8a6543;
297
+  color: #ffffff;
298
+}
299
+
300
+.delete-button:hover,
301
+.cancel-button:hover {
302
+  background: #f6efe6;
303
+}
304
+
305
+.save-button:hover {
306
+  background: #765639;
307
+}
308
+
309
+.bottom-note {
310
+  width: 700px;
311
+  margin: 18px 0 22px 36px;
312
+  padding: 4px 12px;
313
+  border: 2px solid #d8caba;
314
+  border-radius: 4px;
315
+  background: #eadfce;
316
+  color: #7b6b5c;
317
+  font-size: 14px;
318
+  box-sizing: border-box;
319
+}
320
+
321
+.error-message {
322
+  margin: 6px 0 0;
323
+  color: #b33a2f;
324
+  font-size: 14px;
325
+  font-weight: 700;
326
+  line-height: 1.4;
327
+  white-space: normal;
328
+}
329
+
330
+.save-button:disabled {
331
+  background: #c8b8a5;
332
+  border-color: #c8b8a5;
333
+  color: #ffffff;
334
+  cursor: not-allowed;
335
+  opacity: 0.7;
336
+}
337
+
338
+.phone-field {
339
+  width: 100%;
340
+  display: flex;
341
+  flex-direction: column;
342
+}
343
+
344
+.phone-error-message {
345
+  margin: 4px 0 0;
346
+  color: #b33a2f;
347
+  font-size: 12px;
348
+  font-weight: 700;
349
+  line-height: 1.4;
350
+}
351
+
352
+.remove-phone-button:disabled {
353
+  opacity: 0.5;
354
+  cursor: not-allowed;
355
+}

+ 118
- 3
src/app/pages/kakocho-edit/kakocho-edit.ts Bestand weergeven

@@ -1,9 +1,124 @@
1
-import { Component } from '@angular/core';
1
+import { Component, inject } from '@angular/core';
2
+import {
3
+  FormBuilder,
4
+  FormGroup,
5
+  FormControl,
6
+  FormArray,
7
+  ReactiveFormsModule,
8
+  Validators,
9
+} from '@angular/forms';
10
+import { ActivatedRoute, Router, RouterLink } from '@angular/router';
11
+import { AppHeader } from '../../share/header/app-header';
12
+import { AppSideMenu } from '../../share/side-menu/app-side-menu';
13
+import { DankaService } from '../../services/dankaService';
14
+import { Danka } from '../../models/danka';
2 15
 
3 16
 @Component({
4 17
   selector: 'app-kakocho-edit',
5
-  imports: [],
18
+  imports: [AppHeader, AppSideMenu, ReactiveFormsModule, RouterLink],
6 19
   templateUrl: './kakocho-edit.html',
7 20
   styleUrl: './kakocho-edit.scss',
8 21
 })
9
-export class KakochoEdit {}
22
+export class KakochoEdit {
23
+  danka: Danka | undefined;
24
+
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
+  });
32
+
33
+  constructor(
34
+    private dankaService: DankaService,
35
+    private route: ActivatedRoute,
36
+    private router: Router,
37
+  ) {
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
+
50
+        this.phones.clear();
51
+
52
+        for (const phone of this.danka.phones) {
53
+          this.phones.push(this.createPhoneForm(phone.tel, phone.note));
54
+        }
55
+      }
56
+    }
57
+    console.log(this.danka);
58
+  }
59
+
60
+  get phones() {
61
+    return this.dankaForm.get('phones') as FormArray;
62
+  }
63
+
64
+  createPhoneForm(tel = '', note = '') {
65
+    return new FormGroup({
66
+      tel: new FormControl(tel, [Validators.pattern(/^[0-9-]+$/)]),
67
+      note: new FormControl(note),
68
+    });
69
+  }
70
+
71
+  addPhone() {
72
+    this.phones.push(this.createPhoneForm());
73
+  }
74
+
75
+  removePhone(index: number) {
76
+    if(this.phones.length > 1) {
77
+      this.phones.removeAt(index);
78
+    }
79
+  }
80
+
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]);
108
+    } else {
109
+      this.router.navigateByUrl('/danka-list');
110
+    }
111
+  }
112
+
113
+  //削除の処理
114
+  deleteDanka() {
115
+    if (!this.danka) {
116
+      return;
117
+    }
118
+
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');
123
+  }
124
+}

+ 5
- 1
src/app/services/kakocho-service.ts Bestand weergeven

@@ -1,5 +1,5 @@
1 1
 import { Injectable } from '@angular/core';
2
-import {Kakocho} from '../models/kakocho';
2
+import { Kakocho } from '../models/kakocho';
3 3
 
4 4
 @Injectable({
5 5
   providedIn: 'root',
@@ -31,4 +31,8 @@ export class KakochoService {
31 31
       note: '',
32 32
     },
33 33
   ];
34
+
35
+  getKakochoByDankaId(dankaId: string): Kakocho[] {
36
+    return this.kakochoList.filter((kakocho) => kakocho.dankaId === dankaId);
37
+  }
34 38
 }

Laden…
Annuleren
Opslaan