import { AttachFileInfoQueryDto, AttachFileInfoDto } from './../../qmp-model'; import { RhQualityManageSharedService } from './../quality-manage-shared.service'; import { RhQmpService } from './../../qmp.service'; import { RhDynamicInterfaceDto, RhSafeAny, RhTableButtonInfoDto } from 'rh-base/model'; import { Component, OnInit, Input, ViewChild } from '@angular/core'; import { InspectUploadCode, IQualityUploadTypeDto } from '../../qmp-model'; import { RhDynamicSingleTableComponent } from 'rh-base/shared'; import { MsgHelper } from 'rh-base/core'; @Component({ selector: 'rh-inspection-attach-files-preview', templateUrl: './inspection-attach-files-preview.component.html', styleUrls: ['./inspection-attach-files-preview.component.less'] }) export class RhInspectionAttachFilesPreviewComponent implements OnInit { @ViewChild(RhDynamicSingleTableComponent) tableComp!: RhDynamicSingleTableComponent; @Input() rhData!: IQualityUploadTypeDto; @Input() rhOrderType!: string; @Input() rhOrderCode!: InspectUploadCode; uploadFileDisplayInterface!: RhDynamicInterfaceDto; fileQueryDto!: AttachFileInfoQueryDto; fileDataset: AttachFileInfoDto[] = []; inlineButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'download', '下载', 'default', false, 'cloud-download', false, null, (datas, buttonInfo) => this.downloadFile(datas as AttachFileInfoDto, buttonInfo as RhTableButtonInfoDto), false, true ) ]; extraButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'delete', '删除', 'primary', true, 'delete', true, null, (datas, buttonInfo) => this.deleteFile(datas as AttachFileInfoDto[], buttonInfo as RhTableButtonInfoDto), false, true ) ]; defaultFieldDataset = [ { name: 'FileName', displayName: '文件名称', width: 160, visible: true }, { name: 'OrderType', displayName: '单据类型', width: 140, visible: true }, { name: 'OrderCode', displayName: '单据代码', width: 180, visible: true }, { name: 'DirectoryRelativePath', displayName: '相对路径', width: 180, visible: false } ]; constructor(public operator: RhQmpService, public sharedSer: RhQualityManageSharedService) { // } ngOnInit(): void { this.uploadFileDisplayInterface = this.initInterfaceInfo(); this.fileQueryDto = this.initFileQueryDto(this.rhOrderType, this.rhData); // this.getFileDatas(this.fileQueryDto); } downloadFile(item: AttachFileInfoDto, buttonInfo: RhTableButtonInfoDto) { if (event) { event.preventDefault(); event.stopImmediatePropagation(); } buttonInfo['load'] = true; // MsgHelper.ShowGlobalLoadingMessage('正在下载,请稍候...'); // this.operator.DownloadAttachFile(item.AttachFileInfoCode).subscribe((result) => { // if (result?.Success) { // setTimeout(() => { // this.downLoading = false; // MsgHelper.CloseGlobalLoadingMessage(); // }, 1000); // } else { // } // }); this.sharedSer.downAttachFileInfoDatas(item); setTimeout(() => { // MsgHelper.CloseGlobalLoadingMessage(); // MsgHelper.CloseGlobalLoadingMessage(); buttonInfo['load'] = false; }, 1000); } deleteFile(datas: AttachFileInfoDto[], buttonInfo: RhTableButtonInfoDto) { if (event) { event.preventDefault(); event.stopImmediatePropagation(); } buttonInfo.loading = true; this.operator.RemoveAttachFileInfoDatas(datas).subscribe((result) => { if (result?.Success) { MsgHelper.ShowSuccessMessage(`数据删除成功!`); this.getFileDatas(); } else { MsgHelper.ShowWarningModal(`数据删除失败!${result.Message}`); } buttonInfo.loading = false; }); } getFileDatas() { if (this.tableComp) { this.tableComp.refreshData(); } } private initFileQueryDto(orderType: string, data: RhSafeAny) { const temp = AttachFileInfoQueryDto.create(); temp.OrderType = `$${orderType}`; temp.OrderCode = `$${this.sharedSer.orderCodeHandler(this.rhOrderCode, data)}`; return temp; } private initInterfaceInfo() { const dto = RhDynamicInterfaceDto.create(); dto.interfaceType = 'post'; dto.port = 52880; dto.controllerName = 'AttachFileInfoWebApi'; dto.interfaceName = 'GetAttachFileInfoDatas'; return dto; } }