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-inspect-log-prompt-modal",
  templateUrl: "./inspect-log-prompt-modal.component.html",
  styleUrls: ["./inspect-log-prompt-modal.component.less"],
})
export class InspectLogPromptModalComponent implements OnInit {
  hosId;
  // 切换科室，切换弹窗
  hsLoading = false;
  historySpecimenList: any = [];
  historySpecimenPageIndex: number = 1; //表格当前页码
  historySpecimenPageSize: number = 5; //表格每页展示条数
  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.getHistorySpecimen();
  }
  // 关闭弹窗
  hideModal() {
    this.closeModelHs.emit(JSON.stringify({ show: false })); //emits(向上弹射)事件
  }
  // 获取列表数据
  getHistorySpecimen(idx?) {
    if (idx) {
      this.historySpecimenPageIndex = 1;
    }
    let postData = {
      idx: this.historySpecimenPageIndex - 1,
      sum: this.historySpecimenPageSize,
      inspectLog: {
        hosId: this.hosId,
        inspectId: this.id,
      },
    };
    this.hsLoading = true;
    this.mainService
      .getFetchDataList("simple/data", "inspectLog", postData)
      .subscribe((data) => {
        this.hsLoading = false;
        this.historySpecimenList = data.list || [];
        this.historySpecimenListLength = data.totalNum || 0;
      });
  }
}
