|
@@ -0,0 +1,128 @@
|
|
|
+import { Component } from '@angular/core';
|
|
|
+import { CommonNzModule } from '../../../../common.nz.module';
|
|
|
+import { Column, SimpleFormPageComponent } from '../../../../shared/simple-form-page/simple-form-page.component';
|
|
|
+import { EquipmentFormComponent, EquipmentFormModalData } from './form/form.component';
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-equipment',
|
|
|
+ standalone: true,
|
|
|
+ imports: [CommonNzModule],
|
|
|
+ templateUrl: './equipment.component.html',
|
|
|
+ styleUrl: './equipment.component.less',
|
|
|
+})
|
|
|
+export class EquipmentComponent extends SimpleFormPageComponent<BasicData.Equipment> {
|
|
|
+ filterList: BasicData.Equipment[] = [];
|
|
|
+ override keyWord: string = '设备';
|
|
|
+ override key: string = 'name';
|
|
|
+ override columns: Column[] = [
|
|
|
+ {
|
|
|
+ key: 'id',
|
|
|
+ label: '编号',
|
|
|
+ // sortOrder: 'ascend',
|
|
|
+ // sortable: true,
|
|
|
+ width: '80px',
|
|
|
+ },
|
|
|
+ { key: 'name', label: '设备名称' },
|
|
|
+ { key: 'unit', label: '生产单元' },
|
|
|
+ { key: 'line', label: '线路' },
|
|
|
+ ];
|
|
|
+ override inputFields = [{ label: '设备名称', key: 'equipment', initValue: '' }];
|
|
|
+ override validateForm = this.fb.group({
|
|
|
+ equipment: this.fb.control<string | undefined>(undefined),
|
|
|
+ line: this.fb.control<string | undefined>(undefined),
|
|
|
+ unit: this.fb.control<string | undefined>(undefined),
|
|
|
+ });
|
|
|
+ override ngOnInit(): void {
|
|
|
+ super.ngOnInit();
|
|
|
+ }
|
|
|
+ override async fetchList() {
|
|
|
+ const list = (await this.api.basic.getEquipmentList()).filter(item =>
|
|
|
+ this.lines.map(l => l.value).includes(item.line)
|
|
|
+ );
|
|
|
+ this.list = list;
|
|
|
+ this.resetFilterList();
|
|
|
+ }
|
|
|
+ override async onEdit(data: Partial<BasicData.Equipment>) {
|
|
|
+ return this.api.basic.updateEquipment(data).then(() => {
|
|
|
+ this.message.success('编辑成功');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ override async onAdd(data: Partial<BasicData.Equipment>) {
|
|
|
+ return this.api.basic.addEquipment(data).then(() => {
|
|
|
+ this.message.success('新增成功');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ override async onDelete(data: BasicData.Equipment): Promise<void> {
|
|
|
+ return this.api.basic.deletedEquipment(data.id).then(() => {
|
|
|
+ this.message.success('删除成功');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ override createModal(type: 'add' | 'edit', data?: BasicData.Equipment): void {
|
|
|
+ const name = data ? this.getValue(data, this.key) : '';
|
|
|
+ this.modal.create<EquipmentFormComponent, EquipmentFormModalData>({
|
|
|
+ nzClassName: 'precaution-modal',
|
|
|
+ nzTitle: type === 'add' ? '新增' + this.keyWord : '编辑' + this.keyWord + ' - ' + name,
|
|
|
+ nzOkText: type === 'add' ? '新增' : '修改',
|
|
|
+ nzContent: EquipmentFormComponent,
|
|
|
+ nzWidth: 500,
|
|
|
+ nzViewContainerRef: this.viewContainerRef,
|
|
|
+ nzData: {
|
|
|
+ keyWord: this.keyWord,
|
|
|
+ type,
|
|
|
+ params: {
|
|
|
+ name,
|
|
|
+ id: data ? this.getValue(data, 'id') : undefined,
|
|
|
+ line: data ? this.getValue(data, 'line') : undefined,
|
|
|
+ unit: data ? this.getValue(data, 'unit') : undefined,
|
|
|
+ },
|
|
|
+ lines: this.lines,
|
|
|
+ },
|
|
|
+ nzOnOk: async instance => {
|
|
|
+ const res = await instance.submit();
|
|
|
+ if (type === 'add') {
|
|
|
+ await this.onAdd(res!);
|
|
|
+ this.fetchList();
|
|
|
+ } else {
|
|
|
+ await this.onEdit({
|
|
|
+ ...data!,
|
|
|
+ ...res!,
|
|
|
+ });
|
|
|
+ this.onSearch();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ searchFormChange(key: string) {
|
|
|
+ if (key === 'line') {
|
|
|
+ this.validateForm.get('unit')?.reset();
|
|
|
+ }
|
|
|
+ this.resetFilterList();
|
|
|
+ }
|
|
|
+ resetFilterList() {
|
|
|
+ const { equipment, line, unit } = this.validateForm.value;
|
|
|
+ this.filterList = this.list.filter(item => {
|
|
|
+ let isMatch = true;
|
|
|
+ if (equipment) {
|
|
|
+ isMatch = item.name.includes(equipment);
|
|
|
+ }
|
|
|
+ if (isMatch && line) {
|
|
|
+ isMatch = item.line === line;
|
|
|
+ }
|
|
|
+ if (isMatch && unit) {
|
|
|
+ isMatch = item.unit === unit;
|
|
|
+ }
|
|
|
+ return isMatch;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ get lines() {
|
|
|
+ return this.basic.lines || [];
|
|
|
+ }
|
|
|
+ get types() {
|
|
|
+ return this.basic.types || [];
|
|
|
+ }
|
|
|
+ get units() {
|
|
|
+ const line = this.validateForm.value.line;
|
|
|
+ if (!line) return [];
|
|
|
+ return this.basic.units?.filter(item => item.line === line) || [];
|
|
|
+ }
|
|
|
+}
|