import { RhBasicRadioDto } from 'rh-itm/model'; import { DataDisplayDto } from 'rh-itm/shared'; import { ProductionEmployeeQueryDto } from './../../production-manage/production-manage-model'; import { ProductionEmployeeDto, WorkShopLineInfoDto, WorkShopLineProductionParameter } from './../../business-model'; import { Component, EventEmitter, Input, OnInit, Output, SimpleChanges, 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, RhLoginedUserDto, RhSafeAny, RhSelectableDto, RhSelectItem, RhTableButtonInfoDto, RhTableQueryOptionDto } from 'rh-base/model'; import { DynamicFormComponent, RhSharedService } from 'rh-base/shared'; import { IpqcProductInspectOrderQueryDto, ProcessInspectItemDataCollectionDto, ProcessInspectOrderDataCollectionDto, ProcessInspectOrderReportDto } from '../process-control-model'; import { RhProcessControlService } from '../process-control.service'; @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; /** 当前选中车间 */ @Input() rhCurrentWorkShop!: WorkShopLineInfoDto; /** 当前车间的生产参数配置 */ @Input() rhWorkShopProductionPara!: WorkShopLineProductionParameter; /** 是否开始获取数据 */ @Input() isShowWaitProductionOrderDatas = false; isShowWaitProductionOrderListDrawer = false; /** 选择车间 */ @Output() rhSelectWorkShop = new EventEmitter(); /***员工信息相关 */ /** 当前登陆员工(扫码登陆) */ currentEmployee: ProductionEmployeeDto | null = null; /** 员工信息展示数据内容 */ // displayEmployeeDataset: DataDisplayDto[] = []; /** 车间信息展示数据内容 */ displayWorkshopDataset: DataDisplayDto[] = []; /** 系统登录用户 */ loginUser!: RhLoginedUserDto; /** 抽屉状态 */ drawerType = 'base'; /** 在base状态显示的index */ baseSelectedIndex = 1; // 员工班次信息 currentClassType!: RhSelectItem; basicRadioDataset: RhBasicRadioDto[] = [ { index: 1, name: 'main', displayName: '主界面', select: false, disable: false } // { index: 2, name: 'report', displayName: '数据录入', select: false, disable: false }, // { index: 3, name: 'sop', displayName: '查看报告', select: false, disable: false } ]; // @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', // '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'" ) ]; titleButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto('new', '新建', 'primary', 'file', false, null, () => this.openEditTab(), true) ]; selectData!: RhBaseDto; collapseQueryDto: RhSafeAny = {}; defaultQueryDto: RhSafeAny = {}; /** 检验日期 */ 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: Partial | null = null; reportDataLoading = false; constructor( public sharedSer: RhSharedService, public storageSer: RhStorageService, public fb: UntypedFormBuilder, private operator: RhProcessControlService ) { // } ngOnInit() { this.inspectOrderQueryDto = IpqcProductInspectOrderQueryDto.create(); if (this.rhCurrentWorkShop) { this.defaultQueryDto.OrganizationStructureCode = this.rhCurrentWorkShop.OrganizationStructureCode; } // if (!this.rhCurrentWorkShop && this.dataresult) { // this.dataresult.Attach = []; // this.dataresult = { ...this.dataresult }; // } } ngOnChanges(changes: SimpleChanges) { if ( changes && changes['rhCurrentWorkShop'] && changes['isShowWaitProductionOrderDatas'] && changes['isShowWaitProductionOrderDatas'].currentValue === true ) { // this.drawerType = 'scheduling-list'; this.isShowWaitProductionOrderListDrawer = true; const queryDto: RhBaseDto = {}; queryDto['OrganizationStructureCode'] = this.rhCurrentWorkShop.OrganizationStructureCode; // this.defaultQueryDto.OrganizationStructureCode = this.rhCurrentWorkShop.OrganizationStructureCode; this.defaultQueryDto = queryDto; this.defaultQueryDto = { ...this.defaultQueryDto }; this.getValueChange(); } } //#region ********** 员工信息相关 ********** /** * 上工扫码验证 * @param user */ validateUser(user: string) { if (!user || !user.trim()) { MsgHelper.ShowWarningModal('请进行上工扫码!'); return; } const queryDto = ProductionEmployeeQueryDto.create(); queryDto.EmployeeCode = user; this.operator.LoginProductionEmployeeDiscrete(queryDto).subscribe((result) => { if (result && result.Success) { this.currentEmployee = result.Attach; // this.setDisplayEmployeeDataset(); // this.userInput.nativeElement.value = null; } else { MsgHelper.ShowErrorModal(`员工扫码验证失败:${result.Message}`); this.currentEmployee = null; } }); } // 登出 logOutEmployee() { this.operator.LogoutProductionEmployeePP(this.currentEmployee as ProductionEmployeeDto).subscribe((result) => { if (result && result.Success) { // 清除任务单信息 // this.currentProductionWaitProcessOrder = null; // 按钮状态再判断 // this.searchButtonDisabled(); // this.reportButtonDisable(); // this.printButtonDisable(); // this.startButtonDisable(); // 抽屉开关重置 if (this.isShowWaitProductionOrderListDrawer) { this.closeWaitProductionOrderListDrawer(); } // MsgHelper.ShowSuccessMessage(`当前员工已登出!`); this.currentEmployee = null; } else { MsgHelper.ShowErrorModal(`登出失败:${result.Message}`); } }); } closeWaitProductionOrderListDrawer() { this.drawerType = 'base'; this.isShowWaitProductionOrderListDrawer = false; } private setWorkshopInfoDataset() { this.displayWorkshopDataset = [new DataDisplayDto('车间', 'OrganizationStructureName')]; } // 获取当前班次信息 getCurrentClassType(item: RhSelectItem) { this.currentClassType = item; } //#endregion ********** 员工信息相关 ********** // //#region ********** 切换tab ********** onBaseRadioChange(item: RhBasicRadioDto) { this.baseSelectedIndex = item.index; if (item.index === 2) { // this.getReportRecord(this.currentProductionWaitProcessOrder); } if (item.index === 3) { // this.showPdfTime = new Date(Date.now()); } } //#endregion ********** 切换tab ********** 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; if (this.rhCurrentWorkShop) { this.defaultQueryDto.OrganizationStructureCode = this.rhCurrentWorkShop.OrganizationStructureCode; } this.defaultQueryDto = { ...this.defaultQueryDto, ...this.collapseQueryDto }; } getValueChange() { this.defaultQueryDto.OrganizationStructureCode = this.rhCurrentWorkShop.OrganizationStructureCode; 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 ********** 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; } 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() { 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 = { ItemDataCollectionDtos: this.orderReportData.ReportEntryDtos as RhSafeAny[] }; } else { MsgHelper.ShowWarningMessage(`获取检验单明细数据失败!${result.Message}`); this.orderReportData = null; this.orderReportEntryDatas = null; } this.reportDataLoading = false; }, () => { this.reportDataLoading = false; } ); } private initResultDataDto(): RhBaseDto { const temp = ObjectHelper.createRhBaseDto(); temp['InspectorCode'] = this.storageSer.getUserSession()?.User?.UserName; temp['InspectorName'] = this.storageSer.getUserSession()?.User?.DisplayName; return temp; } selectWorkShop() { this.rhSelectWorkShop.emit(); } }