import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { RhAppConfigService, MsgHelper } from 'rh-base/core'; import { RhSafeAny } from 'rh-base/model'; import { RhTaskDispatchService } from '../task-dispatch.service'; import { SharedService } from 'rh-itm/shared'; import { RhMessageContentDto } from 'rh-itm/model'; import { RhBusinessService } from './../../business.service'; import { WorkShopLineInfoDto, WorkShopLineInfoQueryDto, WorkShopLineExtProperyQueryDto, WorkShopLineProductionParameter } from '../../business-model'; @Component({ selector: 'rh-task-dispatch-factory', templateUrl: './task-dispatch-factory.component.html', styleUrls: ['./task-dispatch-factory.component.less'] }) export class RhTaskDispatchFactoryComponent implements OnInit { logoPath = ''; /** 当前公司名称 */ readonly companyName: string; readonly companyDisplayName: string; isShowPopupMenu = false; /** 车间列表 */ get workshopList(): WorkShopLineInfoDto[] { return this.operator.workshopList; } isShowWorkshopModal = false; /** 当前选中车间 */ get currentWorkShop(): WorkShopLineInfoDto { return this.operator.currentWorkShop; } set currentWorkShop(item: WorkShopLineInfoDto) { this.operator.currentWorkShop = item; } /** 选中车间对应的生产模式 */ productionMode = ''; /** 选中车间的生产参数配置 */ workShopProductionPara!: WorkShopLineProductionParameter; /** 当前消息内容 */ currentMessageContent!: RhMessageContentDto; /** 消息样式 */ messageStyle: { [propName: string]: string } = { color: 'whitesmoke', 'font-size': '24px', 'text-align': 'center' }; /** sucess消息 */ successStyle: { [propName: string]: string } = { color: '#49aa19', 'font-size': '24px', 'text-align': 'center' }; /** warning消息 */ warningStyle: { [propName: string]: string } = { color: '#d8bd14', 'font-size': '24px', 'text-align': 'center' }; /** error消息 */ errorStyle: { [propName: string]: string } = { color: '#d32029', 'font-size': '24px', 'text-align': 'center' }; constructor( public operator: RhTaskDispatchService, private appconfig: RhAppConfigService, public router: Router, private sharedSer: SharedService, private businessSer: RhBusinessService ) { this.companyDisplayName = (this.appconfig.appConfig as RhSafeAny).CompanyDisplayName; this.companyName = this.appconfig.appConfig.CompanyName as string; this.logoPath = `./assets/pages/logo_${this.companyName}.png`; } ngOnInit(): void { this.sharedSer.popupMenuVisibleSubject$.subscribe((status) => { this.isShowPopupMenu = status; }); if (!this.currentWorkShop) { this.getWorkShopList(); } else { // 根据选择的车间获取生产参数 this.getProductionParaData(this.currentWorkShop.OrganizationStructureCode); } this.subscribeMessageContent(); } // ********** 多播订阅 ********** private subscribeMessageContent() { this.businessSer.messageContent$.subscribe((result) => { if (result) { this.currentMessageContent = this.businessSer.currentMessageContent = result; } }); } returnToDefaultPage() { this.router.navigate([`${this.appconfig.projectConfig.MainPath}${this.appconfig.projectConfig.MainPagePath}`]); } openWorkshopModal() { this.isShowWorkshopModal = true; } closeWorkshopModal() { this.isShowWorkshopModal = false; } onSelectWorkShop(workshop: WorkShopLineInfoDto) { // 存储当前车间到localStorage if (!workshop) { return; } this.currentWorkShop = workshop; // 根据选择的车间获取生产参数 this.getProductionParaData(this.currentWorkShop.OrganizationStructureCode); this.closeWorkshopModal(); } private getWorkShopList() { const queryDto = WorkShopLineInfoQueryDto.create(); queryDto.IsUse = true; queryDto.Mode = 8; MsgHelper.ShowGlobalLoadingMessage('正在拉取车间数据...', 0); this.operator.GetDiscreteWorkShopLineInfoDatas(queryDto).subscribe( (result) => { if (result && result.Success) { this.operator.workshopList = result.Attach; this.openWorkshopModal(); } else { MsgHelper.ShowWarningMessage(`获取目标车间列表失败,无法启用任务分派!${result.Message}`); // console.log(`车间列表获取失败:${result.Message}`); this.operator.workshopList = []; } MsgHelper.CloseGlobalLoadingMessage(); }, () => { // console.log(`车间列表获取失败!!!`); this.operator.workshopList = []; MsgHelper.CloseGlobalLoadingMessage(); } ); } private getProductionParaData(code: string) { const queryDto = WorkShopLineExtProperyQueryDto.create(); queryDto.OrganizationStructureCode = code; this.operator.GetWorkShopLineProductionParameterData(queryDto).subscribe((result) => { if (result && result.Success) { this.productionMode = result.Attach.ProductionMode as string; this.workShopProductionPara = result.Attach; } else { this.workShopProductionPara = WorkShopLineProductionParameter.create(); MsgHelper.ShowWarningMessage(`车间生产参数获取失败!${result.Message}`); this.productionMode = ''; } }); // console.log(this.productionMode); } }