固定资产项目前端文件
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.
 
 
 
 

140 lines
5.1 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 { AssetCategorySelectComponent } from '../asset-category-select/asset-category-select.component'
import { OrgSelectComponent } from '../org-select/org-select.component'
import { ASSET_SOURCE_MAP, ASSET_STATUS, MAINTENANCE_STATUS, MAINTENANCE_TYPE } from 'app/constants'
import { SelectUserByOrgComponent } from '../select-user-by-org/select-user-by-org.component'
import { ManufacturerSelectComponent } from '../manufacturer-select/manufacturer-select.component'
import { PositionSelectComponent } from '../position-select/position-select.component'
import { MaintenanceSelectComponent } from '../maintenance-select/maintenance-select.component'
import { NzSafeAny } from 'ng-zorro-antd/core/types'
import { NZ_MODAL_DATA } from 'ng-zorro-antd/modal'
import { AssetOperationRecordsComponent } from '../asset-operation-records/asset-operation-records.component'
import { AssetRepairRecordsComponent } from '../asset-repair-records/asset-repair-records.component'
@Component({
selector: 'app-asset-form',
standalone: true,
imports: [
SharedModule,
AssetCategorySelectComponent,
OrgSelectComponent,
SelectUserByOrgComponent,
ManufacturerSelectComponent,
PositionSelectComponent,
MaintenanceSelectComponent,
AssetOperationRecordsComponent,
AssetRepairRecordsComponent,
],
templateUrl: './asset-form.component.html',
styleUrl: './asset-form.component.less',
})
export class AssetFormComponent implements OnInit {
constructor(
private fb: FormBuilder,
private api: ApiService,
private msg: NzMessageService,
) {}
readonly data: NzSafeAny = inject(NZ_MODAL_DATA)
formGroup!: FormGroup
groupIndex = 0
ASSET_STATUS = ASSET_STATUS
ASSET_SOURCE_MAP = ASSET_SOURCE_MAP
MAINTENANCE_STATUS = MAINTENANCE_STATUS
MAINTENANCE_TYPE = MAINTENANCE_TYPE
ngOnInit(): void {
this.formGroup = this.fb.group({
assetId: this.fb.control(null, []),
name: this.fb.control('', [FormValidators.required('请输入')]),
categoryId: this.fb.control(null, [FormValidators.required('请选择')]),
ownCompanyId: this.fb.control(null, [FormValidators.required('请选择')]),
status: this.fb.control(null, [FormValidators.required('请选择')]),
sourceId: this.fb.control(null, []),
unit: this.fb.control(null, []),
positionId: this.fb.control(null, []),
positionDetail: this.fb.control(null, []),
serialNumber: this.fb.control(null, []),
manufacturersVendorId: this.fb.control(null, []),
useUserId: this.fb.control(null, []),
useOrganizationId: this.fb.control(null, []),
manager: this.fb.control(null, []),
purpose: this.fb.control(null, []),
model: this.fb.control(null, []),
maintenanceVendor: this.fb.control(null, []),
contactor: this.fb.control(null, []),
contact: this.fb.control(null, []),
responsiblePerson: this.fb.control(null, []),
maintenanceStartDate: this.fb.control(null, []),
maintenanceEndDate: this.fb.control(null, []),
maintenanceStatus: this.fb.control(null, []),
maintenanceType: this.fb.control(null, []),
suggestMaintenanceType: this.fb.control(null, []),
maintenanceNotes: this.fb.control(null, []),
financialNotes: this.fb.control(null, []),
financialCategoryId: this.fb.control(null, []),
residualsRate: this.fb.control(null, []),
financialOption: this.fb.control(null, []),
expenseItem: this.fb.control(null, []),
navPrice: this.fb.control(null, []),
customerInfo: this.fb.control(null, []),
taxAmountRate: this.fb.control(null, []),
totalAmountPrice: this.fb.control(null, []),
registerDate: this.fb.control(null, []),
})
this.patchValues()
}
patchValues() {
const { value: data, preview } = this.data
if (data) {
this.formGroup.patchValue({
...data,
useUserId: data._useUser?.userId ? [data._useUser?.userId] : [],
manager: data._manager?.userId ? [data._manager?.userId] : [],
responsiblePerson: data._responsiblePerson?.userId ? [data._responsiblePerson?.userId] : [],
categoryId: data._category?.categoryId + '',
positionId: data._position?.positionId + '',
ownCompanyId: data._ownCompany?.organizationId + '',
useOrganizationId: data._useOrganization?.organizationId + '',
maintenanceVendor: data._maintenanceVendor?.maintenanceVendorId,
manufacturersVendorId: data._manufacturersVendor?.manufacturersVendorId,
})
}
if (preview) {
this.formGroup.disable()
}
}
public getValues() {
let values = null
if (FormValidators.validateFormGroup(this.formGroup)) {
const v = this.formGroup.getRawValue()
values = {
...v,
useUserId: v.useUserId?.[0],
manager: v.manager?.[0],
categoryId: v.categoryId?.[0],
ownCompanyId: v.ownCompanyId?.[0],
positionId: v.positionId?.[0],
useOrganizationId: v.useOrganizationId?.[0],
responsiblePerson: v.responsiblePerson?.[0],
}
}
return values
}
}