import { NzTreeNode } from 'ng-zorro-antd/tree'; import { MsgHelper } from 'rh-base/core'; import { Component, OnInit, ViewChild } from '@angular/core'; import { DataResultT, RhSelectableDto, CodeClassModel, RhDynamicTableFieldDto, RhTableQueryOptionDto, RhSafeAny, RhTableButtonInfoDto, RhDynamicComponentFieldType } from 'rh-base/model'; // import { ObjectHelper } from 'rh-base/core'; import { DynamicFormComponent } from 'rh-base/shared'; import { RhTrackManagementService } from '../track-management.service'; import { ProductMaterialBindedMetadataDto, MaterialDocumentDto, ProductMaterialBindedMetadataQueryDto } from '../../qmp-model'; @Component({ selector: 'rh-product-material-binded-management', templateUrl: './product-material-binded-management.component.html', styleUrls: ['./product-material-binded-management.component.css'] }) export class RhProductMaterialBindedManagementComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; @ViewChild('EquipmentLedgeQueryForm', { static: false }) EquipmentLedgeQueryForm!: DynamicFormComponent; selectedIndex = 0; // editDto: RhBaseDto = {}; dataLoading = false; dataresult!: DataResultT; isShowEditModal = false; defaultFieldDataset: RhDynamicComponentFieldType[] = []; boundDataLoading = false; defaultQueryDto: RhSafeAny = {}; editButtonDataset = [ new RhTableButtonInfoDto( 'edit', '编辑', 'default', false, 'form', false, null, (data) => this.openEditTab(data as ProductMaterialBindedMetadataDto), false ), new RhTableButtonInfoDto( 'unbound', '解除绑定', 'primary', true, 'disconnect', false, null, (data) => this.unboundDatas([data as ProductMaterialBindedMetadataDto]), false, true, 'red' ) ]; detailDataLoading = false; detailDataresult = { Attach: [] } as unknown as DataResultT; //树内选中的产品 selectedProduct: RhSafeAny; bindDataset: ProductMaterialBindedMetadataDto[] = []; /** 暂存选中的产品信息对象 */ selectedProudctData!: MaterialDocumentDto; selectedBindData: ProductMaterialBindedMetadataDto | null = null; tabType: 'edit' | 'bind' = 'edit'; constructor(private operator: RhTrackManagementService) { // } ngOnInit(): void { // } detailDataLoadingChange(status: boolean) { this.detailDataLoading = status; } detailSetDatas(dataset: DataResultT) { this.detailDataresult = dataset; } closeBindTab() { this.selectedIndex = 0; this.resetTabType(); // this.isShowDetail = false; this.getDatas(); } //#region ********** 绑定方案 ********** openBindTab() { this.getBindDataset(this.selectedProduct.MaterialCode) .then((datas) => { this.bindDataset = datas; // this.tabType = 'bind'; this.selectedIndex = 1; this.tabType = 'bind'; }) .catch(() => { this.bindDataset = []; }); } openEditTab(data: ProductMaterialBindedMetadataDto) { this.selectedBindData = data; this.selectedIndex = 1; this.tabType = 'edit'; } closeEditTab() { this.closeBindTab(); } onSelectedChange(index: number) { if (index === 0) { this.closeBindTab(); } } setDatas(dataset: DataResultT) { this.dataresult = dataset; if (!this.dataresult?.Success) { MsgHelper.ShowWarningMessage(`搜索无数据!${this.dataresult?.Message}`); } } dataLoadingChange(status: boolean) { this.dataLoading = status; } 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); } refreshData(option: RhTableQueryOptionDto) { this.getDatas(option); } //#region ********** 物料检验方案查询相关(主界面) ********** // onSelectProduct(item: RhSafeAny) { // if (item) { // this.selectedProduct = item; // this.getDatas(); // } // } onSelectProduct(node: NzTreeNode) { if (node && node.origin['customData']) { const data = node.origin['customData']; if (node.level === 1 && node.isSelected) { this.selectedProduct = data; this.getDatas(); } } else { this.selectedProduct = null; } } onStoreEditData(result: DataResultT) { if (result && result.Success) { MsgHelper.ShowSuccessMessage('更新数据成功!'); this.selectedBindData = null; this.closeEditTab(); } else { MsgHelper.ShowWarningModal(`更新数据失败!${result.Message}`); } } unboundDatas(datas: ProductMaterialBindedMetadataDto[]) { MsgHelper.ShowConfirmModal('是否解除绑定?', '解除绑定后数据无法恢复,是否继续?', () => { MsgHelper.ShowGlobalLoadingMessage(`正在解除绑定,请稍候...`); this.operator.RemoveProductMaterialBindedMetadataDatas(datas).subscribe((result) => { MsgHelper.CloseGlobalLoadingMessage(); if (result?.Success) { MsgHelper.ShowSuccessMessage(`解除绑定成功!`); this.getDatas(); } else { MsgHelper.ShowWarningModal(`解除绑定失败!${result.Message}`); } }); }); } //调用子组件中的接口 private getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { const queryDto: RhSafeAny = {}; if (this.selectedProduct?.MaterialCode) { queryDto.ProductCode = this.selectedProduct.MaterialCode; queryDto.ProductName = this.selectedProduct.MaterialName; } this.defaultQueryDto = queryDto; setTimeout(() => { this.queryFormCmt.submitDefaultForm(null, option); }); } } /** 根据产品编号获取绑定的物料列表 */ private getBindDataset(productCode: string): Promise { const queryDto = ProductMaterialBindedMetadataQueryDto.create(); queryDto.ProductCode = productCode; queryDto.Mode = 8; let temp: ProductMaterialBindedMetadataDto[]; return new Promise((resolve, reject) => { this.operator.GetProductMaterialBindedMetadataDatas(queryDto).subscribe( (result) => { if (result?.Success) { temp = result?.Attach || []; } else { MsgHelper.ShowWarningMessage(`获取物料绑定源数据失败!${result.Message}`); temp = []; } resolve(temp); }, () => { temp = []; reject(temp); } ); }); } private resetTabType() { this.tabType = 'edit'; } }