import { ClassShiftDto, FactoryCalendarEntryDto, FactoryCalendarSchemaDto, FactoryCalendarEntryQueryDto } from './../../../mdp-model'; import { Component, EventEmitter, Input, OnInit, Output, SimpleChanges, ChangeDetectorRef } from '@angular/core'; import { RhFactoryCalendarService } from '../../factory-calendar.service'; import * as _ from 'lodash'; import { DataResultT, RhSafeAny, RhSelectableDto, RhTableButtonInfoDto } from 'rh-base/model'; import { MsgHelper } from 'rh-base/core'; interface Month { month: number; select: boolean; } @Component({ selector: 'rh-calendar-entry-datas-table', templateUrl: './calendar-entry-datas-table.component.html', styleUrls: ['./calendar-entry-datas-table.component.less'] }) export class CalendarEntryDatasTableComponent implements OnInit { @Input() rhSelectCalendarData!: FactoryCalendarSchemaDto; // 选择的日历数据 @Input() rhWorkYear = 2021; @Input() rhWorkMonths: Month[] = []; @Input() rhRenderEntryDatas: FactoryCalendarEntryDto[] = []; @Output() rhRefreshDatas = new EventEmitter(); dataLoading = false; calendarResult!: DataResultT; dataresult!: DataResultT; editButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto('node-index', '关联班制', 'default', 'node-index', false, null, (data) => // this.openClassShiftSelectModal(data as RhBaseDto) // ) ]; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('node-index', '关联班制', 'default', false, 'node-index', false, null, () => this.openClassShiftSelectModal()) ]; // 选中的日期数据 selecedDatas: RhSelectableDto[] = []; selectDto: FactoryCalendarEntryDto[] = []; isShowClassShiftSelectModal = false; selectClassShiftDto: ClassShiftDto | null = null; constructor(private operator: RhFactoryCalendarService, private cdr: ChangeDetectorRef) { // } ngOnInit(): void { // // this.calendarResult = this.initCalendarResult(); } ngOnChanges(changes: SimpleChanges): void { const { rhWorkMonths, rhRenderEntryDatas } = changes; if (rhRenderEntryDatas) { this.getDatas(); } else if (rhWorkMonths) { this.filterEntryDatasBySelectedMonths(_.cloneDeep(this.calendarResult), this.rhWorkMonths); } } initCalendarResult(): DataResultT { const dataResult = new DataResultT('', false, [], 0); return dataResult; } initQueryDto() { const dto = FactoryCalendarEntryQueryDto.create(); dto.Mode = 8; dto.FactoryCode = this.rhSelectCalendarData.FactoryCode; dto.FactoryCalendarCode = this.rhSelectCalendarData.FactoryCalendarCode; dto.WorkYear = this.rhWorkYear; return dto; } getDatas() { this.calendarResult = this.initCalendarResult(); this.dataLoading = true; if (this.rhRenderEntryDatas.length > 0) { this.calendarResult.Attach = []; this.calendarResult.Success = true; this.calendarResult.Attach = [...this.rhRenderEntryDatas]; this.calendarResult.TotalCount = this.rhRenderEntryDatas.length; } this.calendarResult = { ...this.calendarResult }; this.filterEntryDatasBySelectedMonths(_.cloneDeep(this.calendarResult), this.rhWorkMonths); this.dataLoading = false; } // 按月筛选明细数据 filterEntryDatasBySelectedMonths(result: DataResultT, months: Month[]) { let editEntryDatas: RhSafeAny[] = []; const dataSource = [...result.Attach]; months.forEach((ele) => { const datas = dataSource.filter((data) => data['WorkYear'] === this.rhWorkYear && data['WorkMonth'] === ele.month); // editEntryDatas = editEntryDatas.concat(datas.reverse()); editEntryDatas = editEntryDatas.concat(datas); }); result.Attach = [...editEntryDatas]; result.TotalCount = editEntryDatas.length; result.Record = editEntryDatas.length; this.dataresult = result; this.cdr.markForCheck(); } //#region ********** 关联班制 ********** selectedDatasChange(dtos: RhSelectableDto[]) { if (dtos) { this.selectDto = []; this.selecedDatas = dtos; this.selecedDatas.forEach((ele) => { this.selectDto.push(ele as FactoryCalendarEntryDto); }); } } openClassShiftSelectModal() { // this.selectDto.push(dto as FactoryCalendarEntryDto); // 当前选中的日历数据 // this.selectClassShiftDto = ClassShiftDto.create(); this.isShowClassShiftSelectModal = true; } closeClassShiftSelectModal() { this.isShowClassShiftSelectModal = false; this.selectDto = []; } refreshSelectClassShift(datas: ClassShiftDto[] | ClassShiftDto) { if (Array.isArray(datas)) { this.selectClassShiftDto = datas[0]; } else { this.selectClassShiftDto = datas ? datas : null; } } relateClassShift() { if (this.selectClassShiftDto) { // console.log(this.selectClassShiftDto); // this.selectDto[0].ClassShiftCode = this.selectClassShiftDto.ClassShiftCode; this.selectDto.forEach((ele) => { ele.ClassShiftCode = this.selectClassShiftDto?.ClassShiftCode; }); this.operator.StoreFactoryCalendarEntryDatas(this.selectDto).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage('班制关联成功!'); // this.getDatas(); this.rhRefreshDatas.emit(); this.closeClassShiftSelectModal(); this.selectDto = []; } else { MsgHelper.ShowErrorMessage(`班制关联失败!${result.Message}`); } }); } } //#endregion 关联班制 // }