import { RhNavigatorService, RhApiUrlsService, RhStorageService, MsgHelper, ObjectHelper, FileHelper } from 'rh-base/core'; import { RhPortType, RhPortLocalFieldType } from 'rh-base/model'; import { DataResultT, RhBaseDto, RhSafeAny, RhTableButtonInfoDto, CodeClassModel, RhDynamicTableFieldDto, OpMode, RhTableQueryOptionDto, OpResult, RhDynamicInterfaceDto, UploadFileOption } from 'rh-base/model'; import { DynamicFormComponent } from 'rh-base/shared'; import { Router } from '@angular/router'; import { EquipmentAttachFilesQueryDto, DataImportInput, EquipmentLedgerDto, EquipmentPrintDto, UpdateEquipmentAttachFilesDto, EquipmentAttachFilesDto, View_EquipmentBindedCheckItemsQueryDto, EquipmentMaintenanceRecordQueryDto, EquipmentFailureReportOrderQueryDto, EquipmentFailureRepairOrderQueryDto, EquipmentBindedMaintenanceSchemaQueryDto, EquipmentBindedInspectionSchemaQueryDto, EquipmentInspectionSchemaDto, SparePartsReceiptApplyOrderMasterQueryDto, EmployeeInfoQueryDto } from './../../emp-model'; import { Component, OnInit, ViewChild } from '@angular/core'; import { RhEquipmentDocumentService } from './../equipment-document.service'; import { firstValueFrom, Observer } from 'rxjs'; import { Observable } from 'rxjs'; import { View_EquipmentBindedMaintenanceItemsQueryDto, EquipmentInspectionRecordQueryDto } from './../../emp-model'; import { FormGroup, UntypedFormGroup } from '@angular/forms'; import { NzModalService } from 'ng-zorro-antd/modal'; import { NzUploadFile } from 'ng-zorro-antd/upload'; @Component({ selector: 'rh-equipment-ledger-manage', templateUrl: './equipment-ledger-manage.component.html', styleUrls: ['./equipment-ledger-manage.component.less'] }) export class RhEquipmentLedgerManageComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; @ViewChild('categoryQueryForm', { static: false }) categoryQueryForm!: DynamicFormComponent; selectedIndex = 0; isShowEdit = false; dataresult!: DataResultT; defaultFieldDataset: RhDynamicTableFieldDto[] = []; dataLoading = false; editDto: RhBaseDto = {}; editForm!: FormGroup; photoUrl!: string; // 查看附件 isShowPreviewModal = false; fileUrl!: string; fileName!: string; fileCatory!: string; MaterialDtos: RhSafeAny; fileDataset: RhSafeAny[] = []; // 上传文件界面 isShowUploadDrawer = false; isDirectoryUploadEnable = false; /** 上传的文件数据模型列表 */ uploadDatas: RhSafeAny; uploadFileList: NzUploadFile[] = []; uploading = false; printLoading = false; // 文档类别 DocumentType = ''; // 文件备注 Remark = ''; isShowFailureModal = false; failureDto: RhBaseDto = {}; //导入设备文档 isImportEquipment = false; // 导入的数据 importDatas: RhSafeAny[] = []; //数据导入页面 isOpenImportTab = false; isAddAfterDeleteAll = false; tableWidth = '0px'; // 导入数据返回的表头信息 dataHeadFields: { FieldName: string; FieldDescription: string }[] = []; // 查看详情 isShowDetail = false; tabNum!: number; /** 是否打开关联点巡检项tab */ isShowBindedEquipmentInspectionItems = false; //详情description currentEquipmentDetail: RhSafeAny; equipmentFiledataresult = { Attach: [] } as unknown as DataResultT; equipmentFileButton: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('refresh', '刷新', 'default', false, 'sync', false, null, () => this.getEquipmentFileDataSource(), true) ]; equipmentFileInterfaceInfo!: RhDynamicInterfaceDto; equipmentFileQueryDto!: EquipmentAttachFilesQueryDto; documentTypes: RhSafeAny[] = []; //点巡检项 selectedBindedCheckItemsDto: RhSafeAny; collapseQueryDto = {}; defaultQueryDto = {}; //是否为点检 isSpotCheck = false; //是否打开关联保养项目tab页 isShowBindedMaintainItems = false; //是否打开维护设备类别Tab isOpenEquipmentCategoryTab = false; // 是否查看图片 isShowImageModel = false; // 保养项目 selectedBindedMaintainDto: RhSafeAny; //是否为巡检项目 isTourInspectionItem = false; // 已关联点检项目 bindedSpotCheckItemsInterfaceInfo!: RhDynamicInterfaceDto; bindedSpotCheckItemsQueryDto!: View_EquipmentBindedCheckItemsQueryDto; // 已关联巡检项目 bindedTourInspectionItemsInterfaceInfo!: RhDynamicInterfaceDto; bindedTourInspectionItemsQueryDto!: View_EquipmentBindedCheckItemsQueryDto; // 已关联保养项目 bindedMaintenanceItemsInterfaceInfo!: RhDynamicInterfaceDto; bindedMaintenanceItemsQueryDto!: View_EquipmentBindedMaintenanceItemsQueryDto; //方案维护 schemaIndex = 0; // 是否为巡检方案tab(默认为否) isTourSchema = false; //点检方案 bindedSpotSchemaDataresult = { Attach: [] } as unknown as DataResultT; bindedSpotSchemaButton: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('refresh', '刷新', 'default', false, 'sync', false, null, () => this.getbindedSchem(), true) ]; // 设备关联的巡检方案 bindedTourSchemaDataresult = { Attach: [] } as unknown as DataResultT; bindedTourSchemaButton: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('refresh', '刷新', 'default', false, 'sync', false, null, () => this.getTourSchema(), true) ]; // 设备关联的保养方案 bindedMaintenanceSchemaInterfaceInfo!: RhDynamicInterfaceDto; bindedMaintenanceSchemaQueryDto!: EquipmentBindedMaintenanceSchemaQueryDto; //是否为巡检履历 isTourInspectionRecord = false; //点检履历 SpotRecordInterfaceInfo!: RhDynamicInterfaceDto; SpotRecordQueryDto!: EquipmentInspectionRecordQueryDto; //巡检履历 TourInspectionRecordInterfaceInfo!: RhDynamicInterfaceDto; TourInspectionRecordQueryDto!: EquipmentInspectionRecordQueryDto; //保养履历 MaintenanceRecordInterfaceInfo!: RhDynamicInterfaceDto; MaintenanceRecordQueryDto!: EquipmentMaintenanceRecordQueryDto; //报修履历 ReportRecordInterfaceInfo!: RhDynamicInterfaceDto; ReportRecordQueryDto!: EquipmentFailureReportOrderQueryDto; //维修履历 RepairRecordInterfaceInfo!: RhDynamicInterfaceDto; RepairRecordQueryDto!: EquipmentFailureRepairOrderQueryDto; //备品备件更新记录 SparePartsReplaceInterfaceInfo!: RhDynamicInterfaceDto; SparePartsReplaceQueryDto!: SparePartsReceiptApplyOrderMasterQueryDto; //设备负责人 principalInterfaceInfo!: RhDynamicInterfaceDto; principalFileQueryDto!: EmployeeInfoQueryDto; // (新建时的)图片上传 uploadImageData!: UploadFileOption; addData: RhSafeAny; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('edit', '编辑', 'default', false, 'edit', false, null, (data) => this.openEditTab(data as RhBaseDto), true), new RhTableButtonInfoDto( 'upload', '上传附件', 'primary', false, 'cloud-upload', false, null, (data) => this.openUploadFileDrawer(data as RhBaseDto), true ), // new RhTableButtonInfoDto('search', '附件信息', 'primary', 'eye', false, null, (data) => this.navigToEquipmentAttachFileManage(data as RhBaseDto), true), // new RhTableButtonInfoDto('detail', '查看详情', 'primary', 'eye', false, null, (data) => this.openDetailTab(data as RhBaseDto), true), // new RhTableButtonInfoDto('search', '下载附件', 'primary', 'download', false, null, (data) => this.downloadFile(data as RhBaseDto), true), new RhTableButtonInfoDto( 'link', '关联点检项', 'primary', false, 'link', false, null, (data) => this.openBindedEquipmentInspectionisSpotCheckItemsTab(data as RhBaseDto), true ), new RhTableButtonInfoDto( 'linkprol', '关联巡检项', 'primary', false, 'link', false, null, (data) => this.openBindedEquipmentInspectionItemsTab(data as RhBaseDto), true ), new RhTableButtonInfoDto( 'linkmantance', '关联保养项', 'primary', false, 'link', false, null, (data) => this.openBindedMaintainItemsTab(data as RhBaseDto), true ) ]; extraButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto( // 'failure', // '故障通知', // 'default', // 'alert', // false, // null, // (data) => this.openFailureModal(data as RhSafeAny[]), // false // ), new RhTableButtonInfoDto( 'print', '打印铭牌', 'primary', false, 'printer', false, null, (data) => this.printEquipmentDatas(data as RhSafeAny[]), false ), new RhTableButtonInfoDto('import', '导入Excel', 'default', false, 'import', false, null, () => this.importEquipmentData(), true) ]; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('new', '新建', 'primary', false, 'file', false, null, () => this.openEditTab(), true) // new RhTableButtonInfoDto( // 'importButton', // '导入Excel', // 'default', // 'import', // false, // null, // () => this.importEquipmentData(), // true // ) ]; // 查看附件 fileButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto('edit', '编辑', 'default', 'edit', false, null, (data) => this.openEditTab(data as RhBaseDto), true), new RhTableButtonInfoDto('scan', '附件查看', 'primary', false, 'eye', false, null, (data) => this.preview(data as RhBaseDto), true), new RhTableButtonInfoDto( 'download', '附件下载', 'primary', false, 'download', false, null, (data) => this.downloadFile(data as RhBaseDto), true ) ]; /*****************************维护设备类别******************************************************* */ categoryDataresult!: DataResultT; CategoryIndex = 0; CategoryEditDto: RhBaseDto = {}; titleCategoryButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('new', '新建', 'primary', false, 'file', false, null, () => this.openCategoryEditTab(), true) ]; editCategoryButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('edit', '编辑', 'default', false, 'edit', false, null, (data) => this.openCategoryEditTab(data as RhBaseDto)) ]; readLoading = false; constructor( private navigator: RhNavigatorService, private operator: RhEquipmentDocumentService, private apiUrls: RhApiUrlsService, private storage: RhStorageService, private modal: NzModalService, public router: Router ) { // } ngOnInit(): void { // 获取文档类型 this.getDocumentTypes(); } initDefaultQueryDto(dto: RhSafeAny) { this.collapseQueryDto = dto; this.defaultQueryDto = { ...this.defaultQueryDto, ...this.collapseQueryDto }; } getValueChange() { this.defaultQueryDto = { ...this.defaultQueryDto, ...this.collapseQueryDto }; setTimeout(() => { this.getDatas(); }); } // 跳转到设备附件 navigateToEquipmentAttachFile() { this.navigator.navigatorTrigger('RH_EquipmentAttachFileManage'); } // 打开设备类别Tab页 openEquipmentCategoryTab() { this.isOpenEquipmentCategoryTab = true; this.selectedIndex = 1; this.isShowDetail = false; this.isShowEdit = false; this.isOpenImportTab = false; this.isShowBindedEquipmentInspectionItems = false; this.isShowBindedMaintainItems = false; } closeEquipmentCategoryTab() { this.isOpenEquipmentCategoryTab = false; this.selectedIndex = 0; this.isShowDetail = false; this.isOpenImportTab = false; this.isShowBindedEquipmentInspectionItems = false; this.isShowBindedMaintainItems = false; } setDatas(dataset: DataResultT) { this.dataresult = dataset; } setInitFieldDataset(item: CodeClassModel) { const tempDatas: RhDynamicTableFieldDto[] = []; item.CodeProperties.forEach((ele) => { const temp = RhDynamicTableFieldDto.create(); temp.name = ele.PropertyName; temp.displayName = ele.Descirption; tempDatas.push(temp); }); this.defaultFieldDataset = [...tempDatas]; } dataLoadingChange(status: boolean) { this.dataLoading = status; } openEditTab(data?: RhBaseDto) { if (data) { this.editDto = data; this.editDto.OpSign = OpMode.OpEdit; this.photoUrl = this.getPhotoUrl(data) as string; } else { this.editDto = {}; this.editDto.OpSign = OpMode.OpAdd; } this.selectedIndex = 1; this.isShowEdit = true; this.isShowDetail = false; this.isOpenEquipmentCategoryTab = false; this.isShowBindedEquipmentInspectionItems = false; } getPhotoUrl(data: RhBaseDto) { return data['EquipmentPhoto'] ? `${this.apiUrls.GetApiOperateUrl( RhPortType.rdp, 'fileapi', // 'GetThumbImage', 'GetImage', RhPortLocalFieldType.rdp )}?parameterCode=EquipmentImageFileRootDirectory&fileName=${data['EquipmentPhoto']}` : null; } closeTab() { this.closeEditTab(); } closeEditTab() { this.selectedIndex = 0; this.isShowEdit = false; this.isShowBindedEquipmentInspectionItems = false; this.isShowBindedMaintainItems = false; this.photoUrl = ''; } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } private getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } resetPicture() { this.photoUrl = ''; } async onStoreDatas(result: DataResultT) { if (result && result.Success) { const msg = this.editDto.OpSign === OpMode.OpAdd ? '新增' : '编辑'; MsgHelper.ShowSuccessMessage(`${msg}数据成功`); if (this.editDto.OpSign === OpMode.OpEdit) { this.selectedIndex = 0; } //上传图片 this.addData = result.Attach; if (this.uploadImageData) { const queryDto: RhSafeAny = this.uploadImageData; queryDto.EquipmentCode = this.addData.EquipmentCode; queryDto.FileUploadDate = new Date(Date.now()); queryDto.DocumentType = 'ImageFile'; try { const result = await this.operator.UploadEquipmentImageFile(queryDto).toPromise(); if (result && result.Success) { this.editForm.get('EquipmentPhoto')?.setValue(null); // MsgHelper.ShowSuccessMessage('图片上传成功!'); } else { MsgHelper.ShowWarningModal(`图片上传失败!${result?.Message}`); } } catch (error) { MsgHelper.ShowWarningModal(`图片上传失败!`); } // .subscribe((result) => { // if (result && result.Success) { // // MsgHelper.ShowSuccessMessage('图片上传成功!'); // } else { // MsgHelper.ShowWarningModal(`图片上传失败!${result.Message}`); // } // }); } this.editDto = ObjectHelper.createRhBaseDto(); this.photoUrl = ''; this.getDatas(); } else { MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); } } /****************上传附件;查看/下载附件************************************ */ openUploadFileDrawer(data: RhSafeAny) { // 判断表中是否已有维护 this.MaterialDtos = data; this.fileDataset = []; // this.datasetChange.emit(this.dataset); this.isShowUploadDrawer = true; } closeUploadFileDrawer() { this.isShowUploadDrawer = false; this.uploadFileList = []; this.Remark = ''; this.DocumentType = ''; this.isImportEquipment = false; } // 查看附件 closePreviewModal() { this.isShowPreviewModal = false; } openPreviewModal() { this.isShowPreviewModal = true; } /** 文档预览 */ preview(item: RhSafeAny) { // const querDto = DocumentAbsoluteAddressQueryDto.create(); // querDto.DocumentInfoCode = item.EquipmentAttachCode; // const extension = /\.(png|jpg|jpeg|bmp|gif)/; // // 非图片传false,否则传入true // if (!extension.test(item.FileName.toLowerCase())) { // querDto.IsOriginalFile = false; // } else { // querDto.IsOriginalFile = true; // } // const url = this.apiUrls.GetApiOperateUrl( // RhPortType.emp, // 'EquipmentLedgerApi', // 'DownloadEquipmentAttachFile', // RhPortLocalFieldType.emp // ); // FileHelper.PostFileBlob(url, querDto).subscribe((result) => { // this.fileUrl = FileHelper.CreateDownloadFileUrl(result); // this.fileName = item.FileName; // // this.fileCatory='.'+item.PdfRelativePath; // // const toPdfReg = /\.(png|jpg|jpeg|bmp|gif|webp|psd|svg|tiff|pdf)/; // // if (toPdfReg.test(this.fileCatory.toLowerCase())) { // /** 打开文档预览Modal */ // this.openPreviewModal(); // // } else { // // const anchor = document.createElement('a'); // // const FileName=item.FileName; // // // anchor.download = FileName.substring(0,FileName.indexOf('.')+1)+'pdf'; // // anchor.download = FileName; // // anchor.href = this.fileUrl; // // anchor.click(); // // } // }); /** 打开文档预览Modal */ this.openPreviewModal(); //更换接口(Get接口),需上传新的文档才可用(因为后端路径有更改) const url = this.apiUrls.GetApiOperateUrl( RhPortType.emp, 'EquipmentLedgerApi', `PreviewEquipmentAttachFile?equipmentAttachCode=${item.EquipmentAttachCode}`, RhPortLocalFieldType.emp ); this.readLoading = true; FileHelper.GetFileBlob(url).subscribe( (result) => { this.fileUrl = FileHelper.CreateDownloadFileUrl(result); this.fileName = item.FileName; // this.fileCatory='.'+item.PdfRelativePath; // const toPdfReg = /\.(png|jpg|jpeg|bmp|gif|webp|psd|svg|tiff|pdf)/; // if (toPdfReg.test(this.fileCatory.toLowerCase())) { this.readLoading = false; // } else { // const anchor = document.createElement('a'); // const FileName=item.FileName; // // anchor.download = FileName.substring(0,FileName.indexOf('.')+1)+'pdf'; // anchor.download = FileName; // anchor.href = this.fileUrl; // anchor.click(); // } }, () => (this.readLoading = false) ); } /** 下载附件 */ downloadFile(item: RhSafeAny) { // const querDto = DocumentAbsoluteAddressQueryDto.create(); // querDto.DocumentInfoCode = item.EquipmentAttachCode; // querDto.IsOriginalFile = true; //更换接口(Get接口),需上传新的文档可用(因为后端路径有更改) const url = this.apiUrls.GetApiOperateUrl( RhPortType.emp, 'EquipmentLedgerApi', `DownloadEquipmentAttachFile?equipmentAttachCode=${item.EquipmentAttachCode}`, RhPortLocalFieldType.emp ); MsgHelper.ShowGlobalLoadingMessage('正在下载文件,请稍候。。。'); FileHelper.GetFileBlob(url).subscribe((result) => { this.fileUrl = FileHelper.CreateDownloadFileUrl(result); this.fileName = item.FileName; const anchor = document.createElement('a'); const FileName = item.FileName; anchor.download = FileName; // anchor.download = FileName.substring(0,FileName.indexOf('.')+1)+'pdf'; anchor.href = this.fileUrl; anchor.click(); setTimeout(() => { MsgHelper.CloseGlobalLoadingMessage(); }, 1000); }); } beforeUpload = (file: NzUploadFile) => { if (!this.isImportEquipment) { return new Observable((observer: Observer) => { const reader = new FileReader(); reader.readAsDataURL(file as RhSafeAny); reader.onload = () => { const queryDto = UpdateEquipmentAttachFilesDto.create(); queryDto.EquipmentCode = this.MaterialDtos.EquipmentCode; queryDto.FileStream = reader.result as RhSafeAny; queryDto.FileName = file.name; const nameList = queryDto.FileName.split('.'); queryDto.FileExtensionName = nameList[nameList.length - 1]; this.uploadDatas = queryDto; this.uploadFileList = this.uploadFileList.concat(file); observer.next(false); observer.complete(); }; reader.onerror = (e) => { MsgHelper.ShowWarningModal(`读取文件失败!${e}`); observer.next(false); observer.complete(); }; }); } else { if (this.uploadFileList.length >= 1) { MsgHelper.ShowWarningMessage('每次只能上传一个文件!'); return false; } return new Observable((observer: Observer) => { const reader = new FileReader(); reader.readAsDataURL(file as RhSafeAny); reader.onload = () => { const importQueryDto = DataImportInput.create(); importQueryDto.FileStreamString = reader.result as RhSafeAny; this.uploadDatas = importQueryDto; // 只有一个文件 this.uploadFileList = this.uploadFileList.concat(file); // this.uploadFileList = [file]; observer.next(false); observer.complete(); }; reader.onerror = (e) => { MsgHelper.ShowWarningModal(`读取文件失败!${e}`); observer.next(false); observer.complete(); }; }); } }; handleUpload() { if (!this.uploadDatas) { MsgHelper.ShowWarningModal('没有需要上传的文件!'); return; } const extensionName = /\.(png|jpg|jpeg|bmp|gif|webp|psd|svg|tiff|pdf|doc|docx|ppt|pptx|xls|xlsx)/; if (!extensionName.test('.' + this.uploadDatas.FileExtensionName.toLowerCase())) { MsgHelper.ShowWarningModal('请上传office文件或pdf格式的文件!'); return; } this.uploading = true; this.uploadDatas.FileUploadDate = new Date(Date.now()); this.uploadDatas.DocumentType = this.DocumentType; this.uploadDatas.Remark = this.Remark; // const userSession = this.storage.getUserSession(); // this.uploadDatas.FactoryCode = userSession.User.FactoryCode; this.operator.UploadEquipmentAttachFile(this.uploadDatas).subscribe( (result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage('文件上传成功!'); this.getDatas(); this.closeUploadFileDrawer(); this.isImportEquipment = false; this.openDetailTabAfterUpload(this.MaterialDtos); } else { MsgHelper.ShowWarningModal(`文件上传失败!${result.Message}`); } this.uploading = false; }, () => (this.uploading = false) ); } // 标签打印 printEquipmentDatas(selectDatas: RhSafeAny[]) { const printDto = EquipmentPrintDto.create(); // 生成数据 selectDatas.map((ele) => { const printList = EquipmentLedgerDto.create(); ObjectHelper.MapT(ele, printList); printDto.PrintList.push(printList); }); this.printLoading = true; this.operator.TemplatePrint(printDto).subscribe( (result) => { if (result.Success) { const userIp = result.Attach.toString(); location.href = FileHelper.getPrintLabelClientUrlLatest(userIp); MsgHelper.ShowWarningMessage(`正在打印铭牌,请耐心等待`); } else { MsgHelper.ShowWarningModal(`铭牌打印失败!${result.Message}`); } this.printLoading = false; }, () => (this.printLoading = false) ); } openFailureModal(selectDatas: RhSafeAny[]) { this.isShowFailureModal = true; this.failureDto = selectDatas[0]; this.initFailureDto(); } closeFailureModal() { this.isShowFailureModal = false; this.failureDto = []; } private initFailureDto() { this.failureDto['Recorder'] = this.storage.getUserSession()?.User?.UserName; this.failureDto['RecorderName'] = this.storage.getUserSession()?.User?.DisplayName; } onStoreFailureDatas(result: DataResultT) { if (result && result.Success) { MsgHelper.ShowSuccessMessage('故障通知成功!'); this.closeFailureModal(); } else { MsgHelper.ShowWarningMessage(`故障通知失败失败!${result.Message}`); } } // 跳转到设备台账 navigToEquipmentAttachFileManage(data: RhSafeAny) { this.navigator.navigatorTrigger('RH_EquipmentAttachFileManage', { EquipmentCode: data.EquipmentCode }); } /********************导入数据************************** */ openImportTab() { this.isOpenImportTab = true; this.isAddAfterDeleteAll = false; this.selectedIndex = 1; } closeImportTab() { this.isOpenImportTab = false; this.selectedIndex = 0; } //导入设备台账 importEquipmentData() { this.isShowUploadDrawer = true; this.isImportEquipment = true; } // 导入 handleImport() { this.uploading = true; // this.uploadDatas.BusinessCode = 'EquipmentLedger'; this.uploadDatas.BusinessCode = 'EquipmentLedgerImport'; this.operator.DataImport(this.uploadDatas).subscribe( (result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage('文件导入成功!'); this.importDatas = result.Attach; this.dataHeadFields = result.DataHeadFields as RhSafeAny; this.tableWidth = this.dataHeadFields.length * 120 + 100 + 'px'; this.closeUploadFileDrawer(); this.getDatas(); this.openImportTab(); } else { MsgHelper.ShowWarningModal(`文件导入失败!${result.Message}`); } this.uploading = false; }, () => (this.uploading = false) ); } /** 清空数据 */ clearImportedPlanDatas() { MsgHelper.ShowConfirmModal('是否继续', '是否清空所有导入的模板数据?', () => { this.importDatas = []; MsgHelper.ShowSuccessMessage('数据清空成功!'); }); } changeIsAddAfterDeleteAll(value: boolean) { if (value) { this.modal.confirm({ nzTitle: '警告!', nzContent: '若勾选此项,将会进行不可逆的删除,是否确认?', nzOnCancel: () => { this.isAddAfterDeleteAll = false; }, nzOkType: 'primary', nzOkDanger: true, nzIconType: 'warning' }); } } removeImportTempData(index: number) { MsgHelper.ShowConfirmModal('是否继续', '是否移除选中的模板数据?', () => { this.importDatas.splice(index, 1); this.importDatas = [...this.importDatas]; }); } getDataType(data: string) { if (data) { const tmp = data.toString().trim().toLowerCase(); const dateReg = new RegExp(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?/, 'i'); if (['true', 'false'].includes(tmp)) { return 'boolean'; } else if (dateReg.test(data)) { return 'date'; } } return 'string'; } // 保存数据 async storeImportedDatas() { if (this.importDatas.some((f) => !f.Success)) { MsgHelper.ShowWarningMessage('请修改错误或重新导入后保存!'); return; } // const businessType = this.selectTpl.BusinessTypeCode; let result: OpResult | null = null; if (this.isAddAfterDeleteAll) { this.importDatas.forEach((f) => (f.OpSign = OpMode.OpAddAfterDeleteAll)); } else { this.importDatas.forEach((f) => (f.OpSign = OpMode.OpAdd)); } try { result = await firstValueFrom(this.operator.StoreEquipmentLedgerDatas(this.importDatas)); } catch (error) { MsgHelper.ShowErrorMessage(`保存错误!${error}`); } if (result) { if (result.Success) { MsgHelper.ShowSuccessMessage('保存成功!'); this.importDatas = []; this.closeImportTab(); } else { MsgHelper.ShowWarningMessage(`保存失败!${result.Message}`); } } } openDetailTabAfterUpload(dto: RhSafeAny) { this.isShowDetail = true; this.isShowBindedEquipmentInspectionItems = false; this.selectedIndex = 1; this.currentEquipmentDetail = dto; // 设备关联的点巡检方案 this.getbindedSchem(); } openDetailTab(dto: RhSafeAny) { this.isShowDetail = true; this.isShowBindedEquipmentInspectionItems = false; this.selectedIndex = 1; this.currentEquipmentDetail = dto.data; // 设备关联的点巡检方案 this.getbindedSchem(); } openBindedEquipmentInspectionisSpotCheckItemsTab(data: RhSafeAny) { this.isShowBindedEquipmentInspectionItems = true; this.isShowDetail = false; this.selectedIndex = 1; this.selectedBindedCheckItemsDto = data; this.isSpotCheck = true; } openBindedEquipmentInspectionItemsTab(data: RhSafeAny) { this.isShowBindedEquipmentInspectionItems = true; this.isShowDetail = false; this.selectedIndex = 1; this.selectedBindedCheckItemsDto = data; this.isSpotCheck = false; } closeDetailTab() { this.isShowDetail = false; this.selectedIndex = 0; } getEquipmentFileDataSource() { this.tabNum = 13; const queryDto = EquipmentAttachFilesQueryDto.create(); queryDto.EquipmentCode = '$' + this.currentEquipmentDetail.EquipmentCode; this.equipmentFileQueryDto = queryDto; this.equipmentFileInterfaceInfo = this.getEquipmentAttachFileDatas(); // this.dataLoading = true; // const queryDto = EquipmentAttachFilesQueryDto.create(); // queryDto.EquipmentCode = '$' + this.currentEquipmentDetail.EquipmentCode; // this.operator.GetEquipmentAttachFileDatas(queryDto).subscribe( // (result) => { // if (result && result.Success) { // this.equipmentFiledataresult = result; // } else { // this.equipmentFiledataresult.Attach = []; // MsgHelper.ShowWarningMessage('暂未上传附件'); // } // this.dataLoading = false; // this.equipmentFiledataresult = { ...this.equipmentFiledataresult }; // }, // () => (this.dataLoading = false) // ); } getEquipmentAttachFileDatas() { const dto = RhDynamicInterfaceDto.create(); // 端口类型获取对应的端口号 const portNum = this.apiUrls.getPortNum(RhPortType.emp); dto.interfaceType = 'post'; dto.port = portNum; dto.controllerName = 'EquipmentLedgerApi'; dto.interfaceName = 'GetEquipmentAttachFileDatas'; return dto; } // 获取文档类型 getDocumentTypes() { this.apiUrls .getSettingEntry({ moduleKey: 'EquipmentManagement', groupKey: 'EquipmentLedger', paraCode: 'EquipmentFileType' }) .subscribe((result) => { if (result.Success) { this.documentTypes = result.Attach; } }); } // onMovePdfFileView(){ // const pdfFileView=document.getElementById('pdfFileView'); // //设置点击(鼠标移动时),达到动态效果 // document.onmousemove=function (e) { // //设置图片的位置等于鼠标的位置(可以适当加减距离) // pdfFileView.style.right=e.pageX-10 + 'px'; // // pdfFileView.style.top=e.pageY-10 + 'px'; // } // } /***************************关联保养项目******************************** */ openBindedMaintainItemsTab(data: RhSafeAny) { this.isShowBindedMaintainItems = true; this.selectedBindedMaintainDto = data; this.isShowDetail = false; this.selectedIndex = 1; } /** 点击查看图片 */ toShowImage() { this.isShowImageModel = true; } closeImageModal() { this.isShowImageModel = false; } // 设备关联的点检项目 getBindedEquipmentSpotCheckCheckItems() { this.toTheFirstTab(); this.tabNum = 4; const queryDto = View_EquipmentBindedCheckItemsQueryDto.create(); queryDto.EquipmentCode = '$' + this.currentEquipmentDetail.EquipmentCode; queryDto.EquipmentName = this.currentEquipmentDetail.EquipmentName; queryDto.CheckType = 'SpotCheck'; this.bindedSpotCheckItemsQueryDto = queryDto; this.bindedSpotCheckItemsInterfaceInfo = this.getEquipmentBindedCheckItemsDatas(); } getEquipmentBindedCheckItemsDatas() { const dto = RhDynamicInterfaceDto.create(); // 端口类型获取对应的端口号 const portNum = this.apiUrls.getPortNum(RhPortType.emp); dto.interfaceType = 'post'; dto.port = portNum; dto.controllerName = 'EquipmentBindedCheckItemsApi'; dto.interfaceName = 'GetEquipmentBindedCheckItemsDatas'; return dto; } getItemType() { // 是否为巡检项目 // this.isTourInspectionItem = true; this.tabNum = 5; const queryDto = View_EquipmentBindedCheckItemsQueryDto.create(); queryDto.EquipmentCode = '$' + this.currentEquipmentDetail.EquipmentCode; queryDto.EquipmentName = this.currentEquipmentDetail.EquipmentName; queryDto.CheckType = 'TourInspection'; this.bindedTourInspectionItemsQueryDto = queryDto; this.bindedTourInspectionItemsInterfaceInfo = this.getEquipmentBindedCheckItemsDatas(); } // 设备关联的保养项目 getBindedEquipmentMaintenanceItems() { this.tabNum = 6; const queryDto = View_EquipmentBindedMaintenanceItemsQueryDto.create(); queryDto.EquipmentCode = '$' + this.currentEquipmentDetail.EquipmentCode; queryDto.EquipmentName = this.currentEquipmentDetail.EquipmentName; this.bindedMaintenanceItemsQueryDto = queryDto; this.bindedMaintenanceItemsInterfaceInfo = this.getEquipmentBindedMaintenanceItemsDatas(); } getEquipmentBindedMaintenanceItemsDatas() { const dto = RhDynamicInterfaceDto.create(); // 端口类型获取对应的端口号 const portNum = this.apiUrls.getPortNum(RhPortType.emp); dto.interfaceType = 'post'; dto.port = portNum; dto.controllerName = 'EquipmentBindedMaintenanceItemsApi'; dto.interfaceName = 'GetEquipmentBindedMaintenanceItemsDatas'; return dto; } //点检履历 getEquipmentInspectionRecord() { this.toTheFirstTab(); this.tabNum = 7; const queryDto = EquipmentInspectionRecordQueryDto.create(); queryDto.EquipmentCode = '$' + this.currentEquipmentDetail.EquipmentCode; queryDto.EquipmentName = this.currentEquipmentDetail.EquipmentName; queryDto.CheckType = 'SpotCheck'; this.SpotRecordQueryDto = queryDto; this.SpotRecordInterfaceInfo = this.getEquipmentInspectionRecordDatas(); } getEquipmentInspectionRecordDatas() { const dto = RhDynamicInterfaceDto.create(); // 端口类型获取对应的端口号 const portNum = this.apiUrls.getPortNum(RhPortType.emp); dto.interfaceType = 'post'; dto.port = portNum; dto.controllerName = 'EquipmentInspectionApi'; dto.interfaceName = 'GetEquipmentInspectionRecordDatas'; return dto; } //巡检 getOtherRecordType() { this.tabNum = 8; const queryDto = EquipmentInspectionRecordQueryDto.create(); queryDto.EquipmentCode = '$' + this.currentEquipmentDetail.EquipmentCode; queryDto.EquipmentName = this.currentEquipmentDetail.EquipmentName; queryDto.CheckType = 'TourInspection'; this.TourInspectionRecordQueryDto = queryDto; this.TourInspectionRecordInterfaceInfo = this.getEquipmentInspectionRecordDatas(); } //保养履历 getMaintenanceRecord() { this.tabNum = 9; const queryDto = EquipmentMaintenanceRecordQueryDto.create(); queryDto.EquipmentCode = '$' + this.currentEquipmentDetail.EquipmentCode; queryDto.EquipmentName = this.currentEquipmentDetail.EquipmentName; this.MaintenanceRecordQueryDto = queryDto; this.MaintenanceRecordInterfaceInfo = this.getEquipmentMaintenanceRecordDatas(); } getEquipmentMaintenanceRecordDatas() { const dto = RhDynamicInterfaceDto.create(); // 端口类型获取对应的端口号 const portNum = this.apiUrls.getPortNum(RhPortType.emp); dto.interfaceType = 'post'; dto.port = portNum; dto.controllerName = 'EquipmentMaintenanceApi'; dto.interfaceName = 'GetEquipmentMaintenanceRecordDatas'; return dto; } //报修履历 getReportRecord() { this.tabNum = 10; const querDto = EquipmentFailureReportOrderQueryDto.create(); querDto.EquipmentCode = this.currentEquipmentDetail.EquipmentCode; this.ReportRecordQueryDto = querDto; this.ReportRecordInterfaceInfo = this.getEquipmentFailureReportOrderDatas(); } getEquipmentFailureReportOrderDatas() { const dto = RhDynamicInterfaceDto.create(); // 端口类型获取对应的端口号 const portNum = this.apiUrls.getPortNum(RhPortType.emp); dto.interfaceType = 'post'; dto.port = portNum; dto.controllerName = 'EquipmentFailureRepairApi'; dto.interfaceName = 'GetEquipmentFailureReportOrderDatas'; return dto; } //维修履历 getRepairRecord() { this.tabNum = 11; const queryDto = EquipmentFailureRepairOrderQueryDto.create(); queryDto.EquipmentCode = '$' + this.currentEquipmentDetail.EquipmentCode; queryDto.EquipmentName = this.currentEquipmentDetail.EquipmentName; this.RepairRecordQueryDto = queryDto; this.RepairRecordInterfaceInfo = this.getEquipmentFailureRepairOrderDatas(); } getEquipmentFailureRepairOrderDatas() { const dto = RhDynamicInterfaceDto.create(); // 端口类型获取对应的端口号 const portNum = this.apiUrls.getPortNum(RhPortType.emp); dto.interfaceType = 'post'; dto.port = portNum; dto.controllerName = 'EquipmentFailureRepairApi'; dto.interfaceName = 'GetEquipmentFailureRepairOrderDatas'; return dto; } //获取设备关联的点巡检方案 getbindedSpotSchem() { // const queryDto = EquipmentBindedInspectionSchemaQueryDto.create(); // queryDto.EquipmentCode = this.detailData.SparePartsCode; // queryDto.OrderCategory = this.detailData.SparePartsName; // this.changeRecordDatasQueryDto = queryDto; // this.changeRecordDatasInterfaceInfo = this.getchangeRecordDatasInterfaceInfo(); this.dataLoading = true; const queryDto = EquipmentBindedInspectionSchemaQueryDto.create(); queryDto.EquipmentCode = '$' + this.currentEquipmentDetail.EquipmentCode; if (this.isTourSchema) { this.tabNum = 2; } else { this.tabNum = 1; } this.operator.GetInspectionSchemaByEquipmentCode(queryDto).subscribe( (result) => { if (this.isTourSchema) { this.bindedTourSchemaDataresult.Attach = []; if (result && result.Success) { result.Attach.forEach((ele) => { if (ele.OrderCategory === 'TourInspection') { this.bindedTourSchemaDataresult.Attach.push(ele); } }); this.bindedTourSchemaDataresult = { ...this.bindedTourSchemaDataresult }; } } else { if (result && result.Success) { this.bindedSpotSchemaDataresult.Attach = []; result.Attach.forEach((ele) => { if (ele.OrderCategory === 'SpotCheck') { this.bindedSpotSchemaDataresult.Attach.push(ele); } }); this.bindedSpotSchemaDataresult = { ...this.bindedSpotSchemaDataresult }; } } this.dataLoading = false; }, () => (this.dataLoading = false) ); } toTheFirstTab() { this.schemaIndex = 0; } getbindedSchem() { this.tabNum = 1; this.isTourSchema = false; this.toTheFirstTab(); this.getbindedSpotSchem(); } //获取设备关联的巡检方案 getTourSchema() { this.isTourSchema = true; this.tabNum = 2; this.getbindedSpotSchem(); } //设备关联的保养方案 getMaintenanceSchema() { this.tabNum = 3; const queryDto = EquipmentBindedMaintenanceSchemaQueryDto.create(); queryDto.EquipmentCode = '$' + this.currentEquipmentDetail.EquipmentCode; this.bindedMaintenanceSchemaQueryDto = queryDto; this.bindedMaintenanceSchemaInterfaceInfo = this.getbindedMaintenanceSchemaInterfaceInfo(); } // 获取明细表体数据查询接口的接口信息 getbindedMaintenanceSchemaInterfaceInfo(): RhDynamicInterfaceDto { const dto = RhDynamicInterfaceDto.create(); // 端口类型获取对应的端口号 const portNum = this.apiUrls.getPortNum(RhPortType.emp); dto.interfaceType = 'post'; dto.port = portNum; dto.controllerName = 'EquipmentMaintenanceApi'; dto.interfaceName = 'GetMaintenanceSchemaByEquipmentCode'; return dto; } /******************************维护设备类别******************************************************** */ openCategoryEditTab(data?: RhBaseDto) { if (data) { this.CategoryEditDto = data; this.CategoryEditDto.OpSign = OpMode.OpEdit; } else { this.CategoryEditDto = {}; this.CategoryEditDto.OpSign = OpMode.OpAdd; } this.CategoryIndex = 1; } closeCategoryEditTab() { this.CategoryIndex = 0; } setCategoryDatas(dataset: DataResultT) { this.categoryDataresult = dataset; } refreshCategoryData(option: RhTableQueryOptionDto) { this.getCategoryDatas(option); } getCategoryDatas(option?: RhTableQueryOptionDto) { if (this.categoryQueryForm) { this.categoryQueryForm.submitDefaultForm(null, option); } } onStoreCategoryData(result: DataResultT) { if (result && result.Success) { const msg = this.CategoryEditDto.OpSign === OpMode.OpAdd ? '新增' : '编辑'; MsgHelper.ShowSuccessMessage(`数据${msg}成功`); if (this.CategoryEditDto.OpSign === OpMode.OpEdit) { this.CategoryIndex = 0; } this.CategoryEditDto = ObjectHelper.createRhBaseDto(); this.getCategoryDatas(); } else { MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); } } //备品备件更新记录 getSparePartsReplace() { this.tabNum = 12; const queryDto = SparePartsReceiptApplyOrderMasterQueryDto.create(); queryDto.EquipmentCode = '$' + this.currentEquipmentDetail.EquipmentCode; queryDto.EquipmentName = this.currentEquipmentDetail.EquipmentName; this.SparePartsReplaceQueryDto = queryDto; this.SparePartsReplaceInterfaceInfo = this.getSparePartsReceiptApplyOrderDetailByEquipmentCode(); } getSparePartsReceiptApplyOrderDetailByEquipmentCode() { const dto = RhDynamicInterfaceDto.create(); // 端口类型获取对应的端口号 const portNum = this.apiUrls.getPortNum(RhPortType.emp); dto.interfaceType = 'post'; dto.port = portNum; dto.controllerName = 'SparePartsApplyOrderApi'; dto.interfaceName = 'GetSparePartsReceiptApplyOrderDetailByEquipmentCode'; return dto; } //设备负责人 getPrincipal() { this.tabNum = 14; const queryDto = EmployeeInfoQueryDto.create(); queryDto.EmployeeCode = '$' + this.currentEquipmentDetail.ResponsiblePerson; this.principalFileQueryDto = queryDto; this.principalInterfaceInfo = this.getEmployeeInfoDatas(); } getEmployeeInfoDatas() { const dto = RhDynamicInterfaceDto.create(); // 端口类型获取对应的端口号 const portNum = this.apiUrls.getPortNum(RhPortType.mdp); dto.interfaceType = 'post'; dto.port = portNum; dto.controllerName = 'EmployeeWebApi'; dto.interfaceName = 'GetEmployeeInfoDatas'; return dto; } uploadImages(formGroup: UntypedFormGroup, data: UploadFileOption) { this.uploadImageData = data; this.editForm = formGroup; if (formGroup && !data) { formGroup.get('EquipmentPhoto')?.setValue(null); } } // test(item, tableData) { // console.log(item, tableData); // } }