import { Component, OnInit, ViewChild } from '@angular/core'; import { FormGroup } from '@angular/forms'; import { MsgHelper, ObjectHelper } from 'rh-base/core'; import { CodeClassModel, DataResultT, OpMode, OpResult, RhBaseDto, RhDynamicTableFieldDto, RhSafeAny, RhSelectableDto, RhTableButtonInfoDto, RhTableQueryOptionDto, WithNil } from 'rh-base/model'; import { DynamicFormComponent } from 'rh-base/shared'; import { ProductionConfigurationService } from '../production-configuration.service'; import { ProcessInfoDto, ProcessInfoQueryDto } from '../../ppm-model'; @Component({ selector: 'rh-scrp-reason-paras', templateUrl: './scrp-reason-paras.component.html', styleUrls: ['./scrp-reason-paras.component.less'] }) export class RhScrpReasonParasComponent implements OnInit { @ViewChild('scrpReasonParasQueryForm', { static: false }) queryFormCmt!: DynamicFormComponent; selectedIndex = 0; dataLoading = false; dataresult!: DataResultT; defaultFieldDataset: RhSafeAny = []; editDto: RhBaseDto = {}; addForm!: FormGroup; filterProcessInfos: ProcessInfoDto[] = []; ProcessInfos: ProcessInfoDto[] = []; SelectedProcess!: WithNil; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('new', '新建', 'primary', false, 'file', false, null, () => this.openEditTab(), true) ]; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('edit', '编辑', 'default', false, 'edit', false, null, (data) => this.openEditTab(data as RhBaseDto)) ]; constructor(private operator: ProductionConfigurationService) { // } ngOnInit(): void { // } beforeSubmit = (a: RhSafeAny) => { if (this.SelectedProcess) { a.ProcessCode = this.SelectedProcess.ProcessCode; a.ProcessName = this.SelectedProcess.ProcessName; return true; } else { return true; } }; dataLoadingChange(status: boolean) { this.dataLoading = status; } setDatas(dataset: DataResultT | OpResult) { this.dataresult = dataset as DataResultT; } setInitFieldDataset(item: CodeClassModel) { const tempDatas: RhSafeAny = []; item.CodeProperties.forEach((ele) => { const temp = RhDynamicTableFieldDto.create(); temp.name = ele.PropertyName; temp.displayName = ele.Descirption; tempDatas.push(temp); }); this.defaultFieldDataset = [...tempDatas]; } openEditTab(data?: RhBaseDto) { if (data) { this.editDto = data; this.editDto.OpSign = OpMode.OpEdit; } else { this.editDto = {}; this.editDto.OpSign = OpMode.OpAdd; } this.selectedIndex = 1; this.getProcessInfo(); } closeEditTab() { this.selectedIndex = 0; } refreshData(option: RhTableQueryOptionDto) { this.getDatas(option); } private getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } onStoreData(result: DataResultT | OpResult) { if (result && result.Success) { const msg = this.editDto.OpSign === OpMode.OpAdd ? '新增' : '编辑'; MsgHelper.ShowSuccessMessage(`数据${msg}成功`); if (this.editDto.OpSign === OpMode.OpEdit) { this.selectedIndex = 0; } this.editDto = ObjectHelper.createRhBaseDto(); this.getDatas(); } else { MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); } } async onChangeOfProcessCode(value: string, formGroup: FormGroup) { if (formGroup) { this.addForm = formGroup; } await this.getProcessInfo(value).then(() => { if (value) { this.filterProcessInfos = this.ProcessInfos.filter( (item) => item['ProcessCategory'] === '生产工序' && item.ProcessCode?.toLowerCase().indexOf(value.toLowerCase()) !== -1 ); } }); } // 选择计划单号获取计划单开工报工信息 getProcessCodeData(code: string) { if (!code || !code.trim()) { MsgHelper.ShowWarningModal('请输入工序代码!'); return; } if (code.indexOf('】') !== -1) { const value = code.split('】')[1]; this.SelectedProcess = this.ProcessInfos.find((e) => e.ProcessCode === value); } else { this.SelectedProcess = this.ProcessInfos.find((e) => e.ProcessCode === code); } } clearProcessCodeInput(formGroup: FormGroup) { if (formGroup) { formGroup.get('ProcessCode')?.setValue(null); } } ProcessCodeChange(code: WithNil) { if (!code || !code.trim()) { MsgHelper.ShowWarningModal('请输入工序代码!'); return; } this.SelectedProcess = this.ProcessInfos.find((e) => e.ProcessCode === code); } //获取工序 getProcessInfo(value?: string): Promise { return new Promise((resolve, reject) => { const queryDto: RhSafeAny = ProcessInfoQueryDto.create(); if (this.addForm) { queryDto.OrganizationStructureCode = this.addForm.get('OrganizationStructureCode')?.value; } queryDto.ProcessCode = value; queryDto.ProcessCategory = '质检工序'; queryDto.Mode = 8; this.operator.GetProcessInfoDatas(queryDto).subscribe( (result) => { if (result && result.Success) { this.ProcessInfos = result.Attach; if (!this.addForm || !this.addForm.get('ProcessCode')?.value) { this.filterProcessInfos = this.ProcessInfos; } } else { this.ProcessInfos = []; } resolve(this.ProcessInfos); // MsgHelper.CloseLoadingMessage(messageId); }, () => { // MsgHelper.CloseLoadingMessage(messageId); } ); }); } }