import { Component, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { RhBaseDto, RhSafeAny, RhSelectItem, RhSelectableDto, RhTableButtonInfoDto, RhTableQueryOptionDto, DataResultT } from 'rh-base/model'; import { FileHelper, MsgHelper, RhApiUrlsService } from 'rh-base/core'; import { RhPortType, RhPortLocalFieldType } from 'rh-base/model'; import { DynamicFormComponent } from 'rh-base/shared'; import { ESopBindType, ESopBindTypeEnum, ESopProcessRoutingDto, ESopProcessRoutingEntryDto, ESopProcessRoutingEntryQueryDto, ESopProcessRoutingQueryDto, ESOP_PAGE_STATUS, ProductProcessRouteQueryDto } from './../../mdp-model'; import { RhEsopNewService } from '../esop-new.service'; import { NzTabComponent } from 'ng-zorro-antd/tabs'; import { NzTreeNode } from 'ng-zorro-antd/tree'; type Type = 'replace' | 'bind'; type UploadFunType = | 'UploadESopFileForMaterial' | 'UploadESopFileForBom' | 'UploadESopFileForProcessRoutingEntry' | 'UploadESopFileForProcessRouting'; type ReplaceFunType = | 'ReplaceMaterialDocument' | 'ReplaceESopBomDocument' | 'ReplaceESopProcessRoutingDocument' | 'ReplaceESopProcessRoutingEntryDocument'; type esopPageStaus = 'Maintain' | 'Browse'; @Component({ selector: 'rh-esop-routing', templateUrl: './esop-routing.component.html', styleUrls: ['./esop-routing.component.css'] }) export class EsopRoutingComponent implements OnInit { /**当前页面是浏览还是维护 */ esopPageStaus: esopPageStaus = 'Maintain'; @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; defaultQueryDto: ESopProcessRoutingQueryDto = ESopProcessRoutingQueryDto.create(); // 表格loading图标 dataLoading = false; selectedIndex = 0; // tab绑定页数 isShowRoutingOrPTab = 0; fileViewDate: Date = new Date(); dataResult!: DataResultT; // 表格当前选中的数据 selectedTableDatas: RhBaseDto[] = []; isShowUploadModal = false; // 文件绑定弹窗 isShowBindModal = false; // 文件替换弹窗 isShowReplaceModal = false; // 文件弹窗宽度 replaceModalWidth = '70vw'; // 日志 isShowLogsModal = false; /** 多选物料树列表*/ selectedDatas: NzTreeNode[] = []; /** 绑定的工艺路线集合 */ ProcessRouteItems: RhSelectItem[] = []; /** 选中的工艺路线 */ selectedProcessRoute: RhSelectItem | null = null; /** 是否显示绑定的工艺路线 */ isShowGrandsonNode = false; //选中的产品节点信息 SelectedNode!: NzTreeNode; //产品树内选中的产品 selectedProduct: RhSafeAny; Type: Type = 'bind'; /** 表格多选框选中数据 */ selectedProcessRoutingEntryDatas: RhSafeAny[] = []; // 表头按钮 titleButtonDataset: RhTableButtonInfoDto[] = []; // 表行内按钮 editButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto( // 'downloadSop', // '下载', // 'default', // 'download', // false, // null, // (data) => this.downloadBtnFun(data as RhBaseDto), // true, // false // ), new RhTableButtonInfoDto( 'readSop', '预览', 'default', false, 'eye', false, null, (data) => this.readFileBtnFun(data as RhBaseDto), true, false ) ]; // 工序 @ViewChild('queryProcessRoutingEntryForm', { static: false }) queryProcessRoutingEntryForm!: DynamicFormComponent; defaultProcessRoutingEntryQueryDto: RhSafeAny = {}; dataProcessRoutingEntryResult: RhSafeAny = {}; // 文件上传弹窗 isShowUploadProcessRoutingEntryModal = false; // 工序详情tab页 isShowProcessRoutingEntryDetails = false; // 工序tab页 isShowProcessRoutingEntryTab = false; selectedDetailsDatas: RhSafeAny[] = []; dataProcessRoutingEntryFilesResult: RhSafeAny = {}; // 当前选中数据 // selecProcessRoutingEntrytData: RhSafeAny = []; editButtonProcessRoutingEntryFilesDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'readSop', '预览', 'default', false, 'eye', false, null, (data) => this.deatilsReadFileProcessRoutingEntryButtonBtnFun(data as RhBaseDto), true, false ) ]; titleButtonProcessRoutingEntryFilesDataset: RhTableButtonInfoDto[] = []; // filesViewDate!: Date; fileList: RhSelectableDto[] = []; // 表行内按钮 editProcessRoutingEntryButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'readSop', '预览', 'default', false, 'eye', false, null, (data) => this.readFileProcessRoutingEntryButtonBtnFun(data as RhBaseDto), true, false ) ]; rhType: ESopBindType = 'ProcessRouting'; // eslint-disable-next-line @typescript-eslint/no-inferrable-types ReplaceFun: ReplaceFunType = 'ReplaceESopProcessRoutingDocument'; examineData: RhSafeAny = {}; // 审核弹窗 isShowExamineModal = false; examineType: ESopBindType = 'ProcessRouting'; // 物料当前选中 clickTreeNow: ESopBindType = 'Material'; //当前树选中 checkboxItems: RhBaseDto[] = []; constructor(private activatedRoute: ActivatedRoute, private apiUrls: RhApiUrlsService, private esopservice: RhEsopNewService) {} ngOnInit(): void { // 获取当前页面是维护还是浏览 this.activatedRoute.data.subscribe((res) => { this.esopPageStaus = res['EsopPs']; // 维护 if (res['EsopPs'] === ESOP_PAGE_STATUS.Maintain) { this.titleButtonDataset = [ // new RhTableButtonInfoDto( // 'batch-bind', // '上传', // 名字叫上传其实是绑定 bind // 'primary', // 'upload', // false, // null, // () => this.uploadOrReplaceTitleBtnFun(this.checkboxItems), // true // ), new RhTableButtonInfoDto( 'to-examine', '批量审核', 'default', false, 'audit', false, null, (data) => this.examineFileBtnFun(this.selectedProcessRoutingEntryDatas), false, false, 'green' ) ]; // 工艺路线 this.editButtonDataset = [ ...this.editButtonDataset, new RhTableButtonInfoDto( 'examineSop', '审核', 'default', false, 'audit', false, null, (data) => this.examineFileBtnFun(data as RhBaseDto), true, false, 'green', "data=>data.SopStatus !== 'Pass' " ), new RhTableButtonInfoDto( 'bindFileSop', '替换', 'default', false, 'swap', false, null, (data) => this.bindFileBtnFun(data as RhBaseDto), true, false, 'green' ), new RhTableButtonInfoDto( 'delSop', '删除', 'default', true, 'delete', false, null, (data) => this.removeBtnFun(data as RhBaseDto), true, false, 'red' ), new RhTableButtonInfoDto( 'logs', '查看操作日志', 'default', false, 'unordered-list', false, null, (data) => this.getLogs(data as RhBaseDto), true, false, '#00f' ) ]; // 工序 this.editProcessRoutingEntryButtonDataset = [ ...this.editProcessRoutingEntryButtonDataset, new RhTableButtonInfoDto( 'bindFileSop', '上传', 'default', false, 'upload', false, null, (data) => this.bindFileProcessRoutingEntryButtonBtnFun(data as RhBaseDto), true, false, 'green' ) ]; this.editButtonProcessRoutingEntryFilesDataset = [ ...this.editButtonProcessRoutingEntryFilesDataset, new RhTableButtonInfoDto( 'examineSop', '审核', 'default', false, 'audit', false, null, (data) => this.examineProcessRoutingEntryFileBtnFun(data as RhBaseDto), true, false, 'green', "data=>data.SopStatus !== 'Pass' " ), new RhTableButtonInfoDto( 'bindFileSop', '替换', 'default', false, 'swap', false, null, (data) => this.bindProcessRoutingEntryFileBtnFun(data as RhBaseDto), true, false, 'green' ), new RhTableButtonInfoDto( 'removeSop', '删除', 'default', true, 'delete', false, null, (data) => this.removeFileProcessRoutingEntryButtonBtnFun(data as RhBaseDto), true, false, 'red' ), new RhTableButtonInfoDto( 'logs', '查看操作日志', 'default', false, 'unordered-list', false, null, (data) => this.getProcessRoutingEntrLogs(ESopBindTypeEnum.ProcessRoutingEntry, data as RhBaseDto), true, false, '#00f' ) ]; this.titleButtonProcessRoutingEntryFilesDataset = [ new RhTableButtonInfoDto( 'to-examine', '批量审核', 'default', false, 'audit', false, null, (data) => this.examineProcessRoutingEntryFileBtnFun(this.selectedProcessRoutingEntryDatas), false, false, 'green' ) ]; // eslint-disable-next-line no-empty } else if (res['EsopPs'] === ESOP_PAGE_STATUS.Browse) { } }); // this.defaultProcessRoutingEntryQueryDto = { // ProcessRoutingCode: '' // }; } /** * * @param data */ uploadOrReplaceTitleBtnFun(data: RhSafeAny) { if (data.length > 0) { this.isShowBindModal = true; } else { MsgHelper.ShowInfoMessage('请先选择物料树型列表中的工艺路线!'); } } getDatas(option?: RhTableQueryOptionDto) { const queryProcessRoutingEntryDto: RhSafeAny = {}; if (this.SelectedNode && this.SelectedNode.level === 2) { queryProcessRoutingEntryDto.ProcessRoutingCode = this.selectedProcessRoute?.Value?.toString(); queryProcessRoutingEntryDto.MaterialCode = this.selectedProduct?.MaterialCode; // queryProcessRoutingEntryDto.ProcessName = this.selectedProcessRoute.Text.toString(); if (queryProcessRoutingEntryDto) { queryProcessRoutingEntryDto.ProcessRoutingCode = '$' + queryProcessRoutingEntryDto.ProcessRoutingCode; queryProcessRoutingEntryDto.MaterialCode = '$' + queryProcessRoutingEntryDto.MaterialCode; } this.defaultProcessRoutingEntryQueryDto = queryProcessRoutingEntryDto; } if (this.isShowRoutingOrPTab === 2) { this.getProcessRoutingEntryFiles(this.selectedDetailsDatas[0]); return; } if (this.queryProcessRoutingEntryForm && this.isShowRoutingOrPTab === 1) { setTimeout(() => { if (this.isShowRoutingOrPTab === 1) { this.queryProcessRoutingEntryForm.submitDefaultForm(null, option); } }); } if (this.queryFormCmt && this.isShowRoutingOrPTab === 0) { const queryDto: RhSafeAny = {}; queryDto.MaterialCode = this.selectedProduct?.MaterialCode; // queryDto.MaterialName = this.selectedProduct?.MaterialName; if (this.SelectedNode) { if (this.SelectedNode.level === 2) { queryDto.ProcessRoutingCode = this.selectedProcessRoute?.Value; } else if (this.SelectedNode.level === 3) { queryDto.ProcessRoutingCode = ''; } } if (queryDto?.ProcessRoutingCode) { queryDto.ProcessRoutingCode = '$' + queryDto.ProcessRoutingCode; } this.defaultQueryDto = queryDto; setTimeout(() => { this.queryFormCmt.submitDefaultForm(null, option); }); } } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } /** * 下载按钮 * @param data */ downloadBtnFun(data: RhBaseDto) { if (data && data['DocumentInfoCode']) { // console.log('download', data); try { this.selectedTableDatas = [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) { // eslint-disable-next-line no-console console.log(error); } } } /** * 替换弹窗中tab切换事件 */ tabChange(event: { index: number; tab: NzTabComponent }) { this.replaceModalWidth = event.index ? '30vw' : '70vw'; } /** * tab 切换事件 */ // eslint-disable-next-line @typescript-eslint/no-empty-function selectedRoutingOrPIndexChange() {} openProcessRoutingEntryTab() { if (this.clickTreeNow == 'Material') { MsgHelper.ShowInfoMessage('请右键工艺路线查看工序'); return; } // console.log(this.selectedProcessRoute); this.isShowProcessRoutingEntryTab = true; this.isShowRoutingOrPTab = 1; this.getDatas(); } // #region -----------------工艺路线----------------- /** * 获取操作日志 * @param data */ getLogs(data: RhSafeAny) { this.selectedTableDatas = [data]; this.rhType = ESopBindTypeEnum.ProcessRouting; this.isShowLogsModal = true; } /** * 删除按钮 * @param data */ removeBtnFun(data: RhSelectableDto) { this.selectedTableDatas = [data]; MsgHelper.ShowDeleteConfirm( `工艺路线名称:${data['ProcessRoutingName']}
文件名称:${data['DocumentInfoName']} 。
是否确认删除?`, () => { this.esopservice.RemoveESopProcessRoutingDocument([data] as ESopProcessRoutingDto[]).subscribe((result) => { // console.log(result); if (result.Success) { MsgHelper.ShowSuccessMessage('删除成功!'); this.getDatas(); } else { MsgHelper.ShowErrorMessage(`删除失败!${result.Message}`); } }); } ); } /** * 替换按钮方法 * @param data */ bindFileBtnFun(data?: RhBaseDto) { if (data) this.selectedTableDatas = [data]; // TODO this.rhType = ESopBindTypeEnum.ProcessRouting; this.ReplaceFun = 'ReplaceESopProcessRoutingDocument'; this.Type = 'replace'; this.isShowReplaceModal = true; } bindFileModalClose() { this.replaceModalWidth = '70vw'; this.isShowReplaceModal = false; this.getDatas(); } /** * 预览按钮 * @param data */ readFileBtnFun(data: RhBaseDto) { this.selectedTableDatas = [data]; this.fileViewDate = new Date(); // this.isShowReadFileModal = true; } SelectedProductCode(item: RhSafeAny) { console.log('SelectedProductCode'); this.selectedProduct = item; this.getDatas(); /** 获取绑定的工艺路线集合 */ // this.getBindingProcessRouteItems(); } getBindingProcessRouteItems() { this.isShowGrandsonNode = true; if (this.SelectedNode && this.SelectedNode.level === 1) { this.ProcessRouteItems = []; const queryDto = ProductProcessRouteQueryDto.create(); queryDto.ProductCode = this.selectedProduct?.MaterialCode; queryDto.ProductName = this.selectedProduct?.MaterialName; this.esopservice.GetProductBindingProcessRouteItems(queryDto).subscribe((result) => { if (result && result.Success) { this.ProcessRouteItems = result.Attach; } else { this.ProcessRouteItems = []; } }); } } getProcessRouteInfo(ProcessRoute: RhSelectItem) { console.log('getProcessRouteInfo'); this.selectedProcessRoute = ProcessRoute; this.getDatas(); } getSelectedNode(node: NzTreeNode) { this.SelectedNode = node; } // selectNodeChangeParams: RhSafeAny; getSelectNodeChange(node: NzTreeNode) { // if (!node || this.selectNodeChangeParams?.origin?.title == node.origin.title) return; // if (!node || this.selectNodeChangeParams == node) return; // console.log('getSelectNodeChange'); // this.selectNodeChangeParams = node; this.SelectedNode = node; if (node && node.origin['customData']) { const data = node.origin['customData']; if (node.level === 2 && node.isSelected) { this.clickTreeNow = 'ProcessRouting'; this.selectedProduct = node.parentNode?.origin?.['customData']; this.selectedProcessRoute = data; this.getDatas(); } if (node.level === 1 && node.isSelected) { this.selectedProduct = data; this.clickTreeNow = 'Material'; // this.getDatas(); /** 获取绑定的工艺路线集合 */ this.getBindingProcessRouteItems(); } } else { this.selectedProcessRoute = null; this.selectedProduct = null; } } /** * * @param $event */ getCheckBoxChange(data: NzTreeNode[]) { this.selectedDatas = data; const arr: RhBaseDto[] = []; this.getNzTreeNodeSelects(data, arr); this.checkboxItems = arr; // console.log(this.checkboxItems); } // 文件弹窗关闭 BindModalClose() { this.replaceModalWidth = '70vw'; this.isShowBindModal = false; this.getDatas(); } /** * 递归调用获取最下层数据 * @param event * @param arr */ getNzTreeNodeSelects(event: NzTreeNode[], arr: RhSafeAny[]) { event.forEach((e: NzTreeNode) => { if (e.children.length == 0 && e.level === 2) { const json = { ProcessRoutingCode: e?.origin?.['customData']?.Value, ProcessRoutingName: e?.origin?.['customData']?.Text, MaterialCode: e?.parentNode?.origin?.key, MaterialName: e?.parentNode?.origin?.title }; arr.push(json); } else { this.getNzTreeNodeSelects(e.children, arr); } }); } /** * bom form查询完成上弹事件绑定方法 * @param dataset */ resultDataChange(dataset: DataResultT) { this.dataResult = dataset; } /** * * @param status */ dataLoadingChange(status: boolean) { this.dataLoading = status; } // #endregion -----------------------工艺路线------------------------ // #region-------------------- 工序--------------------------- /** * 预览中删除文件 * @param data */ delFile(data: RhSafeAny) { if (data.type) { this.readFileProcessRoutingEntryButtonBtnFun(this.selectedTableDatas[0]); } } closeProcessRoutingEntryTab() { this.isShowProcessRoutingEntryTab = false; } resultDataProcessRoutingEntryChange(event: RhSafeAny) { this.dataProcessRoutingEntryResult = event; } /** * 预览 * @param data */ readFileProcessRoutingEntryButtonBtnFun(data: RhSafeAny) { this.selectedTableDatas = [data]; const params = ESopProcessRoutingEntryQueryDto.create(); params.ProcessRoutingCode = data.ProcessRoutingCode; params.ProcessCode = data.ProcessCode; params.MaterialCode = data.MaterialCode; // params.DocumentInfoCode = ''; // params.DocumentInfoName = ''; if (this.esopPageStaus === ESOP_PAGE_STATUS.Maintain) { this.esopservice.GetEsopProcessRoutingEntryDatas(params).subscribe((result) => { this.fileList = result.Attach; this.filesViewDate = new Date(); // if (result.Success) { // this.fileList = result.Attach; // this.filesViewDate = new Date(); // } else { // MsgHelper.ShowErrorMessage('获取失败,' + result.Message); // } }); } else if (this.esopPageStaus === ESOP_PAGE_STATUS.Browse) { this.esopservice.BrowseEsopProcessRoutingEntryDatas(params).subscribe((result) => { this.fileList = result.Attach; this.filesViewDate = new Date(); // if (result.Success) { // this.fileList = result.Attach; // this.filesViewDate = new Date(); // } else { // MsgHelper.ShowErrorMessage('获取失败,' + result.Message); // } }); } } /** * 上传 * @param data */ bindFileProcessRoutingEntryButtonBtnFun(data: RhSafeAny) { this.selectedTableDatas = [data]; this.isShowUploadProcessRoutingEntryModal = true; } uploadModalProcessRoutingEntryClose() { this.isShowUploadProcessRoutingEntryModal = false; this.getDatas(); } // 打开详情页 openProcessRoutingEntryDetailsBtnFun(data: RhSafeAny) { this.selectedDetailsDatas = [data.data]; this.isShowProcessRoutingEntryDetails = false; setTimeout(() => { this.isShowProcessRoutingEntryDetails = true; this.isShowRoutingOrPTab = 2; this.getProcessRoutingEntryFiles(data.data); }, 100); } /** * 获取文件 * @param data */ getProcessRoutingEntryFiles(data: RhBaseDto) { // console.log(data); const params = ESopProcessRoutingEntryQueryDto.create(); params.ProcessRoutingCode = data['ProcessRoutingCode']; params.ProcessCode = data['ProcessCode']; params.MaterialCode = data['MaterialCode']; if (this.esopPageStaus === ESOP_PAGE_STATUS.Maintain) { this.esopservice.GetEsopProcessRoutingEntryDatas(params).subscribe((result) => { if (result.Success) { this.dataProcessRoutingEntryFilesResult = result; } else { MsgHelper.ShowErrorMessage('获取失败,' + result.Message); this.dataProcessRoutingEntryFilesResult = []; } }); } else if (this.esopPageStaus === ESOP_PAGE_STATUS.Browse) { this.esopservice.BrowseEsopProcessRoutingEntryDatas(params).subscribe((result) => { if (result.Success) { this.dataProcessRoutingEntryFilesResult = result; } else { MsgHelper.ShowErrorMessage('获取失败,' + result.Message); this.dataProcessRoutingEntryFilesResult = []; } }); } } closeEntryTab() { this.isShowProcessRoutingEntryDetails = false; this.isShowRoutingOrPTab = 1; } /** * 详情文件预览 * @param data */ deatilsReadFileProcessRoutingEntryButtonBtnFun(data: RhBaseDto) { this.selectedTableDatas = [data]; this.fileViewDate = new Date(); } removeFileProcessRoutingEntryButtonBtnFun(data: RhSelectableDto) { this.selectedTableDatas = [data]; MsgHelper.ShowDeleteConfirm(`工序名称:${data['ProcessName']}
文件名称:${data['DocumentInfoName']} 。
是否确认删除?`, () => { this.esopservice.RemoveESopProcessRoutingEntryDocument([data] as ESopProcessRoutingEntryDto[]).subscribe((result) => { // console.log(result); if (result.Success) { MsgHelper.ShowSuccessMessage('删除成功!'); this.getDatas(); } else { MsgHelper.ShowErrorMessage(`删除失败!${result.Message}`); } }); }); } /** * 日志 * @param type * @param data */ getProcessRoutingEntrLogs(type: ESopBindType, data: RhBaseDto) { this.rhType = type; this.selectedTableDatas = [data]; this.isShowLogsModal = true; } /** * 替换 * @param data */ bindProcessRoutingEntryFileBtnFun(data: RhBaseDto) { if (data) this.selectedTableDatas = [data]; // TODO this.Type = 'replace'; this.ReplaceFun = 'ReplaceESopProcessRoutingEntryDocument'; this.rhType = ESopBindTypeEnum.ProcessRoutingEntry; this.isShowReplaceModal = true; } // #endregion-------------------- 工序--------------------------- /** * 工序文件审核 * @param data */ examineProcessRoutingEntryFileBtnFun(data: RhSafeAny) { this.examineData = Array.isArray(data) ? data : [data]; this.examineType = 'ProcessRoutingEntry'; this.isShowExamineModal = true; } /** * 工艺路线审核 * @param data */ examineFileBtnFun(data: RhSafeAny) { this.examineData = Array.isArray(data) ? data : [data]; this.examineType = 'ProcessRouting'; this.isShowExamineModal = true; } uploadModalexamineClose() { this.isShowExamineModal = false; this.getDatas(); } selectedProcessRoutingEntryDatasChange(event: RhSafeAny[]) { // console.log(event); this.selectedProcessRoutingEntryDatas = event; } selectedProcessRoutingDatasChange(event: RhSafeAny[]) { this.selectedProcessRoutingEntryDatas = event; } }