import { MsgHelper, ObjectHelper, RhApiUrlsService, RhNavigatorService } from 'rh-base/core'; import { RhDynamicComponentFieldType, RhPortType } from 'rh-base/model'; import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'; import { CodeClassModel, DataResultT, RhBaseDto, RhDynamicInterfaceDto, RhDynamicTableFieldDto, RhSafeAny, RhSelectableDto, RhTableButtonInfoDto, RhTableQueryOptionDto } from 'rh-base/model'; import { DynamicFormComponent } from 'rh-base/shared'; import { InspectionSpecificationStandardFileDto, InspectionSpecificationStandardFileQueryDto, IqcInspectSchemaEntryQueryDto, IqcMaterialInspectSchemaDto, IqcMaterialInspectSchemaQueryDto } from './../../../../qmp-model'; import { RhIqcManagementService } from './../../../iqc-management.service'; @Component({ selector: 'rh-inspect-schema-bind', templateUrl: './inspect-schema-bind.component.html', styleUrls: ['./inspect-schema-bind.component.less'] }) export class RhInspectSchemaBindComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; /** 当前选中的物料 */ @Input() rhSelectMaterial: RhSafeAny; /** 绑定成功后的关闭动作 */ @Output() rhClose = new EventEmitter(); // selectedIndex = 0; editDto: RhBaseDto = {}; dataLoading = false; dataresult!: DataResultT; defaultFieldDataset: RhDynamicComponentFieldType[] = []; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('navigateToSchemaPage', '转到检验方案维护', 'default', false, 'send', false, null, (data) => this.navigateToInspectSchemaPage(data as RhBaseDto) ), // new RhTableButtonInfoDto( // 'preview', // '附件预览', // 'default', // 'eye', // false, // null, // (data) => this.filePreview(data as RhBaseDto), // true, // true, // 'green' // ), new RhTableButtonInfoDto('bind', '绑定', 'default', false, 'link', false, null, (data) => this.openBindModal(data as RhBaseDto)) ]; selectData: RhBaseDto | null = null; //#region 绑定 isShowBindModal = false; supplierDatasInterfaceInfo!: RhDynamicInterfaceDto; supplierExtraButton: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('bind', '绑定供应商', 'default', false, 'link', false, null, (data) => this.bindSupplier(data as RhBaseDto[])) ]; suppliersByMaterialExtraButton: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('bindUn', '绑定供应商', 'default', false, 'link', false, null, (data) => this.bindSupplier(data as RhBaseDto[]) ) ]; bindSelectedIndex = 0; bindTabType = null; @ViewChild('supplierQueryForm', { static: false }) supplierQueryFormCmt!: DynamicFormComponent; supplierDataLoading = false; supplierDataResult!: DataResultT; supplierDefaultFieldDataset: RhDynamicComponentFieldType[] = []; // 供应商查询模型 supplierDatasQueryDto!: IqcMaterialInspectSchemaQueryDto; // 物料所属供应商数据查询模型 suppliersByMaterialQueryDto!: IqcMaterialInspectSchemaQueryDto; //#endregion // //#region 检验方案附件预览 isShowFilePreviewModal = false; fileQueryDto!: InspectionSpecificationStandardFileQueryDto; fileDatas: InspectionSpecificationStandardFileDto[] = []; //#endregion // //#region 检验项目明细 entryDatasInterfaceInfo!: RhDynamicInterfaceDto; entryDatasQueryDto!: IqcInspectSchemaEntryQueryDto; //#endregion // constructor(private apiUrl: RhApiUrlsService, private operator: RhIqcManagementService, public navigateSer: RhNavigatorService) { // } ngOnInit() { // 供应商数据相关 this.supplierDatasInterfaceInfo = this.getSupplierDatasInterfaceInfo(); this.supplierDatasQueryDto = IqcMaterialInspectSchemaQueryDto.create(); this.suppliersByMaterialQueryDto = IqcMaterialInspectSchemaQueryDto.create(); // 附件预览 this.fileQueryDto = this.initFileQueryDto(); this.entryDatasInterfaceInfo = this.getInspectItemDatasInterfaceInfo(); this.entryDatasQueryDto = IqcInspectSchemaEntryQueryDto.create(); } setDatas(dataset: DataResultT) { this.dataresult = dataset; if (!this.dataresult?.Success) { MsgHelper.ShowWarningMessage(`搜索无数据!${this.dataresult?.Message}`); } } dataLoadingChange(status: boolean) { this.dataLoading = status; } setInitFieldDatset(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.defaultFieldDataset = [...tempDatas]; } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } //调用子组件中的接口 private getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } //#region ********** 附件相关 ********** // 附件预览 filePreview(data: RhBaseDto) { this.selectData = data; // this.isShowFilePreviewModal = true; this.getInspectionSpecificationStandardFileDatas(data); } openFilePreviewModal() { this.isShowFilePreviewModal = true; } closeFilePreviewModal() { this.isShowFilePreviewModal = false; } initFileQueryDto(): InspectionSpecificationStandardFileQueryDto { const dto = InspectionSpecificationStandardFileQueryDto.create(); return dto; } // 获取附件列表 getInspectionSpecificationStandardFileDatas(dto: RhBaseDto) { this.fileQueryDto.InspectSchemaCode = dto['InspectSchemaCode']; // this.queryDto = { ...this.queryDto }; this.operator.GetInspectionSpecificationStandardFileDatas(this.fileQueryDto).subscribe((result) => { if (result && result.Success) { this.fileDatas = result.Attach; this.openFilePreviewModal(); } else { this.fileDatas = []; MsgHelper.ShowWarningModal(`查询无附件:${result.Message}`); } }); } //#endregion ********** 附件相关 ********** // //#region ********** 绑定 ********** openBindModal(data: RhBaseDto) { if (!this.rhSelectMaterial || !this.rhSelectMaterial.MaterialCode) { MsgHelper.ShowWarningModal('请先选择要绑定的物料!'); return; } this.supplierDatasQueryDto.IsBinding = false; // this.supplierDatasQueryDto.Mode = 8; this.suppliersByMaterialQueryDto.MaterialCode = this.rhSelectMaterial.MaterialCode; this.suppliersByMaterialQueryDto.IsBinding = true; // this.suppliersByMaterialQueryDto.Mode = 8; this.selectData = data; this.isShowBindModal = true; } closeBindModal() { this.isShowBindModal = false; if (this.bindSelectedIndex) { this.bindSelectedIndex = 0; } } getSupplierDatasInterfaceInfo(): RhDynamicInterfaceDto { const dto = RhDynamicInterfaceDto.create(); // 端口类型获取对应的端口号 const portNum = this.apiUrl.getPortNum(RhPortType.emp); dto.interfaceType = 'post'; dto.port = portNum; dto.controllerName = 'IqcMaterialInspectApi'; dto.interfaceName = 'GetIqcMaterialSupplierBindingRecordDatas'; return dto; } bindSupplier(dto: RhBaseDto[]) { const data = IqcMaterialInspectSchemaDto.create(); ObjectHelper.MapT(this.selectData as RhBaseDto, data, true, false); data.SupplierCode = dto[0]['SupplierCode']; data.SupplierName = dto[0]['SupplierName']; // 物料相关信息 data.MaterialCode = this.rhSelectMaterial.MaterialCode; data.MaterialName = this.rhSelectMaterial.MaterialName; data.MaterialSpecification = this.rhSelectMaterial.MaterialSpecification; data.MaterialCategory = this.rhSelectMaterial.MaterialCategory; data.IsUse = true; this.operator.StoreIqcMaterialInspectSchemaData(data).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage('供应商绑定成功!'); this.closeBindModal(); this.rhClose.emit(); } else { MsgHelper.ShowWarningMessage(`供应商绑定失败:${result.Message}`); } }); } setSupplierDatas(dataset: DataResultT) { this.supplierDataResult = dataset; if (!this.supplierDataResult?.Success) { MsgHelper.ShowWarningMessage(`搜索无数据!${this.supplierDataResult?.Message}`); } } supplierDataLoadingChange(status: boolean) { this.supplierDataLoading = status; } setSupplierInitFieldDatset(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.supplierDefaultFieldDataset = [...tempDatas]; } refreshSupplierDatas(option: RhTableQueryOptionDto) { this.getSupplierDatas(option); } //调用子组件中的接口 private getSupplierDatas(option?: RhTableQueryOptionDto) { if (this.supplierQueryFormCmt) { this.supplierQueryFormCmt.submitDefaultForm(null, option); } } //#endregion // //#region ********** 检验项目明细 ********** // openEntryDatasTab(dto: RhBaseDto) { // this.selectData = dto; // this.selectedIndex = 1; // } // closeEntryDatasTab() { // this.selectedIndex = 0; // } getInspectItemDatasInterfaceInfo(): RhDynamicInterfaceDto { const dto = RhDynamicInterfaceDto.create(); // 端口类型获取对应的端口号 const portNum = this.apiUrl.getPortNum(RhPortType.emp); dto.interfaceType = 'post'; dto.port = portNum; dto.controllerName = 'IqcMaterialInspectApi'; dto.interfaceName = 'GetIqcInspectSchemaEntryDatas'; return dto; } //#endregion navigateToInspectSchemaPage(data: RhBaseDto) { this.navigateSer.navigatorTrigger('RH_IqcInspectSchemaManagement', { InspectSchemaCode: data['InspectSchemaCode'] }); } }