import { Component, OnInit, Output, Input } from "@angular/core";
import { EventEmitter } from "@angular/core";
import { UploadFile, NzMessageService} from 'ng-zorro-antd';


@Component({
  selector: "app-excel-import",
  templateUrl: "./excel-import.component.html",
  styleUrls: ["./excel-import.component.less"],
})
export class ExcelImportComponent implements OnInit {
  @Output() submitFormHand = new EventEmitter();
  @Output() hideFormHand = new EventEmitter();
  @Input() isShow: boolean = false; //模态框
  fileList: UploadFile[] = [];

  constructor(private message: NzMessageService) {}

  beforeUpload = (file: UploadFile): boolean => {
    if(this.fileList.length === 0){
      this.fileList = this.fileList.concat(file);
    }
    return false;
  };

  ngOnInit() {}
  // 隐藏模态框
  hideModal() {
    this.hideFormHand.emit();
  }
  // 表单提交
  submitForm(): void {
    if(this.fileList.length === 0){
      this.message.warning('请选择一个文件');
      return;
    }
    this.submitFormHand.emit({fileList: this.fileList});
  }
}
