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

204 lines
5.7 KiB

2 years ago
import { Component, TemplateRef, ViewChild } from '@angular/core'
2 years ago
import { FormControl, FormGroup } from '@angular/forms'
import { AnyObject, TableOption } from 'app/shared/components/server-paginated-table'
2 years ago
import { ApiService } from 'app/services'
import { SharedModule } from 'app/shared/shared.module'
import { format } from 'date-fns'
2 years ago
import { lastValueFrom, of } from 'rxjs'
import { AssetFormComponent, ManufacturerSelectComponent, PositionSelectComponent } from 'app/components'
import { NzModalRef, NzModalService } from 'ng-zorro-antd/modal'
import { NzMessageService } from 'ng-zorro-antd/message'
import { NzSafeAny } from 'ng-zorro-antd/core/types'
import { ASSET_SOURCE_MAP, ASSET_STATUS, ASSET_STATUS_MAP } from 'app/constants'
import { Utils } from 'app/utils'
2 years ago
@Component({
selector: 'app-fixed-asset-manage',
standalone: true,
2 years ago
imports: [SharedModule, AssetFormComponent, PositionSelectComponent, ManufacturerSelectComponent],
2 years ago
templateUrl: './fixed-asset-manage.component.html',
styleUrl: './fixed-asset-manage.component.less',
})
export class FixedAssetManageComponent {
2 years ago
constructor(
private api: ApiService,
private modal: NzModalService,
private msg: NzMessageService,
) {}
2 years ago
queryForm = new FormGroup({
2 years ago
name: new FormControl(),
model: new FormControl(),
status: new FormControl(),
assetCode: new FormControl(),
serialNumber: new FormControl(),
sourceId: new FormControl(),
positionId: new FormControl(),
manufacturersVendorId: new FormControl(),
2 years ago
})
2 years ago
@ViewChild('copyTpl') copyTpl!: TemplateRef<NzSafeAny>
ASSET_STATUS_MAP = ASSET_STATUS_MAP()
ASSET_SOURCE_MAP = ASSET_SOURCE_MAP
2 years ago
table = new TableOption(this.fetchData.bind(this))
2 years ago
copyNum = 1
2 years ago
ngOnInit(): void {
this.table
.setConfig({
selectable: true,
2 years ago
rowKey: 'assetId',
2 years ago
})
.setColumn([
2 years ago
{ key: 'assetCode', title: '资产编号', visible: true },
{ key: 'name', title: '资产名称', visible: true },
{ key: '_category', title: '资产分类', visible: true },
{ key: 'status', title: '资产状态', visible: true },
{ key: '_ownCompany', title: '所属公司', visible: true },
{ key: '_useOrganization', title: '使用组织', visible: true },
{ key: '_position', title: '存放位置', visible: true },
2 years ago
])
.setRowOperate([
{
title: '查看',
onClick: (v) => {
this.onCreate(v, true)
},
},
2 years ago
{ title: '修改', onClick: this.onCreate.bind(this) },
{ title: '复制', onClick: this.onCopy.bind(this) },
{ title: '二维码', onClick: this.qrcode.bind(this) },
{ title: '删除', onClick: this.deleteItem.bind(this) },
2 years ago
])
}
fetchData(p: {}, q: AnyObject) {
2 years ago
return this.api.getAssetPage({ ...p, ...q })
}
2 years ago
2 years ago
onCopy(data: NzSafeAny) {
this.modal.create({
nzTitle: '复制资产',
nzWidth: 600,
nzContent: this.copyTpl,
nzOnOk: async () => {
if (!this.copyNum) {
this.msg.error('请输入复制数量')
return false
}
const res = await lastValueFrom(this.api.copyAsset(this.copyNum, data.assetId))
this.msg.success(res.desc)
this.table.ref.reload()
return true
},
})
}
onCreate(data?: NzSafeAny, preview?: boolean) {
2 years ago
this.modal.create({
nzTitle: data ? '编辑资产' : '添加资产',
nzContent: AssetFormComponent,
nzWidth: '80vw',
nzWrapClassName: 'modal-lg',
nzData: {
value: data,
preview,
},
2 years ago
nzOnOk: async (e) => {
const vals = e.getValues()
if (vals) {
const res = await lastValueFrom(this.api.saveAsset(vals))
this.msg.success(res.desc)
this.table.ref.reload()
return true
}
return false
},
})
}
deleteItem(item?: NzSafeAny) {
const ids = item ? [item.assetId] : Array.from(this.table.ref.selected)
this.modal.confirm({
nzTitle: '警告',
nzContent: `是否要删除${ids.length}个资产?`,
nzOnOk: async () => {
const res = await lastValueFrom(this.api.deleteAsset(ids))
this.msg.success(res.desc)
this.table.ref.reload()
},
})
}
confirmAsset() {
const ids = Array.from(this.table.ref.selected).map((i) => Number(i))
this.modal.confirm({
nzTitle: '警告',
nzContent: `是否对选择的${ids.length}个资产进行确认?`,
nzOnOk: async () => {
const res = await lastValueFrom(this.api.confirmAsset(ids))
this.msg.success(res.desc)
this.table.ref.reload()
2 years ago
},
})
2 years ago
}
qrcode(d: NzSafeAny) {
this.msg.loading('二维码生成中...')
this.api.assetQrcode(d.assetId).subscribe((res) => {
Utils.downLoadFile(res, 'application/pdf')
this.msg.remove()
this.msg.success('二维码生成成功')
})
}
downloadTemplate() {
this.msg.loading('模板下载中...')
this.api.downloadAssetTemplate().subscribe((res) => {
Utils.downLoadFile(res, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8')
this.msg.remove()
this.msg.success('模板下载成功')
})
}
importModalRef?: NzModalRef
importExcel(nzContent: TemplateRef<{}>) {
this.importModalRef = this.modal.create({
nzTitle: '资产数据导入',
nzContent,
nzFooter: null,
})
}
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.uploadAsset(formdata).subscribe((res) => {
this.importModalRef?.close()
this.msg.success(res.desc)
this.table.ref.reload()
})
}
exportExcel() {
const ids = Array.from(this.table.ref.selected).map((i) => Number(i))
if (ids.length === 0) {
return
}
this.msg.loading('Excel生成中...')
this.api.exportAsset(ids).subscribe((res) => {
Utils.downLoadFile(res, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8')
this.msg.remove()
this.msg.success('Excel生成成功')
})
2 years ago
}
}