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

219 lines
7.0 KiB

1 year ago
import { Component, Input, OnInit, ViewChild, inject } from '@angular/core'
import { FormArray, FormBuilder, FormGroup } from '@angular/forms'
2 years ago
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,
) {}
1 year ago
@ViewChild('assetCategorySelect') assetCategorySelect!: AssetCategorySelectComponent
2 years ago
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[] = []
1 year ago
flowForms: NzSafeAny[] = []
extraFields: NzSafeAny[] = []
2 years ago
ngOnInit(): void {
1 year ago
// this.api.getFlowFormList().subscribe((res) => {
// this.flowForms = res.body
// })
2 years ago
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('请选择')]),
1 year ago
// flowForm: this.fb.control(null, [FormValidators.required('请选择')]),
2 years ago
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, []),
1 year ago
_extInfo: this.fb.array([]),
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
}
1 year ago
get extInfo(): FormArray {
return this.formGroup.get('_extInfo') as FormArray
}
onExtraChange(v: any) {
let extraFields: NzSafeAny[] = []
try {
const formValue = this.assetCategorySelect.originTreeData.find((f) => f.categoryId === Number(v))
?._assetExtTemp
extraFields = formValue ?? []
} catch (error) {}
this.setExtraFields(extraFields)
}
ext = null
setExtraFields(fields: NzSafeAny[]) {
this.extInfo.clear()
this.extraFields = fields
.sort((a, b) => a.sort - b.sort)
.map((i) => {
let val = i.value
if (i.type === 'RADIO') {
val = i.value?.value
} else if (i.type === 'DATE') {
val = new Date(i.value)
}
this.extInfo.push(
this.fb.group({
key: this.fb.control(i.key),
name: this.fb.control(i.name),
remark: this.fb.control(i.remark),
sort: this.fb.control(i.sort),
type: this.fb.control(i.type),
value: this.fb.control(val),
fields: this.fb.control(i.type === 'RADIO' ? i.value?.fields : []),
}),
)
return i
})
}
2 years ago
patchValues() {
const { value: data, preview } = this.data
if (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,
})
1 year ago
this.setExtraFields(data._extInfo)
2 years ago
}
if (preview) {
this.formGroup.disable()
}
2 years ago
}
public getValues() {
let values = null
if (FormValidators.validateFormGroup(this.formGroup)) {
const v = this.formGroup.getRawValue()
1 year ago
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],
1 year ago
_extInfo: this.extInfo.value.map((v: any) => {
if (v.type === 'RADIO') {
return {
...v,
value: {
value: v.value,
fields: v.fields.map((i: string) => i),
},
}
}
return v
}),
2 years ago
}
}
return values
}
}