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-department',
  standalone: true,
  imports: [SimpleFormPageComponent, CommonNzModule],
  templateUrl: '../../../../shared/simple-form-page/simple-form-page.component.html',
  styleUrl: './department.component.less',
})
export class DepartmentComponent 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('department');
    this.list = list;
  }
  override async onAdd(data: BasicData.Predefine) {
    return this.api.basic
      .addPredefine({
        ...data,
        type: 'department',
      })
      .then(() => {
        this.message.success('添加成功');
      });
  }
  override async onDelete(data: BasicData.Predefine) {
    return this.api.basic.deletePredefine('department', data.value).then(() => {
      this.message.success('删除成功');
    });
  }
}
