|
|
|
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 { 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 { PositionSelectComponent } from '../position-select/position-select.component'
|
|
|
|
import { ManufacturerSelectComponent } from '../manufacturer-select/manufacturer-select.component'
|
|
|
|
import { tap } from 'rxjs'
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-asset-select',
|
|
|
|
standalone: true,
|
|
|
|
imports: [SharedModule, PositionSelectComponent, ManufacturerSelectComponent],
|
|
|
|
templateUrl: './asset-select.component.html',
|
|
|
|
styleUrl: './asset-select.component.less',
|
|
|
|
providers: [
|
|
|
|
{
|
|
|
|
provide: NG_VALUE_ACCESSOR,
|
|
|
|
multi: true,
|
|
|
|
useExisting: forwardRef(() => AssetSelectComponent),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
export class AssetSelectComponent {
|
|
|
|
constructor(
|
|
|
|
private api: ApiService,
|
|
|
|
private modal: NzModalService,
|
|
|
|
private msg: NzMessageService,
|
|
|
|
) {}
|
|
|
|
|
|
|
|
@Input() radio: boolean = false
|
|
|
|
|
|
|
|
@Input() storage: boolean = false
|
|
|
|
|
|
|
|
@Output() onSelected = new EventEmitter<NzSafeAny>()
|
|
|
|
|
|
|
|
allGetedDataMap = new Map<number, NzSafeAny>()
|
|
|
|
|
|
|
|
originData: NzSafeAny[] = []
|
|
|
|
|
|
|
|
value?: string
|
|
|
|
|
|
|
|
disabled = false
|
|
|
|
|
|
|
|
selectedDataList: NzSafeAny[] = []
|
|
|
|
|
|
|
|
checkedAll = false
|
|
|
|
|
|
|
|
loading = false
|
|
|
|
|
|
|
|
indeterminate = false
|
|
|
|
|
|
|
|
setOfCheckedId = new Set<number>()
|
|
|
|
|
|
|
|
ASSET_SOURCE_MAP = ASSET_SOURCE_MAP
|
|
|
|
|
|
|
|
ASSET_STATUS_MAP = ASSET_STATUS_MAP()
|
|
|
|
|
|
|
|
table = new TableOption(this.fetchData.bind(this))
|
|
|
|
|
|
|
|
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(),
|
|
|
|
})
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.api.getBasicSupplierVendorPage({ pageSize: MAX_PAGE_SIZE, pageNum: 1 }).subscribe((res) => {
|
|
|
|
this.originData = res.body.rows
|
|
|
|
})
|
|
|
|
this.table
|
|
|
|
.setConfig({
|
|
|
|
selectable: true,
|
|
|
|
rowKey: 'assetId',
|
|
|
|
radio: this.radio,
|
|
|
|
noneCache: true,
|
|
|
|
})
|
|
|
|
.setColumn([
|
|
|
|
{ key: 'assetCode', title: '资产编号', visible: true },
|
|
|
|
{ key: 'name', title: '资产名称', visible: true },
|
|
|
|
|
|
|
|
{ key: 'status', title: '资产状态', visible: true },
|
|
|
|
{ key: 'count', title: '库存数量', visible: true },
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchData(p: {}, q: AnyObject) {
|
|
|
|
const fn = this.storage ? 'getAeamBusinessStorageList' : 'getAssetStroagePage'
|
|
|
|
return this.api[fn]({ ...p, ...q }).pipe(
|
|
|
|
tap((res) => {
|
|
|
|
res.body.rows.forEach((item: NzSafeAny) => {
|
|
|
|
this.allGetedDataMap.set(item.assetId, item)
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
onTrigger(nzContent: TemplateRef<{}>) {
|
|
|
|
this.modal.create({
|
|
|
|
nzTitle: '选择资产',
|
|
|
|
nzContent,
|
|
|
|
nzWidth: '80vw',
|
|
|
|
nzWrapClassName: 'modal-lg',
|
|
|
|
nzOnOk: () => {
|
|
|
|
if (this.radio) {
|
|
|
|
this.selectedDataList = []
|
|
|
|
}
|
|
|
|
this.allGetedDataMap.forEach((i: NzSafeAny) => {
|
|
|
|
if (this.table.ref.selected.has(String(i.assetId))) {
|
|
|
|
if (!this.selectedDataList.some((s) => s.assetId === i.assetId)) {
|
|
|
|
this.selectedDataList.push({ ...i, count: 1, max: i.count })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.selectedDataList = this.selectedDataList.slice()
|
|
|
|
this.refreshCheckedStatus()
|
|
|
|
this.onChange(this.selectedDataList)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
onRemove() {
|
|
|
|
this.selectedDataList = this.selectedDataList.filter((i) => !this.setOfCheckedId.has(i.assetId))
|
|
|
|
this.refreshCheckedStatus()
|
|
|
|
this.onChange(this.selectedDataList)
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCheckedSet(id: number, checked: boolean): void {
|
|
|
|
if (checked) {
|
|
|
|
this.setOfCheckedId.add(id)
|
|
|
|
} else {
|
|
|
|
this.setOfCheckedId.delete(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshCheckedStatus(): void {
|
|
|
|
const listOfEnabledData = this.selectedDataList.filter(({ disabled }) => !disabled)
|
|
|
|
this.checkedAll = listOfEnabledData.every(({ assetId }) => this.setOfCheckedId.has(assetId))
|
|
|
|
this.indeterminate =
|
|
|
|
listOfEnabledData.some(({ assetId }) => this.setOfCheckedId.has(assetId)) && !this.checkedAll
|
|
|
|
}
|
|
|
|
|
|
|
|
onItemChecked(id: number, checked: boolean): void {
|
|
|
|
this.updateCheckedSet(id, checked)
|
|
|
|
this.refreshCheckedStatus()
|
|
|
|
}
|
|
|
|
|
|
|
|
onAllChecked(checked: boolean): void {
|
|
|
|
this.selectedDataList
|
|
|
|
.filter(({ disabled }) => !disabled)
|
|
|
|
.forEach(({ assetId }) => this.updateCheckedSet(assetId, checked))
|
|
|
|
this.refreshCheckedStatus()
|
|
|
|
}
|
|
|
|
|
|
|
|
onTouched = () => {}
|
|
|
|
|
|
|
|
onChange(v: NzSafeAny[]) {}
|
|
|
|
|
|
|
|
writeValue(v: NzSafeAny): void {
|
|
|
|
let vals = v
|
|
|
|
if (typeof v === 'string') {
|
|
|
|
try {
|
|
|
|
vals = JSON.parse(v) ?? []
|
|
|
|
} catch (error) {}
|
|
|
|
}
|
|
|
|
if (Array.isArray(vals) && vals.length > 0) {
|
|
|
|
// const ids = vals.map((i: NzSafeAny) => i.assetId)
|
|
|
|
this.api.getAssetStorageListByIds(vals).subscribe((res) => {
|
|
|
|
this.selectedDataList = res.body.rows.map((item: NzSafeAny) => {
|
|
|
|
this.allGetedDataMap.set(item.assetId, item)
|
|
|
|
return item
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
registerOnChange(fn: any): void {
|
|
|
|
this.onChange = fn
|
|
|
|
}
|
|
|
|
|
|
|
|
registerOnTouched(fn: any): void {
|
|
|
|
this.onTouched = fn
|
|
|
|
}
|
|
|
|
|
|
|
|
setDisabledState?(isDisabled: boolean): void {
|
|
|
|
this.disabled = isDisabled
|
|
|
|
}
|
|
|
|
}
|