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.
163 lines
4.5 KiB
163 lines
4.5 KiB
12 months ago
|
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core'
|
||
|
import { SharedModule } from 'app/shared/shared.module'
|
||
|
import { ApiService } from 'app/services'
|
||
|
import { FormBuilder, FormGroup } from '@angular/forms'
|
||
|
import { AnyObject, TableOption } from 'app/shared/components/server-paginated-table'
|
||
|
import { NzSafeAny } from 'ng-zorro-antd/core/types'
|
||
|
import { NzModalService } from 'ng-zorro-antd/modal'
|
||
|
import { NzMessageService } from 'ng-zorro-antd/message'
|
||
|
import { NzDrawerRef, NzDrawerService } from 'ng-zorro-antd/drawer'
|
||
|
import { lastValueFrom } from 'rxjs'
|
||
|
import { FormValidators } from 'app/utils'
|
||
|
import { SelectUserByOrgComponent } from 'app/components'
|
||
|
|
||
|
@Component({
|
||
|
selector: 'app-stockaking-job',
|
||
|
standalone: true,
|
||
|
imports: [SharedModule, SelectUserByOrgComponent],
|
||
|
templateUrl: './stockaking-job.component.html',
|
||
|
styleUrl: './stockaking-job.component.less',
|
||
|
})
|
||
|
export class StockakingJobComponent {
|
||
|
constructor(
|
||
|
private modal: NzModalService,
|
||
|
private msg: NzMessageService,
|
||
|
private drawer: NzDrawerService,
|
||
|
private api: ApiService,
|
||
|
private fb: FormBuilder,
|
||
|
) {}
|
||
|
|
||
|
table = new TableOption(this.fetchData.bind(this))
|
||
|
|
||
|
queryForm!: FormGroup
|
||
|
|
||
|
createForm!: FormGroup
|
||
|
|
||
|
drawerRef?: NzDrawerRef
|
||
|
|
||
|
@ViewChild('drawerFooterTpl') drawerFooterTpl!: TemplateRef<NzSafeAny>
|
||
|
|
||
|
@ViewChild('formContentTpl') formContentTpl!: TemplateRef<NzSafeAny>
|
||
|
|
||
|
initCreateForm() {
|
||
|
this.createForm = this.fb.group({
|
||
|
stocktakingJobId: [],
|
||
|
name: ['', [FormValidators.required('请输入')]],
|
||
|
notes: ['', []],
|
||
|
fullStocktaking: [1, []],
|
||
|
stocktakingStartDate: [null, []],
|
||
|
stocktakingEndDate: [null, []],
|
||
|
})
|
||
|
}
|
||
|
initQueryForm() {
|
||
|
this.queryForm = this.fb.group({
|
||
|
name: [''],
|
||
|
uscc: [''],
|
||
|
code: [''],
|
||
|
})
|
||
|
}
|
||
|
|
||
|
ngOnInit(): void {
|
||
|
this.table
|
||
|
.setConfig({
|
||
|
selectable: true,
|
||
|
rowKey: 'stocktakingJobId',
|
||
|
})
|
||
|
.setColumn([
|
||
|
{ key: 'name', title: '名称' },
|
||
|
{ key: 'fullStocktaking', title: '全员盘点' },
|
||
|
{ key: 'status', title: '盘点状态' },
|
||
|
{ key: 'head', title: '负责人' },
|
||
|
{ key: 'stocktakingUserId', title: '盘点人' },
|
||
|
{ key: 'stocktakingStartDate', title: '购置开始日期', width: '180px' },
|
||
|
{ key: 'stocktakingEndDate', title: '购置结束日期', width: '180px' },
|
||
|
{ key: 'createTime', title: '创建时间', width: '180px' },
|
||
|
{ key: 'createUser', title: '创建人' },
|
||
|
{ key: 'notes', title: '备注' },
|
||
|
])
|
||
|
.setRowOperate([
|
||
|
{ title: '编辑', onClick: this.onCreate.bind(this) },
|
||
|
{ title: '编辑', onClick: this.onCreate.bind(this) },
|
||
|
{ title: '删除', onClick: this.deleteItem.bind(this) },
|
||
|
])
|
||
|
this.initQueryForm()
|
||
|
this.initCreateForm()
|
||
|
}
|
||
|
|
||
|
fetchData(p: {}, q: AnyObject) {
|
||
|
return this.api.getStocktakingJobPage({ ...p, ...q })
|
||
|
}
|
||
|
|
||
|
onCreate(data?: NzSafeAny) {
|
||
|
if (data) {
|
||
|
this.createForm.patchValue(data)
|
||
|
}
|
||
|
this.drawerRef = this.drawer.create({
|
||
|
nzTitle: data ? '编辑盘点任务' : '新增盘点任务',
|
||
|
nzContent: this.formContentTpl,
|
||
|
nzFooter: this.drawerFooterTpl,
|
||
|
nzWidth: 600,
|
||
|
nzOnCancel: this.onCancel.bind(this),
|
||
|
})
|
||
|
}
|
||
|
|
||
|
onConfirm() {
|
||
|
if (FormValidators.validateFormGroup(this.createForm)) {
|
||
|
const { value } = this.createForm
|
||
|
|
||
|
this.api
|
||
|
.saveStocktakingJob({
|
||
|
...value,
|
||
|
|
||
|
// stocktakingJobId: value.stocktakingJobId ?? 0,
|
||
|
})
|
||
|
.subscribe((res) => {
|
||
|
this.msg.success(res.desc)
|
||
|
this.onCancel()
|
||
|
this.table.ref.reload()
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async onCancel() {
|
||
|
this.drawerRef?.close()
|
||
|
this.createForm.reset({})
|
||
|
}
|
||
|
|
||
|
deleteItem(item: NzSafeAny) {
|
||
|
this.modal.confirm({
|
||
|
nzTitle: '警告',
|
||
|
nzContent: '是否要删除该盘点任务?',
|
||
|
nzOnOk: async () => {
|
||
|
const res = await lastValueFrom(this.api.deleteStocktakingJob([item.stocktakingJobId]))
|
||
|
this.msg.success(res.desc)
|
||
|
this.table.ref.reload()
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
onBegin() {
|
||
|
const ids = Array.from(this.table.ref.selected).map((i) => Number(i))
|
||
|
this.modal.confirm({
|
||
|
nzTitle: '警告',
|
||
|
nzContent: '是否要开始该盘点任务?',
|
||
|
nzOnOk: async () => {
|
||
|
const res = await lastValueFrom(this.api.beginStocktakingJob(ids))
|
||
|
this.msg.success(res.desc)
|
||
|
this.table.ref.reload()
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
onStop() {
|
||
|
const ids = Array.from(this.table.ref.selected).map((i) => Number(i))
|
||
|
this.modal.confirm({
|
||
|
nzTitle: '警告',
|
||
|
nzContent: '是否要结束该盘点任务?',
|
||
|
nzOnOk: async () => {
|
||
|
const res = await lastValueFrom(this.api.stopStocktakingJob(ids))
|
||
|
this.msg.success(res.desc)
|
||
|
this.table.ref.reload()
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
}
|