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.
197 lines
5.7 KiB
197 lines
5.7 KiB
import { Component, TemplateRef, ViewChild } 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 { 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'
|
|
|
|
@Component({
|
|
selector: 'app-fixed-asset-manage',
|
|
standalone: true,
|
|
imports: [SharedModule, AssetFormComponent, PositionSelectComponent, ManufacturerSelectComponent],
|
|
templateUrl: './fixed-asset-manage.component.html',
|
|
styleUrl: './fixed-asset-manage.component.less',
|
|
})
|
|
export class FixedAssetManageComponent {
|
|
constructor(
|
|
private api: ApiService,
|
|
private modal: NzModalService,
|
|
private msg: NzMessageService,
|
|
) {}
|
|
|
|
queryForm = new FormGroup({
|
|
name: new FormControl(),
|
|
model: new FormControl(),
|
|
status: new FormControl(),
|
|
assetCode: new FormControl(),
|
|
serialNumber: new FormControl(),
|
|
sourceId: new FormControl(),
|
|
positionId: new FormControl(),
|
|
manufacturersVendorId: new FormControl(),
|
|
})
|
|
|
|
@ViewChild('copyTpl') copyTpl!: TemplateRef<NzSafeAny>
|
|
|
|
ASSET_STATUS_MAP = ASSET_STATUS_MAP()
|
|
|
|
ASSET_SOURCE_MAP = ASSET_SOURCE_MAP
|
|
|
|
table = new TableOption(this.fetchData.bind(this))
|
|
|
|
copyNum = 1
|
|
|
|
ngOnInit(): void {
|
|
this.table
|
|
.setConfig({
|
|
selectable: true,
|
|
rowKey: 'assetId',
|
|
})
|
|
.setColumn([
|
|
{ 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 },
|
|
])
|
|
.setRowOperate([
|
|
{ title: '查看' },
|
|
{ title: '修改', onClick: this.onCreate.bind(this) },
|
|
{ title: '复制', onClick: this.onCopy.bind(this) },
|
|
{ title: '折旧记录' },
|
|
{ title: '二维码', onClick: this.qrcode.bind(this) },
|
|
{ title: '操作明细' },
|
|
{ title: '删除', onClick: this.deleteItem.bind(this) },
|
|
])
|
|
}
|
|
|
|
fetchData(p: {}, q: AnyObject) {
|
|
return this.api.getAssetPage({ ...p, ...q })
|
|
}
|
|
|
|
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()
|
|
},
|
|
})
|
|
}
|
|
|
|
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生成成功')
|
|
})
|
|
}
|
|
}
|
|
|