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