import { isNil } from 'ng-zorro-antd/core/util'; import { RhQmpService } from './../../qmp.service'; import { IpqcProductInspectOrderQueryDto, ProcessInspectItemDataCollectionDto, ProcessInspectOrderDataCollectionDto, ProcessInspectOrderReportDto, QualitySysConfigParameter, ProcessInspectProductDataCollectionDto } from './../../qmp-model'; import { Component, OnInit, ViewChild } from '@angular/core'; import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { MsgHelper, ObjectHelper, RhStorageService } from 'rh-base/core'; import { CodeClassModel, DataResultT, OpMode, RhBaseDto, RhDynamicComponentFieldType, RhDynamicTableFieldDto, RhSafeAny, RhSelectableDto, RhSelectItem, RhTableButtonInfoDto, RhTableQueryOptionDto } from 'rh-base/model'; import { DynamicFormComponent, RhSharedService } from 'rh-base/shared'; import { RhProcessControlService } from '../process-control.service'; import { ActivatedRoute } from '@angular/router'; // import * as _ from 'lodash'; @Component({ selector: 'rh-process-inspect-management', templateUrl: './process-inspect-management.component.html', styleUrls: ['./process-inspect-management.component.less'] }) export class RhProcessInspectManagementComponent implements OnInit { /** 当前的检验类别 */ inspectCategory = 'productInspect'; @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; // @ViewChild('inspectValueInput', { static: false }) inspectValueInput: NzInputNumberComponent; selectedIndex = 0; editDto: RhBaseDto = {}; dataLoading = false; dataresult!: DataResultT; isShowEditModal = false; tabType: string | null = 'edit'; defaultFieldDataset: RhDynamicComponentFieldType[] = []; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'edit', '编辑', 'default', false, 'edit', false, null, (data) => this.openEditTab(data as RhBaseDto), true, true, '#1890FF', "data => data.OrderStatus === 'WaitInspection'" ), new RhTableButtonInfoDto( 'collection', '数据录入', 'default', false, 'form', false, null, (data) => this.openDataEntryTab(data as RhBaseDto), true, true, '#1890FF', "data => data.OrderStatus !== 'CompleteInspection'" ), new RhTableButtonInfoDto( 'report', '查看报告', 'default', false, 'eye', false, null, (data) => this.openOrderReportTab(data as RhBaseDto), true, true, '#1890FF', "data => data.OrderStatus === 'CompleteInspection'" ), new RhTableButtonInfoDto( 'defectRecord', '缺陷记录', 'default', false, 'bars', false, null, (data) => this.openDefectRecordTab(data as RhBaseDto), true, true, '#1890FF', "data => data.OrderStatus !== 'WaitInspection'" ), new RhTableButtonInfoDto( 'usingDecision', '使用决策', 'default', false, 'solution', false, null, (data) => this.openUsingDecisionTab(data as RhBaseDto), true, true, '#1890FF', "data => data.OrderStatus === 'CompleteInspection'" ) ]; titleButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto('new', '新建', 'primary', 'file', false, null, () => this.openEditTab(), true) ]; selectData!: RhBaseDto; collapseQueryDto = {}; defaultQueryDto: Record = {}; /** 检验日期 */ startDate!: Date; endDate!: Date; inspectOrderQueryDto!: IpqcProductInspectOrderQueryDto; /** 需要录入的数据信息(最外层模型) */ collectionData: ProcessInspectOrderDataCollectionDto | null = null; collectionDataLoading = false; /** (第二层模型数据) */ itemDataCollectionDtos: ProcessInspectItemDataCollectionDto[] = []; /** 检验模式数据 */ inspectModeDatas: RhSelectItem[] = []; /** 检验方法数据 */ inspectMethodDatas: RhSelectItem[] = []; // *********** 数据录入modal ********** isShowDataEntryModal = false; entryForm!: UntypedFormGroup; entrySubmitLoading = false; entryStoreLoading = false; // ********** 数据提交 ********** isShowJudgeDataFillModal = false; resultDataFillForm!: UntypedFormGroup; resultDataDto = this.initResultDataDto(); // ********** 查看报告相关 *********** orderReportData: ProcessInspectOrderReportDto | null = null; orderReportEntryDatas: Record | null = {}; reportDataLoading = false; qualityConfigDto!: QualitySysConfigParameter; constructor( public sharedSer: RhSharedService, public storageSer: RhStorageService, public fb: UntypedFormBuilder, private operator: RhProcessControlService, public qmpSer: RhQmpService, public route: ActivatedRoute ) { // } ngOnInit() { const code = this.route.snapshot.queryParamMap.get('InspectOrderCode'); if (code) { this.defaultQueryDto['InspectOrderCode'] = code; } this.inspectOrderQueryDto = IpqcProductInspectOrderQueryDto.create(); this.getQualitySysConfigParameterData(); } openEditTab(data?: RhBaseDto) { // this.rangeDate = []; if (data) { this.editDto = data; this.editDto['InspectPlanDateRange'] = [data['InspectPlanStartTime'], data['InspectPlanEndTime']]; this.editDto.OpSign = OpMode.OpEdit; } else { this.editDto = {}; this.editDto.OpSign = OpMode.OpAdd; } this.selectData = data as RhBaseDto; this.tabType = 'edit'; this.selectedIndex = 1; } closeEditTab() { this.tabType = null; this.selectedIndex = 0; } setDatas(dataset: DataResultT) { this.dataresult = dataset; if (!this.dataresult?.Success) { MsgHelper.ShowWarningMessage(`搜索无数据!${this.dataresult?.Message}`); } } dataLoadingChange(status: boolean) { this.dataLoading = status; } onStoreData(result: DataResultT) { 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.ShowWarningModal(`存储数据失败!${result.Message}`); } } setInitFieldDatset(item: CodeClassModel) { const tempDatas: RhDynamicComponentFieldType[] = []; item.CodeProperties.forEach((ele) => { const temp = RhDynamicTableFieldDto.create(); temp.name = ele.PropertyName; temp.displayName = ele.Descirption; tempDatas.push(temp); }); this.defaultFieldDataset = [...tempDatas]; } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } //调用子组件中的接口 private getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } initDefaultQueryDto(dto: RhSafeAny) { this.collapseQueryDto = dto; this.defaultQueryDto = { ...this.defaultQueryDto, ...this.collapseQueryDto }; } getValueChange() { this.defaultQueryDto = { ...this.defaultQueryDto, ...this.collapseQueryDto }; setTimeout(() => { this.getDatas(); }); } setStartAndEndDate(dates: Date[]) { if (!dates || dates?.length < 2) { return; } this.startDate = new Date(dates[0]); this.endDate = new Date(dates[1]); } dataHandler = (data: RhBaseDto) => { data['InspectPlanStartTime'] = this.startDate; data['InspectPlanEndTime'] = this.endDate; return true; }; //#region ********** 缺陷报告tab ********** openDefectRecordTab(dto: RhBaseDto) { this.selectData = dto; this.tabType = 'defectRecord'; this.selectedIndex = 1; } closeDefectRecordTab() { this.tabType = null; this.selectedIndex = 0; } //#endregion // //#region ********** 使用决策tab ********** openUsingDecisionTab(dto: RhBaseDto) { this.selectData = dto; this.tabType = 'usingDecision'; this.selectedIndex = 1; } closeUsingDecisionTab() { this.tabType = null; this.selectedIndex = 0; } //#endregion // //#region ********** 数据录入Tab ********** openDataEntryTab(data: RhBaseDto) { if (data['OrderStatus'] === 'CompleteInspection') { MsgHelper.ShowWarningModal('当前任务单已完成检验,无法进行数据录入'); return; } this.selectData = data; /** 初始化table的widthConfig和nzScroll的值 */ // this.initWidthConfig(); this.tabType = 'dataEntry'; this.selectedIndex = 1; // 获取需要录入的数据信息 this.getProcessInspectOrderDataCollectionData(this.selectData); } closeDataEntryTab() { this.selectedIndex = 0; } // 获取需要录入的数据信息 getProcessInspectOrderDataCollectionData(data: RhBaseDto) { this.collectionDataLoading = true; this.inspectOrderQueryDto.InspectOrderCode = data['InspectOrderCode']; // this.productList = []; this.operator.GetProcessInspectOrderDataCollectionData(this.inspectOrderQueryDto).subscribe( (result) => { if (result && result.Success) { /** 一层数据 */ this.collectionData = result.Attach; // 检验项目数据采集 /** 二层数据 */ this.itemDataCollectionDtos = this.collectionData.ItemDataCollectionDtos as ProcessInspectItemDataCollectionDto[]; } else { this.collectionData = null; this.itemDataCollectionDtos = []; // this.productList = []; } this.collectionDataLoading = false; }, () => { this.collectionDataLoading = false; } ); } // 开始检验 startInspectProcessInspectOrder() { if (this.selectData['InspectStartTime']) { return; } this.operator.StartInspectProcessInspectOrder(this.collectionData as ProcessInspectOrderDataCollectionDto).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage('开始检验成功!'); this.selectData['InspectStartTime'] = result.Attach?.['InspectStartTime']; if (this.collectionData) { this.collectionData.InspectStartTime = result.Attach?.['InspectStartTime']; // this.collectionData = {...this.collectionData}; // this.storageDatas.InspectStartTime = result.Attach.InspectStartTime; } this.selectData = { ...this.selectData }; } else { MsgHelper.ShowErrorMessage(`开始检验失败!${result.Message}`); } }); } // 点击数据提交按钮,弹出合格数、不良数及检验结果的填写modal openResultDataFillModal() { if ( this.qualityConfigDto?.IsIqcMustDataEntry && !this.validateDataEntryCompletion(this.collectionData as ProcessInspectOrderDataCollectionDto) ) { MsgHelper.ShowErrorModal('存在未填写的数据,请检查后重试!'); return; } ObjectHelper.MapT(this.collectionData as ProcessInspectOrderDataCollectionDto, this.resultDataDto); this.resultDataDto.OpSign = OpMode.OpAdd; this.resultDataDto['InspectorCode'] = this.resultDataDto['InspectorCode'] || this.storageSer.getUserSession()?.User?.UserName; this.resultDataDto['InspectorName'] = this.resultDataDto['InspectorName'] || this.storageSer.getUserSession()?.User?.DisplayName; this.isShowJudgeDataFillModal = true; } closeResultDataFillModal() { this.isShowJudgeDataFillModal = false; } onStoreEntryData(result: DataResultT) { if (result && result.Success) { MsgHelper.ShowSuccessMessage(`数据提交成功!`); if (this.isShowJudgeDataFillModal) { this.isShowJudgeDataFillModal = false; } this.resultDataDto = this.initResultDataDto(); // 关闭数据录入tab,回到主界面并刷新数据 this.getDatas(); this.tabType = null; this.selectedIndex = 0; } else { MsgHelper.ShowWarningModal(`数据提交失败!${result.Message}`); } } entryDataHandler = (data: RhBaseDto) => { if (data['GoodQty'] + data['BadQty'] === data['SendInspectQty']) { return true; } else { MsgHelper.ShowWarningModal('合格数与不良数之和不等于送检数量,请检查!'); return false; } }; //#endregion ********** 数据录入 ********** // // //#region ********** 数据录入Modal ********** openDataEnrtyModal() { this.isShowDataEntryModal = true; } closeDataEnrtyModal(data: ProcessInspectOrderDataCollectionDto | null) { // TODO: 自动暂存 // this.currentInputInspectItem = null; // this.currentInputProduct = null; if (data) { this.storeEntryData(data); } this.isShowDataEntryModal = false; } // 数据暂存 storeEntryData(data: ProcessInspectOrderDataCollectionDto) { this.entryStoreLoading = true; this.operator.StoreProcessInspectOrderDataCollectionData(data).subscribe( (result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage('检验数据暂存成功!'); this.getProcessInspectOrderDataCollectionData(this.selectData); // this.closeDataEnrtyModal(); } else { MsgHelper.ShowErrorMessage(`检验数据暂存失败:${result.Message}`); } this.entryStoreLoading = false; }, () => { this.entryStoreLoading = false; } ); } //#endregion ********** 数据录入Modal ********** // //#region ********** 查看报告tab ********** openOrderReportTab(dto: RhBaseDto) { if (dto['OrderStatus'] !== 'CompleteInspection') { MsgHelper.ShowWarningModal('当前任务单尚未完成检验,无法查看报告!'); return; } this.selectData = dto; this.tabType = 'orderReport'; // 获取报告数据 this.getProcessInspectOrderReportData(); } closeOrderReportTab() { this.tabType = 'edit'; this.selectedIndex = 0; } getProcessInspectOrderReportData() { this.reportDataLoading = true; const queryDto = IpqcProductInspectOrderQueryDto.create(); // queryDto.InspectSchemaCode = this.selectData.InspectSchemaCode; queryDto.InspectOrderCode = this.selectData['InspectOrderCode']; this.operator.GetProcessInspectOrderReportData(queryDto).subscribe( (result) => { if (result && result.Success) { this.selectedIndex = 1; this.orderReportData = result.Attach; this.orderReportEntryDatas = { ReportGroupDtos: [this.orderReportData] }; } else { MsgHelper.ShowWarningMessage(`获取检验单明细数据失败!${result.Message}`); this.orderReportData = null; this.orderReportEntryDatas = null; } this.reportDataLoading = false; }, () => { this.reportDataLoading = false; } ); } private getQualitySysConfigParameterData() { this.qmpSer.GetQualitySysConfigParameterData().subscribe((result) => { if (result.Success) { this.qualityConfigDto = result.Attach; } else { MsgHelper.ShowWarningMessage(`加载质量系统参数配置失败:${result.Message}`); } }); } private initResultDataDto(): RhBaseDto { const temp = ObjectHelper.createRhBaseDto(); temp['InspectorCode'] = this.storageSer.getUserSession()?.User?.UserName; temp['InspectorName'] = this.storageSer.getUserSession()?.User?.DisplayName; return temp; } validateDataEntryCompletion(data: ProcessInspectOrderDataCollectionDto): boolean { // 项目维度时,检测`ItemDataCollectionDtos`,物料/产品维度,检测`MaterialDataCollectionDtos` if (data?.IsItemEntry) { return this.validateItemDataCollectionDatas(data.ItemDataCollectionDtos as ProcessInspectItemDataCollectionDto[]); } else { return this.validateMaterialDataCollectionDatas(data.ProductDataCollectionDtos as ProcessInspectProductDataCollectionDto[]); } } private validateItemDataCollectionDatas(datas: ProcessInspectItemDataCollectionDto[]): boolean { let valid = true; if (datas?.length) { return true; } datas.forEach((ele) => { if (ele?.ItemDataValueDtos?.length) { if (ele.ItemDataValueDtos.some((inner) => isNil(inner.InspectResult))) { valid = false; } } }); return valid; } private validateMaterialDataCollectionDatas(datas: ProcessInspectProductDataCollectionDto[]) { let valid = true; if (!datas?.length) { return true; } datas.forEach((ele) => { if (ele?.ProductDataValueDtos?.length) { if (ele.ProductDataValueDtos.some((inner) => isNil(inner.InspectResult))) { valid = false; } } }); return valid; } }