固定资产项目前端文件
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.6 KiB

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 { OrgSelectComponent } from '../org-select/org-select.component'
import { SelectUserByOrgComponent } from '../select-user-by-org/select-user-by-org.component'
import { PositionSelectComponent } from '../position-select/position-select.component'
import { NzSafeAny } from 'ng-zorro-antd/core/types'
import { NZ_MODAL_DATA } from 'ng-zorro-antd/modal'
import { SupplierSelectComponent } from '../supplier-select/supplier-select.component'
import { AssetSelectComponent } from '../asset-select/asset-select.component'
import { WarehouseSelectComponent } from '../warehouse-select/warehouse-select.component'
@Component({
selector: 'app-asset-business-allot-form',
standalone: true,
imports: [
SharedModule,
SelectUserByOrgComponent,
SupplierSelectComponent,
AssetSelectComponent,
OrgSelectComponent,
PositionSelectComponent,
WarehouseSelectComponent,
],
templateUrl: './asset-business-allot-form.component.html',
styleUrl: './asset-business-allot-form.component.less',
})
export class AssetBusinessAllotFormComponent {
constructor(
private fb: FormBuilder,
private api: ApiService,
private msg: NzMessageService,
) {}
readonly data: NzSafeAny = inject(NZ_MODAL_DATA)
formGroup!: FormGroup
groupIndex = 0
uploadLoading = false
ngOnInit(): void {
this.formGroup = this.fb.group({
id: this.fb.control(null, []),
name: this.fb.control('', [FormValidators.required('请输入')]),
// useUserId: this.fb.control(null, [FormValidators.required('请选择')]),
// useOrganizationId: this.fb.control(null, [FormValidators.required('请选择')]),
11 months ago
businessGeneratedDate: this.fb.control(null, [FormValidators.required('请选择')]),
notes: this.fb.control(null, []),
inWarehouseId: this.fb.control(null, [FormValidators.required('请选择')]),
11 months ago
// outWarehouseId: this.fb.control(null, [FormValidators.required('请选择')]),
attach: this.fb.control('', []),
assetIdList: this.fb.control([], []),
12 months ago
applicant: this.fb.control({ value: '', disabled: true }, []),
})
this.patchValues()
}
patchValues() {
const { value: data, preview } = this.data
if (data) {
this.formGroup.patchValue({
...data,
useUserId: data._useUser?.userId ? [data._useUser?.userId] : [],
positionId: data._position?.positionId + '',
useOrganizationId: data._useOrganization?.organizationId + '',
12 months ago
inWarehouseId: data._inWarehouse?.warehouseId,
11 months ago
// outWarehouseId: data._outWarehouse?.warehouseId,
12 months ago
applicant: data._applicant?.userName,
})
}
if (preview) {
this.formGroup.disable()
}
}
public getValues() {
let values = null
if (FormValidators.validateFormGroup(this.formGroup)) {
const v = this.formGroup.value
values = {
...v,
useUserId: v.useUserId?.[0],
manager: v.manager?.[0],
categoryId: v.categoryId?.[0],
ownCompanyId: v.ownCompanyId?.[0],
positionId: Number(v.positionId?.[0]),
useOrganizationId: Number(v.useOrganizationId?.[0]),
12 months ago
assetIdList: v.assetIdList,
}
}
return values
}
onFileChange(e: Event) {
const target = e.target as HTMLInputElement
const file = target.files![0]
target.value = ''
const formdata = new FormData()
formdata.append('file', file)
this.api.upload(formdata).subscribe((res) => {
this.formGroup.get('attach')?.setValue(res.body.fileName)
})
}
}