import { Component } from '@angular/core';
import { CommonNzModule } from '../../../../common.nz.module';
import { Column, SimpleFormPageComponent } from '../../../../shared/simple-form-page/simple-form-page.component';

@Component({
  selector: 'app-consequence',
  standalone: true,
  imports: [SimpleFormPageComponent, CommonNzModule],
  templateUrl: '../../../../shared/simple-form-page/simple-form-page.component.html',
  styleUrl: './consequence.component.less',
})
export class ConsequenceComponent extends SimpleFormPageComponent<BasicData.Predefine> {
  override showSearchForm = false;
  override editable = false;
  override keyWord: string = '后果';
  override key: string = 'value';
  override columns: Column[] = [
    { key: 'seq', label: '序号' },
    { key: 'value', label: '可能引发的后果' },
  ];
  override inputFields = [{ label: '可能引发的后果', key: 'value', initValue: '' }];
  override async fetchList() {
    const list = await this.api.basic.getPredefineList('consequence');
    this.list = list;
  }
  override async onAdd(data: BasicData.Predefine) {
    return this.api.basic
      .addPredefine({
        ...data,
        type: 'consequence',
      })
      .then(() => {
        this.message.success('添加成功');
      });
  }
  override async onDelete(data: BasicData.Predefine) {
    return this.api.basic.deletePredefine('consequence', data.value).then(() => {
      this.message.success('删除成功');
    });
  }
}
