import { Component, OnInit, OnDestroy, ViewChild } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { MainService } from "../../services/main.service";
import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
import { NzMessageService } from "ng-zorro-antd";
import { ToolService } from 'src/app/services/tool.service';
@Component({
  selector: "app-outgoing-record-detail",
  templateUrl: "./outgoing-record-detail.component.html",
  styleUrls: ["./outgoing-record-detail.component.less"],
})
export class OutgoingRecordDetailComponent implements OnInit {
  @ViewChild("osComponentRef1", {
    read: OverlayScrollbarsComponent,
    static: false,
  })
  osComponentRef1: OverlayScrollbarsComponent;
  @ViewChild("osComponentRef2", {
    read: OverlayScrollbarsComponent,
    static: false,
  })
  osComponentRef2: OverlayScrollbarsComponent;
  constructor(
    private message: NzMessageService,
    private route: ActivatedRoute,
    private mainService: MainService,
    private tool: ToolService,
  ) {}
  maskFlag: any = false;
  id: number; //工单id
  orderInfo: any; //工单详情信息
  hosId;

  ngOnInit() {
    this.hosId = this.tool.getCurrentHospital().id;
    this.tabType = this.route.snapshot.params.type || 1;
    this.getInfo();
  }

  // 获取工单详情
  hsLoading:boolean = false;
  getInfo() {
    this.id = +this.route.snapshot.paramMap.get("id");
    this.maskFlag = this.message.loading("正在加载中..", {
      nzDuration: 0,
    }).messageId;
    this.mainService
      .getFetchData("simple/data", "clinicalWasteOut", this.id)
      .subscribe((data) => {
        this.orderInfo = data.data || {};
        this.message.remove(this.maskFlag);
        this.maskFlag = false;
        this.getList();
      });
  }

  // 获取列表
  pageIndex: number = 1;//表格当前页码
  pageSize: number = 10;//表格每页展示条数
  total: number = 0;//表格总数据量
  list: any = [];
  getList() {
    let postData = {
      idx: this.pageIndex - 1,
      sum: this.pageSize,
      clinicalWaste: {
        outId: this.id,
        hosId: this.hosId,
      }
    }
    this.hsLoading = true;
    this.mainService.getFetchDataList('simple/data','clinicalWaste', postData).subscribe(res => {
      if (res.status == 200) {
        this.hsLoading = false;
        this.list = res.list || [];
        this.total = res.totalNum || 0;
      }
    });
  }
  // 切换tab栏
  tabType: number = 1; //tab栏
  checkTab(type) {
    this.tabType = type;
  }

  // 关闭弹框
  close() {
    history.go(-1);
  }

}
