import { OpResult, RhBaseDto, RhSelectItem } from 'rh-base/model'; import { RhProcessRouteService } from './../../../process-route.service'; import { ProcessRoutingEntryDto } from './../../../../mdp-model'; import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; import { UntypedFormBuilder } from '@angular/forms'; import { MsgHelper, RhApiUrlsService } from 'rh-base/core'; type uploadType = 'upload' | 'replace'; @Component({ selector: 'rh-process-info-edit', templateUrl: './process-info-edit.component.html', styleUrls: ['./process-info-edit.component.less'] }) export class ProcessInfoEditComponent implements OnInit { @Input() rhData!: ProcessRoutingEntryDto; //通过rhDataChange来双向绑定ProcessRoutingEntryDto的变化,使之与外界进行交互 @Output() rhDataChange = new EventEmitter(); @Input() rhEditable = true; // 只获取数据变化,不调用接口,用于流程图绘制时的工序编辑 @Input() rhGetDataOnly = false; // *********编辑form********************** // editForm: FormGroup; // editDto: ProcessRoutingEntryDto; // ********质量配置相关******** // newAdd = true; // firstInspectTypeDatas = FirstInspectTypeDatas; submitQualityLoading = false; isShowButton = true; isShowQualityTab = true; isQualityConfig!: boolean; // 当前tab页序列号 selectedIndex!: number; // 工序列表 processResourceTypes: RhSelectItem[] = []; // 上传sop uploadType: uploadType = 'upload'; uploadDatas: RhBaseDto[] = []; isShowUploadModal = false; processBeforeSubmit = () => { if (this.rhGetDataOnly) { this.rhDataChange.emit(this.rhData); } return !this.rhGetDataOnly; }; constructor(public operator: RhProcessRouteService, public fb: UntypedFormBuilder, private apiUrls: RhApiUrlsService) {} formatQualificationRate = (value: number) => `${value ? value : '0'} %`; ngOnInit() { // this.initEditQualityDto(); // if (!this.editForm) { // this.createEditForm(ProcessRoutingEntryDto.create()); // } // this.initDatas(); // this.getProcessResourceTypes(); } initDatas() { // } // ngOnChanges(changes: SimpleChanges) { // const { rhData } = changes; // if (rhData && rhData.currentValue) { // if (this.editForm) { // this.editForm.reset(this.rhData); // // this.getDatas(this.initProcessRoutingQualityPtyQueryDto()); // // console.log(this.rhData); // } else { // this.createEditForm(this.rhData, true); // } // } // } //#region 关联Form编辑区域 initEditItem(): ProcessRoutingEntryDto { // 使用构造函数初始化对象 const dto = ProcessRoutingEntryDto.create(); dto.ProductBaseQty = 1; return dto; } // createEditForm(dto: ProcessRoutingEntryDto, isData = false) { // this.editForm = this.fb.group({ // ProcessRoutingCode: [dto.ProcessRoutingCode], // ProcessCode: [dto.ProcessCode], // ProcessSeq: [dto.ProcessSeq], // IskeyWorkStage: [dto.IskeyWorkStage], // IsOutSide: [dto.IsOutSide], // OutSideCycle: [dto.OutSideCycle], // // TimeUnit: [dto.TimeUnit, ], // ProcessType: [dto.ProcessType], // StandardWorkTimeUnit: [dto.StandardWorkTimeUnit], // StandardWorkTime: [dto.StandardWorkTime], // LaborTime: [dto.LaborTime], // MachineTime: [dto.MachineTime], // LaborWorkingTime: [dto.LaborWorkingTime], // MachineWorkingTime: [dto.MachineWorkingTime], // QualificationRate: [dto.QualificationRate], // IsDispatch: [isData ? dto.IsDispatch : true], // 是否派工 // IsReport: [isData ? dto.IsReport : true], // 是否报工 // ProductBaseQty: [isData ? dto.ProductBaseQty : 1] // }); // } // submitEditForm($event: Event) { // if ($event) { // $event.preventDefault(); // } // if (!this.rhData) { // MsgHelper.ShowWarningMessage(`请先选择工序!`); // return; // } // // this.editDto.FactoryCode = this.rhData.FactoryCode; // FormHelper.YGSubmitForm(this.rhData, this.editForm, (dto) => { // if (this.rhGetDataOnly) { // this.rhDataChange.emit(this.rhData); // } else { // this.operator.StoreProcessRoutingEntryData(dto).subscribe((result) => { // if (result && result.Success) { // MsgHelper.ShowSuccessMessage('编辑信息成功'); // // console.log(this.rhData); // this.rhDataChange.emit(this.rhData); // } else { // MsgHelper.ShowWarningModal(`编辑工序明细失败!${result.Message}`); // } // }); // } // }); // } onStoreProcessData(result: OpResult) { if (result && result.Success) { MsgHelper.ShowSuccessMessage('编辑工序明细成功'); // console.log(this.rhData); this.rhDataChange.emit(this.rhData); } else { MsgHelper.ShowWarningModal(`编辑工序明细失败!${result.Message}`); } } // 当前激活 tab 面板的 序列号变更回调函数 // getSelectedIndex(index: number) { // // console.log(index); // this.selectedIndex = index; // } getProcessResourceTypes() { this.apiUrls .getSettingEntry({ moduleKey: 'MDP', groupKey: 'ProcessRoutingManagement', paraCode: 'ProcessResourceType' }) .subscribe((result) => { if (result.Success) { this.processResourceTypes = result.Attach; } }); } // *****************************************sop********************************************** openUploadModal(uploadType: uploadType) { this.uploadType = uploadType; this.uploadDatas = [this.rhData as RhBaseDto]; this.isShowUploadModal = true; } closeUploadModal() { this.isShowUploadModal = false; } uploadSuccess() { this.closeUploadModal(); this.rhData = { ...this.rhData }; // this.getDatas(); } }