import { PlanDispatchObjectDto, ProductionDispatchOrderQueryDto, ProductionPlanDispatchDto, ProductionPlanOrderDto } from './../../ppm-model'; import { Component, OnInit, SimpleChanges, ViewChild } from '@angular/core'; import { CodeClassModel, DataResultT, OpResult, RhBaseDto, RhDynamicTableFieldDto, RhLoginedUserDto, RhSafeAny, RhSelectableDto, RhTableButtonInfoDto, RhTableQueryOptionDto, WithNil } from 'rh-base/model'; import { MsgHelper, ObjectHelper, RhStorageService } from 'rh-base/core'; import { DynamicFormComponent } from 'rh-base/shared'; import { RhProductionPerformService } from '../production-perform.service'; @Component({ selector: 'rh-production-plan-dispatch', templateUrl: './production-plan-dispatch.component.html', styleUrls: ['./production-plan-dispatch.component.less'] }) export class RhProductionPlanDispatchComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; selectedIndex = 0; editDto: RhBaseDto = {}; dataLoading = false; dataresult!: DataResultT; isShowEditModal = false; defaultFieldDataset: RhSafeAny = []; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'dispatch', '计划派工', 'default', false, 'edit', false, null, (data) => this.getDispatchDtos(data as ProductionPlanOrderDto), true ) ]; titleButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto('new', '新建', 'primary', 'file', false, null, () => this.openEditTab(), true) ]; // 所选的可派工计划 selectPlanData!: ProductionPlanOrderDto; dispatchDataresult!: DataResultT; dispatchLoading = false; selectDispatchOrder!: ProductionPlanDispatchDto; dispatchEditButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'dispatchOrder', '派工', 'default', false, 'edit', false, null, (data: RhSafeAny) => this.openDispatchModal(data), true ) ]; dispatchedOrders!: DataResultT; dispatchedOrderLoading = false; isShowDispatchModal = false; loginUser!: WithNil; /** 计划日期 */ startDate!: Date; endDate!: Date; rangeDate: Date[] = []; // currentDispatchNum = 0; constructor(private operator: RhProductionPerformService, private storage: RhStorageService) { // } ngOnInit() { this.selectDispatchOrder = this.initDispatchOrder(); this.loginUser = this.storage.getUserSession()?.User; } selectedIndexChange(index: number) { if (!index) { this.getDatas(); } } setDatas(dataset: DataResultT | OpResult) { this.dataresult = dataset as DataResultT; if (!this.dataresult?.Success) { MsgHelper.ShowWarningMessage(`搜索无数据!${this.dataresult?.Message}`); } } dataLoadingChange(status: boolean) { this.dataLoading = status; } setInitFieldDatset(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]; } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } //调用子组件中的接口 private getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } // 获取可派工对象 getDispatchDtos(dto: ProductionPlanOrderDto) { this.selectPlanData = dto; this.dispatchLoading = true; this.dispatchDataresult = { Attach: [], TotalCount: 0 } as DataResultT; this.operator.GetPlanDispatchObjectDatas(this.selectPlanData).subscribe( (result) => { if (result && result.Success) { this.openDispatchTab(); this.dispatchDataresult = result; this.currentDispatchNum = 0; this.dispatchDataresult.Attach.forEach((ele) => { this.currentDispatchNum += ele['AlreadyDispatchQty']; }); this.selectPlanData.ProductionDispatchQty = this.currentDispatchNum.toString(); this.selectPlanData = { ...this.selectPlanData }; } else { MsgHelper.ShowWarningModal(`${result.Message}`); } this.dispatchLoading = false; }, () => { this.dispatchLoading = false; } ); } openDispatchTab(data?: RhBaseDto) { // this.selectPlanData = data as ProductionPlanOrderDto; // 获取可派工对象 // this.getDispatchDtos(this.selectPlanData); // 获取已经被分派出来的派工单 this.getProductionDispatchOrderDatasBy(); this.selectedIndex = 1; } closeDispatchTab() { this.selectedIndex = 0; } getProductionDispatchOrderDatasBy() { this.dispatchedOrderLoading = true; const dto = ProductionDispatchOrderQueryDto.create(); dto.ProductionPlanCode = '$' + this.selectPlanData.ProductionPlanCode; this.operator.GetProductionDispatchOrderDatas(dto).subscribe( (result) => { if (result) { this.dispatchedOrders = result; if (!result.Success) { MsgHelper.ShowWarningMessage(`未获取到派工单数据:${result.Message}`); } } else { this.dispatchedOrders = { Attach: [], TotalCount: 0 } as DataResultT; } this.dispatchedOrderLoading = false; }, () => { this.dispatchedOrderLoading = false; } ); } // 派工 initDispatchOrder(): ProductionPlanDispatchDto { const dto = ProductionPlanDispatchDto.create(); return dto; } openDispatchModal(dto: RhBaseDto) { const order = dto as PlanDispatchObjectDto; ObjectHelper.MapT(order, this.selectDispatchOrder); this.selectDispatchOrder.ProductionPlanCode = this.selectPlanData.ProductionPlanCode; this.selectDispatchOrder.Dispatcher = this.loginUser?.UserName; this.isShowDispatchModal = true; } closeDispatchModal() { this.isShowDispatchModal = false; } setStartAndEndDate(dates: Date[]) { if (!dates || dates?.length < 2) { return; } this.startDate = new Date(dates[0]); this.endDate = new Date(dates[1]); // console.log(this.startDate, this.endDate); } dataHandler = (data: RhSafeAny) => { data.PlanStartTime = this.startDate; data.PlanEndTime = this.endDate; return true; }; dispatchPlanOrder(result: DataResultT | OpResult) { if (result && result.Success) { MsgHelper.ShowSuccessMessage(`派工成功!`); this.getProductionDispatchOrderDatasBy(); this.getDispatchDtos(this.selectPlanData); this.closeDispatchModal(); } else { MsgHelper.ShowWarningModal(`派工失败!${result.Message}`); } } }