import { Component, OnInit, ViewChild, Input, Output, EventEmitter, SimpleChanges } from '@angular/core'; import { RhBaseQueryDto, RhSelectableDto, RhTableQueryOptionDto, DataResultT, RhDynamicInterfaceDto, CodeClassModel, RhDynamicTableFieldDto, RhDynamicComponentFieldType, RhSafeAny } from 'rh-base/model'; import { MsgHelper } from 'rh-base/core'; import { DynamicFormComponent } from 'rh-base/shared'; @Component({ selector: 'rh-warehouse-shelf-table-select', templateUrl: './warehouse-shelf-table-select.component.html', styleUrls: ['./warehouse-shelf-table-select.component.less'] }) export class WarehouseShelfTableSelectComponent implements OnInit { @ViewChild('warehouseShelfTableSelectQueryForm', { static: false }) queryFormCmt!: DynamicFormComponent; @Input() rhDefaultQueryDto!: RhBaseQueryDto; @Output() rhModelChange = new EventEmitter(); /** 搜索选项 */ queryOption = RhTableQueryOptionDto.create(1, 10); selectedData: RhSelectableDto | null = null; /** 表格Loading */ dataLoading = false; dataresult!: DataResultT; //#region default setting区域 /** 设置默认搜索接口 */ defaultFormInterface: RhDynamicInterfaceDto = { interfaceType: 'post', port: 52880, controllerName: 'WarehouseWebApi', interfaceName: 'GetWarehouseShelfConfigDatas' }; /** 设置默认的form显示字段 */ defaultFormFieldDataset: RhSafeAny[] = [ { name: 'WarehouseShelfCode', displayName: '货架代码', placeholder: '货架代码', editable: true }, { name: 'WarehouseShelfName', displayName: '货架名称', placeholder: '货架名称', editable: true } ]; /** 设置默认的table显示字段 */ defaultTableFieldDataset: RhSafeAny[] = [ { name: 'WarehouseShelfCode', displayName: '货架代码', width: 100 }, { name: 'WarehouseShelfName', displayName: '货架名称', width: 100 }, { name: 'WarehouseCode', displayName: '仓库代码', width: 100 }, { name: 'WarehouseAreaCode', displayName: '库区代码', width: 100 }, { name: 'Remark', displayName: '备注', width: 100 } ]; //#endregion default setting区域结束 constructor() { // } ngOnInit(): void { // } ngOnChanges(changes: SimpleChanges): void { const { rhDefaultQueryDto } = changes; if (rhDefaultQueryDto && rhDefaultQueryDto.currentValue) { setTimeout(() => { this.getDatas(); }, 1000); } } setDatas(result: DataResultT) { if (result && result.Success) { this.dataresult = result; } else { this.dataresult.Attach = []; this.dataresult = { ...this.dataresult }; MsgHelper.ShowWarningMessage(`搜索无数据!${result.Message}`); } } dataLoadingChange(status: boolean) { this.dataLoading = status; } onSelectedDatasChange(datas: RhSelectableDto[]) { if (datas?.length === 1) { this.selectedData = datas[0]; } else { this.selectedData = null; } this.rhModelChange.emit(this.selectedData as RhSelectableDto); } refreshDatas(option: RhTableQueryOptionDto) { this.queryOption = option; this.getDatas(option); } setInitFieldDataset(item: CodeClassModel) { const tempDatas: RhDynamicComponentFieldType[] = []; item.CodeProperties.forEach((ele) => { const temp = RhDynamicTableFieldDto.create(); temp.name = ele.PropertyName; temp.displayName = ele.Descirption; tempDatas.push(temp); }); this.defaultTableFieldDataset = [...tempDatas]; } // 调用子组件中的接口 private getDatas(option?: RhTableQueryOptionDto) { option = option || this.queryOption; if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } }