import { DataResultT, RhLoginedUserDto, RhSafeAny, RhSelectableDto } from 'rh-base/model'; import { EquipmentCheckSheetDto, EquipmentCheckDifferenceDto, EquipmentLedgerDto, EquipmentCheckDifferenceQueryDto } from './../../../emp-model'; import { RhEquipmentInventoryService } from './../../equipment-inventory.service'; import { Component, OnInit, Input, Output, EventEmitter, SimpleChanges } from '@angular/core'; import * as _ from 'lodash'; import { DateHelper, FileHelper, MsgHelper, RhApiUrlsService, RhStorageService } from 'rh-base/core'; import { RhPortType, RhPortLocalFieldType } from 'rh-base/model'; @Component({ selector: 'rh-emp-inventory-differences-snippet', templateUrl: './emp-inventory-differences-snippet.component.html', styleUrls: ['./emp-inventory-differences-snippet.component.less'] }) export class EmpInventoryDifferencesSnippetComponent implements OnInit { dataLoading = false; dataresult!: DataResultT; ledgerResult!: DataResultT; checkResult!: DataResultT; ledgerDiffResult!: DataResultT; ledgerList: EquipmentLedgerDto[] = []; checkList: EquipmentCheckSheetDto[] = []; ledgerDiffList: EquipmentLedgerDto[] = []; exportLoading = false; reviewLoading = false; currentUser!: RhLoginedUserDto; @Input() rhEquipmentCheckPlanCode = ''; @Output() rhEmpCheckReviewSuccess = new EventEmitter(); constructor(private operator: RhEquipmentInventoryService, private apiUrls: RhApiUrlsService, private storageSer: RhStorageService) { // } ngOnInit(): void { this.currentUser = this.storageSer.getUserSession()?.User as RhLoginedUserDto; } ngOnChanges(changes: SimpleChanges): void { const { rhEquipmentCheckPlanCode } = changes; if (rhEquipmentCheckPlanCode) { if (rhEquipmentCheckPlanCode.currentValue) { this.getDatas(); } else { this.ledgerList = []; this.checkList = []; this.ledgerDiffList = []; this.ledgerResult = { Success: false, Attach: [], TotalCount: 0, Message: '', pureInputPara: void 0, SkipCount: 0 }; this.checkResult = { Success: false, Attach: [], TotalCount: 0, Message: '', pureInputPara: void 0, SkipCount: 0 }; this.ledgerDiffResult = { Success: false, Attach: [], TotalCount: 0, Message: '', pureInputPara: void 0, SkipCount: 0 }; } } } dataLoadingChange(status: boolean) { this.dataLoading = status; } setDatas(dataset: DataResultT) { this.dataresult = dataset; // 设备台账信息 const ledgertemp = _.cloneDeep(dataset); this.ledgerList = ledgertemp.Attach.EquipmentLedgerDtos || []; ledgertemp.Attach = this.ledgerList as RhSafeAny; ledgertemp.TotalCount = 0; // 设备盘点信息 const checktemp = _.cloneDeep(dataset); this.checkList = checktemp.Attach.EquipmentCheckSheetDtos || []; checktemp.Attach = this.checkList as RhSafeAny; checktemp.TotalCount = 0; // 未盘点设备信息 const ledgerdifftemp = _.cloneDeep(dataset); this.ledgerDiffList = ledgerdifftemp.Attach.EquipmentLedgerDifferenceDtos || []; ledgerdifftemp.Attach = this.ledgerDiffList as RhSafeAny; ledgerdifftemp.TotalCount = 0; this.ledgerResult = ledgertemp as RhSafeAny; this.checkResult = checktemp as RhSafeAny; this.ledgerDiffResult = ledgerdifftemp as RhSafeAny; } getDatas() { this.dataLoading = true; const dto = EquipmentCheckDifferenceQueryDto.create(); dto.EquipmentCheckPlanCode = this.rhEquipmentCheckPlanCode; this.operator.GetEquipmentCheckDifferences(dto).subscribe( (result) => { this.setDatas(result); this.dataLoading = false; }, () => { this.dataLoading = false; } ); } // 导出 exportEquipmentCheckSheetDatas() { const dto = EquipmentCheckDifferenceQueryDto.create(); dto.EquipmentCheckPlanCode = this.rhEquipmentCheckPlanCode; const url = this.apiUrls.GetApiOperateUrl( RhPortType.emp, 'EquipmentCheckApi', 'ExportEquipmentCheckSheetDatas', RhPortLocalFieldType.emp ); const fileName = '导出数据' + DateHelper.format(new Date(Date.now()), 'yyyyMMddHHmmss') + '.xlsx'; FileHelper.downloadFileViaPost(url, dto, fileName); this.exportLoading = true; setTimeout(() => { this.exportLoading = false; }, 1000); } audit() { if (this.dataresult.Attach) { this.reviewLoading = true; const empCheckDiff = _.cloneDeep(this.dataresult.Attach); empCheckDiff.AuditEmployeeCode = this.currentUser.UserName as string; empCheckDiff.AuditEmployeeName = this.currentUser.DisplayName as string; empCheckDiff.EquipmentCheckPlanCode = this.rhEquipmentCheckPlanCode; this.operator.EquipmentCheckReview(empCheckDiff).subscribe( (result) => { if (result.Success) { // MsgHelper.ShowSuccessModal(`计划${this.rhEquipmentCheckPlanCode}已开始审核,请在盘点审核中查看!`); MsgHelper.ShowConfirmModal( `计划${this.rhEquipmentCheckPlanCode}已开始审核,是否前往盘点审核中查看`, '', () => { this.rhEmpCheckReviewSuccess.emit(this.rhEquipmentCheckPlanCode); }, () => { this.rhEmpCheckReviewSuccess.emit(null); } ); } else { MsgHelper.ShowWarningMessage(`开始审核失败!${result.Message}`); } this.reviewLoading = false; }, () => { this.reviewLoading = false; } ); } else { MsgHelper.ShowWarningMessage('没有可以审核的数据!'); } } }