import { MsgHelper, ObjectHelper } from 'rh-base/core'; import { RhMouldDocumentService } from './../../../mould-document.service'; import { Component, Input, OnInit } from '@angular/core'; import { DataResultT, OpMode, RhBaseDto, RhSafeAny, RhSelectItem, RhTableButtonInfoDto } from 'rh-base/model'; import { MouldDocumentDto, MouldDocumentQueryDto, MouldBindingMaterialRecordQueryDto, MouldBindingMaterialRecordDto } from './../../../../mdp-model'; @Component({ selector: 'rh-bind-material', templateUrl: './bind-material.component.html', styleUrls: ['./bind-material.component.less'] }) export class BindMaterialComponent implements OnInit { /** 传入模具信息 */ @Input() rhData!: MouldDocumentDto; BindMaterialDataresult = { Attach: [] as MouldBindingMaterialRecordDto[] } as DataResultT; defaultFieldDataset = []; // dataLoading = false; selectedIndex = 0; addDto: RhBaseDto = {}; // isShowVersionDatas = false; MouldVersionDatas: RhSelectItem[] = []; Versionloading = false; selectedMouldVersionEdit = false; bindTableLoading = false; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('new', '新建关联', 'primary', false, 'file', false, null, () => this.openEditTab(), true), new RhTableButtonInfoDto('refresh', '刷新数据', 'default', false, 'sync', false, null, () => this.refreshDatas(), true) // new RhTableButtonInfoDto('delete', '删除', 'danger', 'delete', false, null, (datas) => this.removeRecords(datas as RhBaseDto[])) ]; // extraButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto('enableButton', '启用', 'primary', 'file', false, null, (datas) => this.removeRecords(datas as RhBaseDto[])), // new RhTableButtonInfoDto('disabledButton', '禁用', 'danger', 'delete', false, null, (datas) => this.removeRecords(datas as RhBaseDto[])) // ]; bindDataHandler = (data: MouldDocumentDto) => { data.MouldCode = this.rhData.MouldCode; data.MouldName = this.rhData.MouldName; data.MouldErpCode = this.rhData.MouldErpCode; data.MouldErpName = this.rhData.MouldErpName; data.MouldCategory = this.rhData.MouldCategory; data.MouldName = this.rhData.MouldName; data.MouldVersionCode = this.rhData.currentMouldVersion; return true; }; constructor(private operator: RhMouldDocumentService) { // } ngOnInit(): void { this.getVersionDatas(); } // setDatas(dataset: DataResultT) { // this.BindMaterialDataresult = dataset; // } refreshDatas() { this.getBindedMaterialRecordDatas(this.rhData.currentMouldVersion as string); } openEditTab(data?: RhBaseDto) { if (data) { this.addDto = data; this.addDto.OpSign = OpMode.OpEdit; } else { this.addDto = {}; this.addDto.OpSign = OpMode.OpAdd; } this.selectedIndex = 1; } closeEditTab() { this.selectedIndex = 0; } enableEdit($event: Event) { if ($event) { $event.preventDefault(); $event.stopImmediatePropagation(); } this.selectedMouldVersionEdit = true; } onStoreDatas(result: DataResultT) { if (result && result.Success) { const msg = this.addDto.OpSign === OpMode.OpAdd ? '新增' : '编辑'; MsgHelper.ShowSuccessMessage(`${msg}数据成功`); if (this.addDto.OpSign === OpMode.OpEdit) { this.selectedIndex = 0; } this.addDto = ObjectHelper.createRhBaseDto(); this.getBindedMaterialRecordDatas(this.rhData.currentMouldVersion as string); } else { MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); } } // //选择 版本号 // openVersionDatasModal() { // this.isShowVersionDatas = true; // } // closeVersionModal() { // this.isShowVersionDatas = false; // } getVersionDatas() { this.Versionloading = true; const queryDto = MouldDocumentQueryDto.create(); queryDto.MouldCode = this.rhData.MouldCode; queryDto.MouldName = this.rhData.MouldName; this.operator.GetMouldVersionDatas(queryDto).subscribe( (result) => { if (result && result.Success) { this.MouldVersionDatas = result.Attach.map((ele) => { return new RhSelectItem(ele, ele); }); this.rhData.currentMouldVersion = result.Attach[0]; this.getBindedMaterialRecordDatas(this.rhData.currentMouldVersion); } else { this.MouldVersionDatas = []; } this.Versionloading = false; }, () => (this.Versionloading = false) ); } getBindedMaterialRecordDatas(version: string) { if (!version) { MsgHelper.ShowWarningMessage(`当前版本号为空,请检查后重试!`); return; } // this.selectedMouldVersionEdit = false; const queryDto = MouldBindingMaterialRecordQueryDto.create(); queryDto.MouldCode = this.rhData.MouldCode; queryDto.MouldVersionCode = version; queryDto.Mode = 8; this.bindTableLoading = true; this.operator.GetMouldBindingMaterialRecordDatas(queryDto).subscribe( (result) => { if (result && result.Success) { this.BindMaterialDataresult.Attach = result.Attach; MsgHelper.ShowSuccessMessage('获取绑定物料信息成功!'); } else { this.BindMaterialDataresult.Attach = []; MsgHelper.ShowWarningMessage(`暂无数据${result.Message}`); } this.BindMaterialDataresult = { ...this.BindMaterialDataresult }; this.bindTableLoading = false; // this.dataLoading = false; }, () => (this.bindTableLoading = false) ); } onSelect(version: string) { // this. } // removeRecords(datas: RhBaseDto[]) { // MsgHelper.ShowConfirmModal('是否删除', '删除后数据无法回复', () => { // }) // } // disabledRecords(datas: RhBaseDto[]) { // // // } // enableRecords(datas: RhBaseDto[]) { // // // } }