import { Component, Input, OnInit, inject } from '@angular/core' import { FormBuilder, FormGroup } from '@angular/forms' import { ApiService } from 'app/services' import { SharedModule } from 'app/shared/shared.module' import { FormValidators, Utils } from 'app/utils' import { NzMessageService } from 'ng-zorro-antd/message' import { NzSafeAny } from 'ng-zorro-antd/core/types' import { NZ_MODAL_DATA } from 'ng-zorro-antd/modal' import { ActivatedRoute } from '@angular/router' import { STOCKTAKING_JOB_STATUS_MAP, taskTypeTitle } from 'app/constants' import { AssetSelectComponent, OrgSelectComponent, PositionSelectComponent, SelectUserByOrgComponent, SupplierSelectComponent, } from 'app/components' import { UploadComponent } from '../../../shared/components/upload/upload.component' @Component({ selector: 'app-stocktaking-detail-form', standalone: true, imports: [ SharedModule, SelectUserByOrgComponent, SupplierSelectComponent, AssetSelectComponent, OrgSelectComponent, PositionSelectComponent, UploadComponent, ], templateUrl: './task-form.component.html', styleUrl: './task-form.component.less', }) export class TaskFormComponent { constructor( private fb: FormBuilder, private api: ApiService, private msg: NzMessageService, private route: ActivatedRoute, ) {} readonly data: NzSafeAny = inject(NZ_MODAL_DATA) STOCKTAKING_JOB_STATUS_MAP = STOCKTAKING_JOB_STATUS_MAP formGroup!: FormGroup groupIndex = 0 uploadLoading = false uploadImgLoading = false iconPreview = '' flowForms: NzSafeAny[] = [] teamList: NzSafeAny[] = [] handle = false ngOnInit(): void { this.api.getAssetTeamAll().subscribe((res) => { this.teamList = res.body }) this.api.getFlowFormList().subscribe((res) => { this.flowForms = res.body }) this.formGroup = this.fb.group({ teamId: this.fb.control(null, [FormValidators.required('请选择')]), name: this.fb.control(null, [FormValidators.required('请输入')]), remark: this.fb.control(null, []), formTempId: this.fb.control(null, [FormValidators.required('请选择')]), // plannedDate: this.fb.control(null, [FormValidators.required('请选择')]), actualStartTime: this.fb.control(null, []), businessId: this.fb.control(null, []), attachment: this.fb.control(null, []), duration: this.fb.control(null, []), order: this.fb.control(false, []), limit: this.fb.control(false, []), img: this.fb.control(null, []), assetIdList: this.fb.control([], []), }) this.patchValues() } title?: string patchValues() { const { value: data, preview, type } = this.data this.title = taskTypeTitle.get(type) if (data) { this.formGroup.patchValue({ ...data, }) } if (preview) { this.formGroup.disable() } } public getValues() { let values = null if (FormValidators.validateFormGroup(this.formGroup)) { const v = this.formGroup.value const form = this.flowForms.find((i) => i.formTempId === v.formTempId) values = { ...v, formName: form.formName, formValue: form.formValue, teamName: this.teamList.find((i) => i.teamId === v.teamId).teamName, assetIdList: v.assetIdList.map((i: NzSafeAny) => { return { ...i, // assetId: i, } }), // assetId } } return values } }