소스 검색

[add]

檀家情報の新規追加の処理
poohr 1 개월 전
부모
커밋
1a1effb7a5
2개의 변경된 파일22개의 추가작업 그리고 15개의 파일을 삭제
  1. 4
    0
      src/app/app.routes.ts
  2. 18
    15
      src/app/pages/danka-edit/danka-edit.ts

+ 4
- 0
src/app/app.routes.ts 파일 보기

17
     path: 'danka-detail/:id',
17
     path: 'danka-detail/:id',
18
     component: DankaDetail,
18
     component: DankaDetail,
19
   },
19
   },
20
+  {
21
+    path: 'danka-new',
22
+    component: DankaEdit,
23
+  },
20
   {
24
   {
21
     path: 'danka-edit/:id',
25
     path: 'danka-edit/:id',
22
     component: DankaEdit,
26
     component: DankaEdit,

+ 18
- 15
src/app/pages/danka-edit/danka-edit.ts 파일 보기

23
   danka: Danka | undefined;
23
   danka: Danka | undefined;
24
 
24
 
25
   dankaForm = new FormGroup({
25
   dankaForm = new FormGroup({
26
-    householdName: new FormControl('鈴木家'),
27
-    householder: new FormControl('鈴木 太郎'),
28
-    postalCode: new FormControl('123-4567'),
29
-    address: new FormControl('市内 1-2-3'),
26
+    householdName: new FormControl(''),
27
+    householder: new FormControl(''),
28
+    postalCode: new FormControl(''),
29
+    address: new FormControl(''),
30
     phones: new FormArray([
30
     phones: new FormArray([
31
-      this.createPhoneForm('03-xxxx-xxxx', '自宅'),
32
-      this.createPhoneForm('090-xxxx-xxxx', '世帯主'),
33
-      this.createPhoneForm('0584-xx-xxxx', '寺報連絡'),
31
+      this.createPhoneForm('', ''),
32
+      this.createPhoneForm('', ''),
33
+      this.createPhoneForm('', ''),
34
     ]),
34
     ]),
35
   });
35
   });
36
 
36
 
82
 
82
 
83
   //保存の処理
83
   //保存の処理
84
   saveDanka() {
84
   saveDanka() {
85
-    if (!this.danka) {
86
-      return;
87
-    }
88
-
89
     const formValue = this.dankaForm.value;
85
     const formValue = this.dankaForm.value;
86
+    const isEdit = !!this.danka;
87
+    const dankaId = isEdit ? this.danka!.id : Date.now().toString();
90
 
88
 
91
     const updatedDanka = {
89
     const updatedDanka = {
92
-      id: this.danka.id,
90
+      id: dankaId,
93
       householdName: formValue.householdName ?? '',
91
       householdName: formValue.householdName ?? '',
94
       householder: formValue.householder ?? '',
92
       householder: formValue.householder ?? '',
95
       postalCode: formValue.postalCode ?? '',
93
       postalCode: formValue.postalCode ?? '',
101
     };
99
     };
102
 
100
 
103
     this.dankaService.saveDanka(updatedDanka);
101
     this.dankaService.saveDanka(updatedDanka);
104
-    this.router.navigate(['./danka-detail', this.danka.id]);
105
-    console.log(this.dankaService.getDankaList());
102
+
103
+    if (isEdit) {
104
+      this.router.navigate(['/danka-detail', dankaId]);
105
+    } else {
106
+      this.router.navigateByUrl('/danka-list');
107
+    }
108
+
106
   }
109
   }
107
 
110
 
108
   //削除の処理
111
   //削除の処理
116
     console.log(this.dankaService.getDankaById(this.danka.id));
119
     console.log(this.dankaService.getDankaById(this.danka.id));
117
     this.router.navigateByUrl('/danka-list');
120
     this.router.navigateByUrl('/danka-list');
118
   }
121
   }
119
- }
122
+}

Loading…
취소
저장