import { Component, OnInit, ViewChild } from '@angular/core'; import { DataResultT, RhBaseDto, RhTableButtonInfoDto, CodeClassModel, RhDynamicTableFieldDto, OpMode, RhTableQueryOptionDto, RhSafeAny, RhSelectItem, RhDynamicComponentFieldType } from 'rh-base/model'; import { NzModalService } from 'ng-zorro-antd/modal'; import { ExtProductInfo, ExtProductQueryDto, ProductDocumentDto } from '../../mdp-model'; import { RhProductDefineService } from '../product-define.service'; import { MsgHelper, RhNavigatorService } from 'rh-base/core'; import { DynamicFormComponent } from 'rh-base/shared'; // 产品档案 @Component({ selector: 'rh-product-document-manage', templateUrl: './product-document-manage.component.html', styleUrls: ['./product-document-manage.component.less'] }) export class RhProductDocumentManageComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; selectedIndex = 0; dataresult!: DataResultT; defaultFieldDataset: RhDynamicComponentFieldType[] = []; dataLoading = false; editDto: RhBaseDto = {}; editButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('edit', '编辑', 'default', false, 'edit', false, null, (data) => this.openEditTab(data as RhBaseDto), true) // new RhTableButtonInfoDto('readBom', '查看Bom', 'default', 'eye', false, null, (data) => this.gotoBomDetailPage(data), true) ]; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('new', '新建', 'primary', false, 'file', false, null, () => this.openEditTab(), true), new RhTableButtonInfoDto( 'delete', '删除', 'primary', true, 'delete', false, null, (data) => this.deleteDatas(data as ProductDocumentDto[]), false, true ) ]; extraButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('sync', '同步', 'primary', false, 'sync', false, null, () => this.openSyncModal(), true) ]; // 辅助 isAddTab = false; isEditTab = false; isShowEditBModal = false; // 同步产品信息 syncProductList: ExtProductInfo[] = []; selectedSyncProducts: ProductDocumentDto[] = []; isShowSyncModal = false; extDataLoading = false; // 管道数据源 measureUnits: RhSelectItem[] = []; constructor(public operator: RhProductDefineService, private modal: NzModalService, private navigator: RhNavigatorService) {} ngOnInit(): void { // this.getMeasureUnitSelectItems(); } setDatas(dataset: DataResultT) { this.dataresult = dataset; if (this.editDto && this.editDto.OpSign === OpMode.OpEdit) { if (this.dataresult.Success && this.dataresult.Attach && this.dataresult.Attach.length) { this.editDto = this.dataresult.Attach.find((f) => f['ProductCode'] === this.editDto['ProductCode']) as RhBaseDto; } } } setInitFieldDataset(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]; } dataLoadingChange(status: boolean) { this.dataLoading = status; } openEditTab(data?: RhBaseDto) { if (data) { this.editDto = data; this.editDto.OpSign = OpMode.OpEdit; this.isAddTab = false; this.isEditTab = true; } else { this.editDto = {}; this.editDto.OpSign = OpMode.OpAdd; this.isAddTab = true; this.isEditTab = false; } this.selectedIndex = 1; } closeAddTab() { this.isAddTab = false; this.selectedIndex = 0; } closeEditTab() { this.isEditTab = false; this.selectedIndex = 0; } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } private getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } onStoreDatas(result: DataResultT) { if (result && result.Success) { const msg = this.editDto.OpSign === OpMode.OpAdd ? '新增' : '编辑'; MsgHelper.ShowSuccessMessage(`${msg}数据成功`); this.selectedIndex = 0; this.getDatas(); } else { MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); } } deleteDatas(selectDatas: ProductDocumentDto[]) { MsgHelper.ShowDeleteConfirm('删除后数据无法恢复,是否确定?', () => { this.modal.confirm({ nzTitle: '警告!', nzContent: '若删除此项,将会同时删除BOM信息,该操作不可逆,是否确认?', nzOnOk: () => { this.operator.RemoveProductDocumentDatas(selectDatas).subscribe((result) => { if (result.Success) { this.getDatas(); MsgHelper.ShowSuccessMessage('删除成功!'); } else { MsgHelper.ShowWarningMessage(`删除失败!${result.Message}`); } }); }, nzOkType: 'primary', nzOkDanger: true, nzIconType: 'warning' }); }); } // gotoBomDetailPage(data: RhBaseDto) { // this.navigator.navigatorTrigger('RH_ProductManufactureBomManage', { // ProductCode: data.ProductCode, // Time: new Date().getTime() // // ProductName: data.ProductName, // // ProductSpecification: data.ProductSpecification, // // IsSemiFinishedProduct: data.IsSemiFinishedProduct // }); // } openEditBModal() { MsgHelper.ShowConfirmModal('是否确定编辑', '修改会同步更新BOM信息', () => { this.isShowEditBModal = true; }); } closeEditBModal() { this.isShowEditBModal = false; } onStoreBDatas(result: DataResultT) { if (result && result.Success) { MsgHelper.ShowSuccessMessage('更新产品档案及其BOM信息成功!'); this.closeEditBModal(); this.getDatas(); } else { MsgHelper.ShowWarningMessage(`更新产品档案及其BOM信息失败!${result.Message}`); } } // ************ 同步产品信息 ************** openSyncModal() { this.loadProductFromOtherSystems(); this.isShowSyncModal = true; } closeSyncModal() { this.syncProductList.forEach((ele) => (ele.select = false)); this.isShowSyncModal = false; } // 载入产品信息 loadProductFromOtherSystems() { const queryDto = ExtProductQueryDto.create(); queryDto.Mode = 8; this.extDataLoading = true; this.operator.GetExtProductInfo(queryDto).subscribe( (result) => { if (result && result.Success) { this.syncProductList = result.Attach; } else { this.syncProductList = []; MsgHelper.ShowWarningModal(`获取第三方用户数据失败!${result.Message}`); } this.extDataLoading = false; }, () => (this.extDataLoading = false) ); } // 获取所选产品信息 getSelectedDataset(dtos: ProductDocumentDto[]) { this.selectedSyncProducts = dtos; } // 保存所选产品信息 saveProducts() { this.operator.StoreProductDocumentDatas(this.selectedSyncProducts).subscribe((result) => { if (result && result.Success) { MsgHelper.ShowSuccessMessage(`保存成功!`); this.syncProductList = []; this.getDatas(); this.closeSyncModal(); } else { MsgHelper.ShowWarningModal(`保存失败!${result.Message}`); } }); } // 获取单位信息 // getMeasureUnitSelectItems() { // this.operator.GetMeasureUnitSelectItems().subscribe((result) => { // if (result.Success) { // this.measureUnits = result.Attach; // } // }); // } }