import { Component } from '@angular/core' import { FormControl, FormGroup } from '@angular/forms' import { AnyObject, TableOption } from 'app/shared/components/server-paginated-table' import { ApiService } from 'app/services' import { SharedModule } from 'app/shared/shared.module' import { format } from 'date-fns' import { lastValueFrom, of } from 'rxjs' import { NzSafeAny } from 'ng-zorro-antd/core/types' import { NzModalService } from 'ng-zorro-antd/modal' import { NzMessageService } from 'ng-zorro-antd/message' import { AssetBusinessCollectionComponent, AssetBusinessStorageFormComponent } from 'app/components' import { BUSINESS_STATUS_MAP } from 'app/constants' @Component({ selector: 'app-fixed-asset-manage-distribution', standalone: true, imports: [SharedModule], templateUrl: './fixed-asset-manage-distribution.component.html', styleUrl: './fixed-asset-manage-distribution.component.less', }) export class FixedAssetManageDistributionComponent { constructor( private api: ApiService, private modal: NzModalService, private msg: NzMessageService, ) {} queryForm = new FormGroup({ name: new FormControl(), businessId: new FormControl(), status: new FormControl(), date: new FormControl(), }) BUSINESS_STATUS_MAP = BUSINESS_STATUS_MAP table = new TableOption(this.fetchData.bind(this)) ngOnInit(): void { this.table // .setConfig({ // selectable: true, // rowKey: 'id', // }) .setColumn([ { key: 'id', title: '主键', visible: false }, { key: 'businessId', title: '业务编号', visible: true, width: '350px' }, { key: 'name', title: '业务名称', visible: true }, { key: 'status', title: '办理状态', visible: true }, { key: '_useOrganization', title: '领用后公司/部门', visible: true }, { key: '_useUser', title: '使用人员', visible: true }, { key: '_position', title: '存放位置', visible: true }, { key: '_position', title: '详细位置', visible: true }, { key: 'businessGeneratedDate', title: '领用日期', visible: true }, { key: 'notes', title: '备注', visible: true }, ]) .setRowOperate([ { title: '查看', onClick: (v) => { this.onCreate(v, true) }, }, { title: '修改', onClick: this.onCreate.bind(this) }, { title: '确认', onClick: this.confirm.bind(this) }, // { title: '单据' }, { title: '删除', onClick: this.deleteItem.bind(this) }, ]) } fetchData(p: {}, q: AnyObject) { return this.api.getBusinessCollectionPage({ ...p, ...q }) } onCreate(data?: NzSafeAny, preview?: boolean) { this.modal.create({ nzTitle: data ? '编辑资产领用' : '添加资产领用', nzContent: AssetBusinessCollectionComponent, nzWidth: '80vw', nzWrapClassName: 'modal-lg', nzData: { value: data, preview, }, nzOnOk: async (e) => { const vals = e.getValues() if (vals) { const res = await lastValueFrom(this.api.saveBusinessCollection(vals)) this.msg.success(res.desc) this.table.ref.reload() return true } return false }, }) } confirm(item?: NzSafeAny) { const ids = [item.id] this.modal.confirm({ nzTitle: '警告', nzContent: `是否要进行该操作?`, nzOnOk: async () => { const res = await lastValueFrom(this.api.confirmBusinessCollection(ids)) this.msg.success(res.desc) this.table.ref.reload() }, }) } deleteItem(item?: NzSafeAny) { const ids = [item.id] this.modal.confirm({ nzTitle: '警告', nzContent: `是否要删除${ids.length}个资产领用?`, nzOnOk: async () => { const res = await lastValueFrom(this.api.deleteBusinessCollection(ids)) this.msg.success(res.desc) this.table.ref.reload() }, }) } }