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.
230 lines
5.9 KiB
230 lines
5.9 KiB
import { STOCKTAKING_JOB_STATUS_MAP } from './../../../../constants/index'
|
|
import {
|
|
ChangeDetectorRef,
|
|
Component,
|
|
EventEmitter,
|
|
Input,
|
|
OnInit,
|
|
Output,
|
|
TemplateRef,
|
|
ViewChild,
|
|
forwardRef,
|
|
} from '@angular/core'
|
|
import { ControlValueAccessor, FormControl, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms'
|
|
|
|
import { NzSafeAny } from 'ng-zorro-antd/core/types'
|
|
|
|
import { NzModalService } from 'ng-zorro-antd/modal'
|
|
|
|
import { ApiService } from 'app/services'
|
|
import { NzMessageService } from 'ng-zorro-antd/message'
|
|
|
|
import { SharedModule } from 'app/shared/shared.module'
|
|
import { FormValidators, Utils } from 'app/utils'
|
|
import { NzFormatEmitEvent, NzTreeNode } from 'ng-zorro-antd/tree'
|
|
import { NzTreeSelectComponent } from 'ng-zorro-antd/tree-select'
|
|
import { ASSET_SOURCE_MAP, ASSET_STATUS_MAP, MAX_PAGE_SIZE } from 'app/constants'
|
|
import { AnyObject, TableOption } from 'app/shared/components/server-paginated-table'
|
|
import { AssetSelectComponent, StocktakingDetailFormComponent } from 'app/components'
|
|
import { lastValueFrom } from 'rxjs'
|
|
import { ActivatedRoute } from '@angular/router'
|
|
|
|
@Component({
|
|
selector: 'app-stocktaking-detail',
|
|
standalone: true,
|
|
imports: [SharedModule],
|
|
templateUrl: './stocktaking-detail.component.html',
|
|
styleUrl: './stocktaking-detail.component.less',
|
|
})
|
|
export class StocktakingDetailComponent {
|
|
constructor(
|
|
private api: ApiService,
|
|
private modal: NzModalService,
|
|
private msg: NzMessageService,
|
|
private route: ActivatedRoute,
|
|
) {}
|
|
|
|
@ViewChild('startTpl') startTpl!: TemplateRef<{}>
|
|
|
|
originData: NzSafeAny[] = []
|
|
|
|
loading = false
|
|
|
|
ASSET_SOURCE_MAP = ASSET_SOURCE_MAP
|
|
|
|
ASSET_STATUS_MAP = ASSET_STATUS_MAP()
|
|
|
|
STOCKTAKING_JOB_STATUS_MAP = STOCKTAKING_JOB_STATUS_MAP
|
|
|
|
table = new TableOption(this.fetchData.bind(this))
|
|
|
|
uploadImgLoading = false
|
|
|
|
uploadLoading = false
|
|
|
|
iconPreview = ''
|
|
|
|
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(),
|
|
})
|
|
|
|
onImgChange(e: Event) {
|
|
const target = e.target as HTMLInputElement
|
|
const file = target.files![0]
|
|
target.value = ''
|
|
if (file.size / 1024 / 1024 >= 2) {
|
|
this.msg.error('图片大小不能超过2M')
|
|
return
|
|
}
|
|
const fileReader = new FileReader()
|
|
fileReader.onload = () => {
|
|
const base64 = fileReader.result as string
|
|
this.iconPreview = base64
|
|
}
|
|
fileReader.readAsDataURL(file)
|
|
const formdata = new FormData()
|
|
formdata.append('file', file)
|
|
this.api.upload(formdata).subscribe((res) => {
|
|
this.startForm.get('img')?.setValue(res.body.fileName)
|
|
})
|
|
}
|
|
|
|
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.upload(formdata).subscribe((res) => {
|
|
this.startForm.get('attachment')?.setValue(res.body.fileName)
|
|
})
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.api
|
|
.getBasicSupplierVendorPage({
|
|
pageSize: MAX_PAGE_SIZE,
|
|
pageNum: 1,
|
|
})
|
|
.subscribe((res) => {
|
|
this.originData = res.body.rows
|
|
})
|
|
this.table
|
|
.setConfig({
|
|
selectable: true,
|
|
})
|
|
.setColumn([
|
|
{ key: 'id', title: '主键', visible: true },
|
|
{ key: 'code', title: '资产编号', visible: true },
|
|
{ key: 'name', title: '资产名称', visible: true },
|
|
// { key: 'category', title: '资产分类', visible: true },
|
|
{ key: 'status', title: '盘点状态', visible: true },
|
|
{ key: 'createTime', title: '操作时间', visible: true },
|
|
// { key: '_ownCompany', title: '所属公司', visible: true },
|
|
// { key: '_useOrganization', title: '使用组织', visible: true },
|
|
// { key: '_position', title: '存放位置', visible: true },
|
|
])
|
|
.setRowOperate([
|
|
{
|
|
title: '开始盘点',
|
|
onClick: this.onStart.bind(this),
|
|
},
|
|
])
|
|
}
|
|
|
|
fetchData(p: {}, q: AnyObject) {
|
|
return this.api
|
|
.getStocktakingJobDetailPage({
|
|
...p,
|
|
...q,
|
|
stocktakingJobId: Number(this.route.snapshot.paramMap.get('id')),
|
|
})
|
|
.pipe()
|
|
}
|
|
|
|
add(data?: NzSafeAny) {
|
|
let nzTitle = data ? '编辑资产盘点' : '添加资产盘点'
|
|
|
|
this.modal.create({
|
|
nzTitle,
|
|
nzContent: StocktakingDetailFormComponent,
|
|
nzWidth: '80vw',
|
|
nzWrapClassName: 'modal-lg',
|
|
nzData: {
|
|
value: data,
|
|
},
|
|
nzOnOk: async (e) => {
|
|
const vals = e.getValues()
|
|
if (vals) {
|
|
const res = await lastValueFrom(
|
|
this.api.saveStocktakingJobDetail({
|
|
...vals,
|
|
stocktakingJobId: Number(this.route.snapshot.paramMap.get('id')),
|
|
}),
|
|
)
|
|
this.msg.success(res.desc)
|
|
this.table.ref.reload()
|
|
return true
|
|
}
|
|
|
|
return false
|
|
},
|
|
})
|
|
}
|
|
|
|
startForm = new FormGroup({
|
|
status: new FormControl(null, [FormValidators.required('请选择盘点状态')]),
|
|
img: new FormControl(null, []),
|
|
attachment: new FormControl(null, []),
|
|
notes: new FormControl(null, []),
|
|
})
|
|
|
|
onStart(data: NzSafeAny) {
|
|
this.modal.create({
|
|
nzTitle: '开始盘点',
|
|
nzContent: this.startTpl,
|
|
nzOnOk: async () => {
|
|
if (FormValidators.validateFormGroup(this.startForm)) {
|
|
const res = await lastValueFrom(
|
|
this.api.startStocktakingJob({
|
|
...this.startForm.value,
|
|
stocktakingJobId: Number(this.route.snapshot.paramMap.get('id')),
|
|
assetId: data._asset.assetId,
|
|
id: data.id,
|
|
}),
|
|
)
|
|
this.msg.success(res.desc)
|
|
this.table.ref.reload()
|
|
this.startForm.reset()
|
|
return true
|
|
}
|
|
return false
|
|
},
|
|
nzOnCancel: () => {
|
|
this.startForm.reset()
|
|
},
|
|
})
|
|
}
|
|
|
|
deleteItem() {
|
|
this.modal.confirm({
|
|
nzTitle: '警告',
|
|
nzContent: '是否要删除该盘点?',
|
|
nzOnOk: async () => {
|
|
const res = await lastValueFrom(
|
|
this.api.deleteStocktakingDetail(Array.from(this.table.ref.selected).map((i) => Number(i))),
|
|
)
|
|
this.msg.success(res.desc)
|
|
this.table.ref.reload()
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|