Преглед изворни кода

[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,6 +17,10 @@ export const routes: Routes = [
17 17
     path: 'danka-detail/:id',
18 18
     component: DankaDetail,
19 19
   },
20
+  {
21
+    path: 'danka-new',
22
+    component: DankaEdit,
23
+  },
20 24
   {
21 25
     path: 'danka-edit/:id',
22 26
     component: DankaEdit,

+ 18
- 15
src/app/pages/danka-edit/danka-edit.ts Прегледај датотеку

@@ -23,14 +23,14 @@ export class DankaEdit {
23 23
   danka: Danka | undefined;
24 24
 
25 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 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,14 +82,12 @@ export class DankaEdit {
82 82
 
83 83
   //保存の処理
84 84
   saveDanka() {
85
-    if (!this.danka) {
86
-      return;
87
-    }
88
-
89 85
     const formValue = this.dankaForm.value;
86
+    const isEdit = !!this.danka;
87
+    const dankaId = isEdit ? this.danka!.id : Date.now().toString();
90 88
 
91 89
     const updatedDanka = {
92
-      id: this.danka.id,
90
+      id: dankaId,
93 91
       householdName: formValue.householdName ?? '',
94 92
       householder: formValue.householder ?? '',
95 93
       postalCode: formValue.postalCode ?? '',
@@ -101,8 +99,13 @@ export class DankaEdit {
101 99
     };
102 100
 
103 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,4 +119,4 @@ export class DankaEdit {
116 119
     console.log(this.dankaService.getDankaById(this.danka.id));
117 120
     this.router.navigateByUrl('/danka-list');
118 121
   }
119
- }
122
+}

Loading…
Откажи
Сачувај