import { Component, OnInit, ViewChild } from '@angular/core'; import { DataResultT, RhBaseDto, RhSafeAny, RhTableButtonInfoDto, RhTableQueryOptionDto } from 'rh-base/model'; import { FileHelper, MsgHelper, RhApiUrlsService } from 'rh-base/core'; import { RhPortType, RhPortLocalFieldType } from 'rh-base/model'; import { DocumentInfoDto, DocumentInfoQueryDto } from './../../mdp-model'; import { RhEsopNewService } from '../esop-new.service'; import { DynamicFormComponent } from 'rh-base/shared'; type uploadType = 'upload' | 'replace'; @Component({ selector: 'rh-esop-file', templateUrl: './esop-file.component.html', styleUrls: ['./esop-file.component.css'] }) export class EsopFileComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; defaultQueryDto: DocumentInfoQueryDto = DocumentInfoQueryDto.create(); // 表格loading图标 dataLoading = false; // selectedIndex = 0; dataResult!: DataResultT; uploadType: uploadType = 'upload'; // 表格当前选中的数据 selectedDatas: RhBaseDto[] = []; isShowUploadModal = false; isShowbindModal = false; fileViewDate!: Date; // 表头按钮 titleButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto( // 'uploadSop', // '上传', // 'primary', // 'upload', // false, // null, // (data) => this.uploadOrReplaceBtnFun('upload', data as RhBaseDto), // true, // false, // 'blue' // ) ]; // 表行内按钮 editButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto( // 'replaceSop', // '替换', // 'default', // 'edit', // false, // null, // (data) => this.uploadOrReplaceBtnFun('replace', data as RhBaseDto), // true, // false, // 'green' // ), // new RhTableButtonInfoDto( // 'downloadFile', // '下载', // 'default', // 'download', // false, // null, // (data) => this.downloadFileBtnFun(data as RhBaseDto), // true, // false, // 'green' // ), new RhTableButtonInfoDto( 'readFile', '预览', 'default', false, 'eye', false, null, (data) => this.readFileBtnFun(data as RhBaseDto), true, false, 'green' ), // new RhTableButtonInfoDto( // 'BindItems', // '当前绑定', // 'default', // 'tags', // false, // null, // (data) => this.BindItemsBtnFun(data as RhBaseDto), // true, // false, // 'red' // ), new RhTableButtonInfoDto( 'removeFile', '删除', 'default', true, 'delete', false, null, (data) => this.removeFileBtnFun(data as RhBaseDto), true, false, 'red' ) ]; constructor(private apiUrls: RhApiUrlsService, private esopService: RhEsopNewService) {} ngOnInit(): void {} // 调用查询 getDatas(option?: RhTableQueryOptionDto) { // console.log(this.queryFormCmt); const queryDto: RhSafeAny = {}; this.isShowUploadModal = false; this.isShowbindModal = false; this.defaultQueryDto = queryDto; setTimeout(() => { this.queryFormCmt.submitDefaultForm(null, option); }); } /** * form查询完成上弹事件绑定方法 * @param dataset */ resultDataChange(dataset: DataResultT) { this.dataResult = dataset; } /** * * @param status */ dataLoadingChange(status: boolean) { this.dataLoading = status; } /** * 第一页tab被选中 */ tabSelect() { this.getDatas(); } /** * 打开文件弹窗 * @param uploadType * @param data */ uploadOrReplaceBtnFun(uploadType: uploadType, data?: RhBaseDto) { this.uploadType = uploadType; if (data) this.selectedDatas = [data]; if (this.selectedDatas && this.selectedDatas.length > 0) this.isShowUploadModal = true; } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } /** * 下载 * @param data */ downloadFileBtnFun(data: RhBaseDto) { if (data && data['DocumentInfoCode']) { // console.log('download', data); try { this.selectedDatas = [data]; const url = this.apiUrls.GetApiOperateUrl( RhPortType.mdp, 'ESopWebApi', `DownloadESopDoucumentFile?documentCode=${data['DocumentInfoCode']}`, RhPortLocalFieldType.mdp ); const fileName = data['DocumentInfoName']; FileHelper.downloadFileViaGet(url, fileName); setTimeout(() => { MsgHelper.CloseGlobalLoadingMessage(); }, 1000); } catch (error) { console.log(error); } } } /** * 预览 */ readFileBtnFun(data: RhBaseDto) { this.fileViewDate = new Date(); this.selectedDatas = [data]; } /** * 删除 * @param data */ removeFileBtnFun(data: RhBaseDto) { this.selectedDatas = [data]; MsgHelper.ShowDeleteConfirm(`文件名称:${data['DocumentInfoName']} 。
是否确认删除?`, () => { this.esopService.RemoveDocumentInfoDatas([data] as DocumentInfoDto[]).subscribe((result) => { // console.log(result); if (result.Success) { MsgHelper.ShowSuccessMessage('删除成功!'); this.getDatas(); } else { MsgHelper.ShowErrorMessage(`删除失败!${result.Message}`); } }); }); } BindItemsBtnFun(data: RhBaseDto) { this.isShowbindModal = false; setTimeout(() => { this.selectedDatas = [data['data']]; this.isShowbindModal = true; this.selectedIndex = 1; }, 100); } selectedDatasChange(event: RhBaseDto[]) { // console.log(event); this.selectedDatas = event; } uploadModelSuccess() { this.isShowUploadModal = false; this.getDatas(); } //关闭tab closeEntryTab() { this.selectedIndex = 0; this.isShowbindModal = false; } closeEsopFileUploadModal() {} }