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

198 lines
5.7 KiB

12 months ago
import { Component, TemplateRef, ViewChild } from '@angular/core'
12 months ago
import { FormControl, FormGroup } from '@angular/forms'
import { AnyObject, TableOption } from 'app/shared/components/server-paginated-table'
12 months ago
import { ApiService } from 'app/services'
import { SharedModule } from 'app/shared/shared.module'
import { format } from 'date-fns'
12 months 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'
12 months ago
@Component({
selector: 'app-fixed-asset-manage',
standalone: true,
12 months ago
imports: [SharedModule, AssetFormComponent, PositionSelectComponent, ManufacturerSelectComponent],
12 months ago
templateUrl: './fixed-asset-manage.component.html',
styleUrl: './fixed-asset-manage.component.less',
})
export class FixedAssetManageComponent {
12 months ago
constructor(
private api: ApiService,
private modal: NzModalService,
private msg: NzMessageService,
) {}
12 months ago
queryForm = new FormGroup({
12 months 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(),
12 months ago
})
12 months ago
@ViewChild('copyTpl') copyTpl!: TemplateRef<NzSafeAny>
ASSET_STATUS_MAP = ASSET_STATUS_MAP()
ASSET_SOURCE_MAP = ASSET_SOURCE_MAP
12 months ago
table = new TableOption(this.fetchData.bind(this))
12 months ago
copyNum = 1
12 months ago
ngOnInit(): void {
this.table
.setConfig({
selectable: true,
12 months ago
rowKey: 'assetId',
12 months ago
})
.setColumn([
12 months 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 },
12 months ago
])
.setRowOperate([
12 months ago
{ title: '查看' },
{ title: '修改', onClick: this.onCreate.bind(this) },
{ title: '复制', onClick: this.onCopy.bind(this) },
12 months ago
{ title: '折旧记录' },
12 months ago
{ title: '二维码', onClick: this.qrcode.bind(this) },
12 months ago
{ title: '操作明细' },
12 months ago
{ title: '删除', onClick: this.deleteItem.bind(this) },
12 months ago
])
}
fetchData(p: {}, q: AnyObject) {
12 months ago
return this.api.getAssetPage({ ...p, ...q })
}
12 months ago
12 months 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) {
this.modal.create({
nzTitle: data ? '编辑资产' : '添加资产',
nzContent: AssetFormComponent,
nzWidth: '80vw',
nzWrapClassName: 'modal-lg',
nzData: data,
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()
12 months ago
},
})
12 months 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生成成功')
})
12 months ago
}
}