Kaynağa Gözat

feat: jd name

Signed-off-by: carlos <568187512@qq.com>
carlos 2 ay önce
ebeveyn
işleme
9a0862a6b9

+ 28 - 26
src/app/pages/manager/basic/dj/job-edit/job-edit.component.html

@@ -1,28 +1,30 @@
-<div class="flex pb-4">
-  <button nz-button class="precaution-green" nzType="primary" (click)="onJobAdd()">添加岗位</button>
-</div>
-<div class="flex items-center leading-8 flex-wrap">
-  @for (job of copyData; track job.id) {
-    <span class="mr-2 last:mr-0">
-      @if (!editJob || editJob.id !== job.id) {
-        <span class="job-text">
-          <nz-tag class="precaution-tag rounded cursor-pointer" nzColor="#1e5eff">
-            <span class="text-sm">
-              {{ job.name }}
+<nz-spin [nzSpinning]="loading">
+  <div class="flex pb-4">
+    <button nz-button class="precaution-green" nzType="primary" (click)="onJobAdd()">添加岗位</button>
+  </div>
+  <div class="flex items-center leading-8 flex-wrap">
+    @for (job of copyData; track job.id) {
+      <span class="mr-2 last:mr-0">
+        @if (!editJob || editJob.id !== job.id) {
+          <span class="job-text">
+            <nz-tag class="precaution-tag rounded cursor-pointer" nzColor="#1e5eff">
+              <span class="text-sm">
+                {{ job.name }}
+              </span>
+            </nz-tag>
+            <span class="job-action">
+              <span nz-icon nzType="edit" class="icon-normal mr-1" (click)="onJobEdit(job)"></span>
+              <span nz-icon nzType="delete" class="icon-delete" (click)="onJobDelete(job)"></span>
             </span>
-          </nz-tag>
-          <span class="job-action">
-            <span nz-icon nzType="edit" class="icon-normal mr-1" (click)="onJobEdit(job)"></span>
-            <span nz-icon nzType="delete" class="icon-delete" (click)="onJobDelete(job)"></span>
           </span>
-        </span>
-      } @else {
-        <span class="inline-block text-nowrap">
-          <input nz-input class="precaution-input" [(ngModel)]="editJobValue" />
-        </span>
-        <span nz-icon nzType="check" class="icon-normal ml-2" (click)="onJobEditConfirm(job)"></span>
-        <span nz-icon nzType="close" class="icon-normal ml-1" (click)="onJobEditCancel(job)"></span>
-      }
-    </span>
-  }
-</div>
+        } @else {
+          <span class="inline-block text-nowrap">
+            <input nz-input class="precaution-input" [(ngModel)]="editJobValue" />
+          </span>
+          <span nz-icon nzType="check" class="icon-normal ml-2" (click)="onJobEditConfirm(job)"></span>
+          <span nz-icon nzType="close" class="icon-normal ml-1" (click)="onJobEditCancel(job)"></span>
+        }
+      </span>
+    }
+  </div>
+</nz-spin>

+ 7 - 5
src/app/pages/manager/basic/dj/job-edit/job-edit.component.ts

@@ -29,7 +29,8 @@ export class JobEditComponent {
     private modal: NzModalService,
     private api: ApiService
   ) {}
-  ngAfterViewInit() {
+  ngOnInit() {
+    console.time('fetchJobs');
     this.fetchJobs();
   }
   onJobAdd() {
@@ -112,18 +113,19 @@ export class JobEditComponent {
     });
   }
   get allJobs() {
-    return this.basic.jobs;
+    return this.basic.jobs || [];
   }
   get departmentId() {
     return this.nzModalData.departmentId;
   }
 
-  jobs: BasicData.Job[] = [];
   copyData: BasicData.Job[] = [];
   getJobs() {
     const list = this.allJobs.filter(j => j.department === this.departmentId);
-    this.jobs = list;
-    this.copyData = list.slice();
+    this.copyData = list;
+  }
+  ngAfterViewInit() {
+    console.timeEnd('fetchJobs');
   }
   fetchJobs() {
     this.basic.fetchJobs().then(() => {

+ 1 - 1
src/app/pages/manager/risk/risk-bank/risk-item-form/risk-item-form.component.ts

@@ -112,7 +112,7 @@ export class RiskItemFormComponent {
     }));
 
     this.options.job = this.basic.jobs.map(item => ({
-      label: item.name,
+      label: this.basic.getJobName(item.id),
       value: item.id,
     }));
     this.options.unit = this.getPositionOptions();

+ 9 - 1
src/app/services/basic.service.ts

@@ -100,8 +100,16 @@ export class BasicDataService {
   getEquipmentName(equipmentId: number) {
     return this.equipments.find(eq => eq.id === equipmentId)?.name;
   }
+  getDepartmentName(departmentId: number) {
+    return this.departments.find(eq => eq.id === departmentId)?.name;
+  }
   getJobName(jobId: number) {
-    return this.jobs.find(job => job.id === jobId)?.name;
+    const jobDto = this.jobs.find(job => job.id === jobId);
+    if (!jobDto) return '';
+    const departmentId = jobDto?.department;
+    const departmentName = this.getDepartmentName(departmentId);
+    if (!departmentName) return jobDto.name;
+    return `${jobDto.name}(${departmentName})`;
   }
   getConsequenceName(consequenceId: number) {
     return this.consequences.find(con => con.id === consequenceId)?.value;