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 { ESopBindType, ESopBomDto, ESopBomQueryDto, ESopMaterialDto, ESOP_PAGE_STATUS, ESopBindTypeEnum } from './../../mdp-model'; import { RhEsopNewService } from '../esop-new.service'; type Type = 'replace' | 'bind'; import { DynamicFormComponent } from 'rh-base/shared'; import { NzTreeNode } from 'ng-zorro-antd/tree'; import { NzTabComponent } from 'ng-zorro-antd/tabs'; type UploadFunType = | 'UploadESopFileForMaterial' | 'UploadESopFileForBom' | 'UploadESopFileForProcessRoutingEntry' | 'UploadESopFileForProcessRouting'; type ReplaceFunType = | 'ReplaceMaterialDocument' | 'ReplaceESopBomDocument' | 'ReplaceESopProcessRoutingDocument' | 'ReplaceESopProcessRoutingEntryDocument'; type esopPageStaus = 'Maintain' | 'Browse'; @Component({ selector: 'rh-esop-material', templateUrl: './esop-material.component.html', styleUrls: ['./esop-material.component.css'] }) export class EsopMaterialComponent implements OnInit { /**当前页面是浏览还是维护 */ esopPageStaus: esopPageStaus = 'Maintain'; /**-----------------------物料------------------- */ @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; // 默认查询参数 defaultQueryDto: RhSafeAny = {}; // 用于承接左边物料选择后的数据 selectedProduct: RhSafeAny = {}; // 打开的页签第几页 selectedIndex = 0; // 表格loading图标 dataLoading = false; //文件上传弹窗显影控制 isShowUploadModal = false; // 操作日志弹窗 isShowLogsModal = false; // 预览文件弹窗 // isShowReadFileModal = false; // 绑定弹窗 isShowBindModal = false; // 替换 isShowReplaceModal = false; replaceModalWidth = '70vw'; nodeDatas: NzTreeNode[] = []; isShowGrandsonNode = true; MaterialRouteItems: RhSelectItem[] = []; // 表的数据源 dataResult!: DataResultT; /** 表格当前选中的数据 */ selectedDatas: RhBaseDto[] = []; fileViewDate!: Date; Type: Type = 'bind'; // 表头上方的按钮配置 titleButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto('batch-replace', '绑定', 'primary', 'sync', false, null, (data) => this.bindFileBtnFun(), false) ]; // 表行内按钮 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 ) ]; rhType: ESopBindType = 'Material'; /** -------------------------Bom------------------------------ */ @ViewChild('queryBomForm', { static: false }) queryBomFormCmt!: DynamicFormComponent; isShowBomTab = false; isShowBomOrMTab = 0; dataBomResult!: DataResultT; //数据集 defaultBomQueryDto: RhSafeAny = {}; //查询对像 isShowUploadBomModal = false; //bom上传弹窗 isShowBomDetails = false; filesViewDate!: Date; titleButtonBomDataset: RhTableButtonInfoDto[] = []; // 行内按钮 editButtonBomDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'readFileBomSop', '预览', 'primary', false, 'eye', false, null, (data) => this.readFileBomBtnFun(data as RhBaseDto), true, false ) ]; /**---------------------------bom详情-------------------- */ dataBomFilesResult!: DataResultT; selectedDetailsDatas: RhBaseDto[] = []; //打开详情页的数据 fileList: ESopBomDto[] = []; selecteDetailsdDatas: RhBaseDto[] = []; editButtonBomFilesDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto( // 'downloadFileBomSop', // '下载', // 'primary', // 'download', // false, // null, // (data) => this.downloadBtnFun(data as ESopBomDto), // true, // false // ), new RhTableButtonInfoDto( 'readFileBomSop', '预览', 'primary', false, 'eye', false, null, (data) => this.readFileBtnFun(data as RhBaseDto), true, false ) ]; titleButtonBomDetailDataset: RhTableButtonInfoDto[] = []; //使用文件替换的时候调用的方法在esop-new.service中 ReplaceFun: ReplaceFunType = 'ReplaceMaterialDocument'; examineData: RhSafeAny[] = []; // 审核弹窗 isShowExamineModal = false; examineType: ESopBindType = 'Material'; //当前树选中 /**用于承接左边物料多选后的数据*/ checkboxItems: RhBaseDto[] = []; constructor(private esopService: RhEsopNewService, private apiUrls: RhApiUrlsService, private activatedRoute: ActivatedRoute) {} ngOnInit(): void { // 获取当前页面是维护还是浏览 this.activatedRoute.data.subscribe((res) => { this.esopPageStaus = res['EsopPs']; if (res['EsopPs'] === ESOP_PAGE_STATUS.Maintain) { //bom this.editButtonBomDataset = [ new RhTableButtonInfoDto( 'uploadFileBomSop', '上传', 'primary', false, 'upload', false, null, (data) => this.uploadBomBtnFun(data as RhBaseDto), true, false ), ...this.editButtonBomDataset ]; // bom详情页 this.titleButtonBomDetailDataset = [ new RhTableButtonInfoDto( 'to-examine', '批量审核', // 名字叫上传其实是绑定 bind // '添加', 'default', false, 'audit', false, null, (data) => this.examineBomFileBtnFun(this.selecteDetailsdDatas), false ) ]; this.editButtonBomFilesDataset = [ ...this.editButtonBomFilesDataset, // new RhTableButtonInfoDto( // 'bindBomFileSop', // '替换', // 'default', // 'swap', // false, // null, // (data) => this.bindBomFileBtnFun(data as RhBaseDto), // true, // false, // 'green' // ), new RhTableButtonInfoDto( 'bindFileSop', '替换', 'default', false, 'swap', false, null, (data) => this.bindBomFileBtnFun(data as RhBaseDto), true, false, 'green' ), new RhTableButtonInfoDto( 'examineSop', '审核', 'default', false, 'audit', false, null, (data) => this.examineBomFileBtnFun(data as RhBaseDto), true, false, 'green', "data=>data.SopStatus !== 'Pass' " ), new RhTableButtonInfoDto( 'removeBomFileSop', '删除', 'primary', true, 'delete', false, null, (data) => this.removeBomFileBtnFun(data as RhBaseDto), true, false, 'red' ), new RhTableButtonInfoDto( 'logs', '查看操作日志', 'default', false, 'unordered-list', false, null, (data) => this.getLogs(ESopBindTypeEnum.Bom, data as RhBaseDto), true, false, '#00f' ) ]; //物料 this.titleButtonDataset = [ // new RhTableButtonInfoDto( // 'batch-bind', // '上传', // 名字叫上传其实是绑定 bind // // '添加', // 'primary', // 'upload', // false, // null, // () => this.uploadOrReplaceTitleBtnFun(this.selectedProducts), // // (data) => this.uploadOrReplaceBtnFun('upload'), // true // ), new RhTableButtonInfoDto( 'to-examine', '批量审核', 'default', false, 'audit', false, null, (data) => this.examineFileBtnFun(this.selectedDatas), false ) ]; this.editButtonDataset = [ ...this.editButtonDataset, new RhTableButtonInfoDto( 'bindFileSop', '替换', 'default', false, 'swap', false, null, (data) => this.bindFileBtnFun(data as RhBaseDto), true, false, 'green' ), new RhTableButtonInfoDto( 'examineSop', '审核', 'default', false, 'audit', false, null, (data) => this.examineFileBtnFun(data as RhBaseDto), true, false, 'green', "data=>data.SopStatus !== 'Pass' " ), 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(ESopBindTypeEnum.Material, data as RhBaseDto), true, false, '#00f' ) ]; } else if (res['EsopPs'] === ESOP_PAGE_STATUS.Browse) { // 只能看 } }); // this.getMaterialDocumentDatas(); } /** * 树形接口选中后上弹事件绑定方法 * @param event */ SelectNodeChange(node: NzTreeNode) { if (node) { if (node.origin['customData'] && node.level === 1 && node.isSelected) { const data = node.origin['customData']; if (data) { this.selectedProduct = JSON.parse(JSON.stringify(data)); this.selectedProduct.MaterialCode = '$' + this.selectedProduct.MaterialCode; this.getDatas(); } } else { this.selectedProduct = null; } } } /** * 选中的物料信息 绑定事件 * @param event */ // GetSelectedMaterial(event) { // // console.log(event); // if (event) { // this.selectedProduct = event; // this.getDatas(); // } // } /** * 物料树复选框多选 绑定事件 * @param event */ getCheckBoxChange(event: NzTreeNode[]) { // console.log(event); const arr: RhBaseDto[] = []; this.getNzTreeNodeSelects(event, arr); this.checkboxItems = arr; } /** * 递归调用获取最下层数据 * @param event * @param arr */ getNzTreeNodeSelects(event: NzTreeNode[], arr: RhSafeAny[]) { event.forEach((e: NzTreeNode) => { if (e.children.length == 0 && e.origin['customData']?.MaterialCode) { arr.push(e.origin['customData']); } else { this.getNzTreeNodeSelects(e.children, arr); } }); } selectedDatasChange(event: RhBaseDto[]) { // console.log(event); this.selectedDatas = event; } selectedBomDetailsDatasChange(event: RhBaseDto[]) { // console.log(event); this.selecteDetailsdDatas = event; } // 调用查询 getDatas(option?: RhTableQueryOptionDto) { // console.log(this.queryFormCmt); const queryDto: RhSafeAny = {}; const queryBomDto: RhSafeAny = {}; queryDto.MaterialCode = this.selectedProduct?.MaterialCode; queryDto.MaterialName = this.selectedProduct?.MaterialName; //bom查询赋值 queryBomDto.MaterialCode = this.selectedProduct?.MaterialCode; queryBomDto.MaterialName = this.selectedProduct?.MaterialName; this.defaultBomQueryDto = queryBomDto; this.defaultQueryDto = queryDto; setTimeout(() => { if (this.isShowBomOrMTab == 1) { this.queryBomFormCmt.submitDefaultForm(null, option); } else if (this.isShowBomOrMTab == 0) { this.queryFormCmt.submitDefaultForm(null, option); } else if (this.isShowBomOrMTab == 2) { this.getBomFiles(this.selectedDetailsDatas[0]); } }); } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } /** * 获取 */ // getMaterialDocumentDatas() { // const queryDto = MaterialDocumentQueryDto.create(); // this.esopService.GetMaterialDocumentDatas(queryDto).subscribe((result) => { // // console.log(result); // if (result.Success) { // const childNodes: NzTreeNode[] = []; // result.Attach.forEach((temp) => { // const tempNode = new NzTreeNode( // { // title: temp.MaterialName, // key: temp?.MaterialCode, // isLeaf: true, // customData: temp // } // // temp // ); // childNodes.push(tempNode); // }); // this.nodeDatas = childNodes; // } // }); // } /** * form查询完成上弹事件绑定方法 * @param dataset */ resultDataChange(dataset: DataResultT) { this.dataResult = dataset; } /** * bom form查询完成上弹事件绑定方法 * @param dataset */ resultDataBomChange(dataset: DataResultT) { this.dataBomResult = dataset; } /** * * @param status */ dataLoadingChange(status: boolean) { this.dataLoading = status; } /** * 打开bom标签 */ selectedBomOrMIndexChange() { setTimeout(() => { this.getDatas(); }, 100); } /** * 下载按钮 * @param data */ downloadBtnFun(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); } } } openBomTab() { this.isShowBomTab = true; this.isShowBomOrMTab = 1; this.selectedBomOrMIndexChange(); } // #region -----------------物料----------------- /** * 预览按钮 * @param data */ readFileBtnFun(data: RhBaseDto) { this.selectedDatas = [data]; this.fileViewDate = new Date(); // this.isShowReadFileModal = true; } /** * 打开文件弹窗 * @param uploadType * @param data */ uploadOrReplaceBtnFun(uploadType: Type, data?: RhBaseDto) { this.Type = uploadType; if (data) this.selectedDatas = [data]; if (this.selectedDatas && this.selectedDatas.length > 0) this.isShowUploadModal = true; } /** * 物料绑定文件弹窗关闭 */ BindModalClose() { this.replaceModalWidth = '70vw'; this.isShowBindModal = false; this.getDatas(); } /** * 替换按钮方法 * @param data */ bindFileBtnFun(data?: RhBaseDto) { if (data) this.selectedDatas = [data]; // TODO this.rhType = ESopBindTypeEnum.Material; this.Type = 'replace'; this.ReplaceFun = 'ReplaceMaterialDocument'; this.isShowReplaceModal = true; } /** * 替换弹窗中tab切换事件 */ tabChange(event: { index: number; tab: NzTabComponent }) { this.replaceModalWidth = event.index ? '30vw' : '70vw'; } /** * 表头 打开文件绑定弹窗 * @param uploadType * @param data */ uploadOrReplaceTitleBtnFun(data?: RhBaseDto[]) { if (data?.length) { this.selectedDatas = data; this.Type = 'bind'; this.isShowBindModal = true; } else { MsgHelper.ShowWarningMessage('请先选择物料树型列表中的物料!'); } } /** * 删除按钮 * @param data */ removeBtnFun(data: RhSelectableDto) { this.selectedDatas = [data]; MsgHelper.ShowDeleteConfirm(`物料名称:${data['MaterialName']}
文件名称:${data['DocumentInfoName']} 。
是否确认删除?`, () => { this.esopService.RemoveESopMaterialDocument([data] as ESopMaterialDto[]).subscribe((result) => { // console.log(result); if (result.Success) { MsgHelper.ShowSuccessMessage('删除成功!'); this.getDatas(); } else { MsgHelper.ShowErrorMessage(`删除失败!${result.Message}`); } }); }); } /** * 获取操作日志 * @param type * @param data */ getLogs(type: ESopBindTypeEnum, data: RhBaseDto) { this.rhType = type; this.selectedDatas = [data]; this.isShowLogsModal = true; } /** * 文件上传弹窗成功事件绑定方法 */ uploadSuccess() { this.isShowUploadModal = false; this.getDatas(); } /** * 文件替换关闭弹窗 */ bindFileModalClose() { this.replaceModalWidth = '70vw'; this.isShowReplaceModal = false; this.getDatas(); } // #endregion -----------------------物料------------------------ // #region -----------------------bom------------------------ /** * 所文件预览删除 * @param data */ delFile(data: RhSafeAny) { if (data.type) { this.readFileBomBtnFun(this.selectedDatas[0]); } } /** * 关闭弹窗 */ uploadModalBomClose() { this.isShowUploadBomModal = false; this.getDatas(); } /** * * @param data */ readFileBomBtnFun(data: RhBaseDto) { this.selectedDatas = [data]; const params = ESopBomQueryDto.create(); params.BomCode = data['BomCode'] || data['ProductBomCode']; params.MaterialCode = data['MaterialCode']; params.MaterialName = data['MaterialName']; if (this.esopPageStaus === ESOP_PAGE_STATUS.Maintain) { this.esopService.GetEsopBomDatas(params).subscribe((reslut) => { this.fileList = reslut.Attach; this.filesViewDate = new Date(); // if (reslut.Success) { // this.fileList = reslut.Attach; // this.filesViewDate = new Date(); // } else { // this.fileList = reslut.Attach; // this.filesViewDate = new Date(); // // MsgHelper.ShowInfoMessage('获取失败,' + reslut.Message); // } }); } else if (this.esopPageStaus === ESOP_PAGE_STATUS.Browse) { this.esopService.BrowseEsopBomDatas(params).subscribe((reslut) => { this.fileList = reslut.Attach; this.filesViewDate = new Date(); }); } } /** * 上传弹窗 * @param data */ uploadBomBtnFun(data: RhBaseDto) { this.selectedDatas = [data]; this.isShowUploadBomModal = true; } /** * 打开bom详情页 * @param data */ openBomDetailsBtnFun(data: RhBaseDto) { this.selectedDetailsDatas = [data['data']]; this.isShowBomDetails = false; setTimeout(() => { this.isShowBomDetails = true; this.isShowBomOrMTab = 2; // this.getBomFiles(data.data); }, 100); } /** * 关闭详情页 */ closeEntryTab() { this.isShowBomDetails = false; } /** * 获取bom文件 * @param data */ getBomFiles(data: RhBaseDto) { const params = ESopBomQueryDto.create(); params.BomCode = data['ProductBomCode']; params.MaterialCode = data['MaterialCode']; params.MaterialName = data['MaterialName']; if (this.esopPageStaus === ESOP_PAGE_STATUS.Maintain) { this.esopService.GetEsopBomDatas(params).subscribe((reslut) => { if (reslut.Success) { this.dataBomFilesResult = reslut as unknown as DataResultT; } else { this.dataBomFilesResult = DataResultT.fail('获取失败,' + reslut.Message, {} as RhBaseDto); MsgHelper.ShowErrorMessage('获取失败,' + reslut.Message); } }); } else if (this.esopPageStaus === ESOP_PAGE_STATUS.Browse) { this.esopService.BrowseEsopBomDatas(params).subscribe((reslut) => { if (reslut.Success) { this.dataBomFilesResult = reslut as unknown as DataResultT; } else { this.dataBomFilesResult = DataResultT.fail('获取失败,' + reslut.Message, {} as RhBaseDto); MsgHelper.ShowErrorMessage('获取失败,' + reslut.Message); } }); } } /** * 删除bom下文件 * @param data */ removeBomFileBtnFun(data: RhSelectableDto) { this.selectedDatas = [data]; MsgHelper.ShowDeleteConfirm(`bom名称:${data['BomCode']}
文件名称:${data['DocumentInfoName']} 。
是否确认删除?`, () => { this.esopService.RemoveESopBomDocument([data] as ESopBomDto[]).subscribe((result) => { // console.log(result); if (result.Success) { MsgHelper.ShowSuccessMessage('删除成功!'); this.getDatas(); } else { MsgHelper.ShowErrorMessage(`删除失败!${result.Message}`); } }); }); } /** * 替换 * @param data */ bindBomFileBtnFun(data: RhBaseDto) { if (data) this.selectedDatas = [data]; // TODO this.rhType = ESopBindTypeEnum.Bom; this.ReplaceFun = 'ReplaceESopBomDocument'; this.Type = 'replace'; this.isShowReplaceModal = true; } closeBomTab() { this.isShowBomTab = false; } // #endregion ---------------------bom------------------------- /** * bom文件审核 * @param data */ examineBomFileBtnFun(data: RhBaseDto) { this.examineData = Array.isArray(data) ? data : [data]; this.examineType = 'Bom'; this.isShowExamineModal = true; } /** * 物料审核 * @param data */ examineFileBtnFun(data: RhBaseDto) { this.examineData = Array.isArray(data) ? data : [data]; this.examineType = 'Material'; this.isShowExamineModal = true; } uploadModalexamineClose() { this.isShowExamineModal = false; this.getDatas(); } }