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

151 lines
5.4 KiB

2 years ago
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'
2 years ago
import { ASSET_SOURCE_MAP, ASSET_STATUS, MAINTENANCE_STATUS, MAINTENANCE_TYPE, MAX_PAGE_SIZE } from 'app/constants'
2 years ago
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'
2 years ago
import { AssetRepairRecordsComponent } from '../asset-repair-records/asset-repair-records.component'
2 years ago
@Component({
selector: 'app-asset-form',
standalone: true,
imports: [
SharedModule,
AssetCategorySelectComponent,
OrgSelectComponent,
SelectUserByOrgComponent,
ManufacturerSelectComponent,
PositionSelectComponent,
MaintenanceSelectComponent,
AssetOperationRecordsComponent,
2 years ago
AssetRepairRecordsComponent,
2 years ago
],
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
2 years ago
financialCategory: NzSafeAny[] = []
2 years ago
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, []),
2 years ago
})
2 years ago
this.patchValues()
2 years ago
2 years ago
this.api.getBasicFinancialCategory({}).subscribe((res) => {
this.financialCategory = res.body
})
2 years ago
}
patchValues() {
const { value: data, preview } = this.data
if (data) {
2 years ago
console.log('data', data)
2 years ago
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] : [],
2 years ago
categoryId: data._category?.categoryId ? data._category?.categoryId + '' : null,
positionId: data._position?.positionId ? data._position?.positionId + '' : null,
ownCompanyId: data._ownCompany?.organizationId ? data._ownCompany?.organizationId + '' : null,
useOrganizationId: data._useOrganization?.organizationId
? data._useOrganization?.organizationId + ''
: null,
2 years ago
maintenanceVendor: data._maintenanceVendor?.maintenanceVendorId,
manufacturersVendorId: data._manufacturersVendor?.manufacturersVendorId,
})
}
if (preview) {
this.formGroup.disable()
}
2 years ago
}
public getValues() {
let values = null
if (FormValidators.validateFormGroup(this.formGroup)) {
const v = this.formGroup.getRawValue()
2 years ago
console.log('v', v)
2 years ago
values = {
...v,
useUserId: v.useUserId?.[0],
manager: v.manager?.[0],
2 years ago
categoryId: v.categoryId,
ownCompanyId: v.ownCompanyId,
2 years ago
positionId: v.positionId,
2 years ago
useOrganizationId: v.useOrganizationId,
2 years ago
responsiblePerson: v.responsiblePerson?.[0],
}
}
return values
}
}