import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { MainService } from '../../services/main.service';
import { ToolService } from 'src/app/services/tool.service';

@Component({
  selector: 'app-medical-waste-log-prompt-modal',
  templateUrl: './medical-waste-log-prompt-modal.component.html',
  styleUrls: ['./medical-waste-log-prompt-modal.component.less']
})
export class MedicalWasteLogPromptModalComponent implements OnInit {
  hosId;
  // 切换科室，切换弹窗
  hsLoading = false;
  historySpecimenList: any = [];
  historySpecimenPageIndex: number = 1;//表格当前页码
  historySpecimenPageSize: number = 9999;//表格每页展示条数
  historySpecimenListLength: number = 10;//表格总数据量
  @Input() show: Boolean;
  @Input() id: String;

  @Output() closeModelHs = new EventEmitter<any>();//1.组件暴露一个 EventEmitter 属性，当事件发生时，子组件利用该属性 emits(向上弹射)事件

  constructor(
    private mainService: MainService,
    private tool: ToolService
  ) { }

  ngOnInit() {
    this.hosId = this.tool.getCurrentHospital().id;
    this.getList();
  }
  // 关闭弹窗
  hideModal() {
    this.closeModelHs.emit(JSON.stringify({ show: false }));//emits(向上弹射)事件
  }
  // 获取列表数据
  getList(idx?) {
    if (idx) {
      this.historySpecimenPageIndex = 1;
    }
    let postData = {
      idx: this.historySpecimenPageIndex - 1,
      sum: this.historySpecimenPageSize,
      clinicalWasteLog: {
        clinicalWasteId: this.id,
        hosId: this.hosId,
      }
    }
    this.hsLoading = true;
    this.mainService.getFetchDataList('simple/data','clinicalWasteLog',postData).subscribe(data => {
      this.hsLoading = false;
      this.historySpecimenList = data.list || [];
      this.historySpecimenListLength = data.totalNum || 0;
    })
  }
}


